Open Source Release


Team Wiki

Getting Started Setup Workstation Account Calendar/Announcements External Resources Basic Reference


League Specific
SPL (Nao)

NSL (Darwin)


Code Reference Using Shared Memory Interfaces Game Control Game Day Tips Testing and Utilities



Contacts Packing List Administration

Shm

Page: Main.Shm - Last Modified : Wed, 10 Aug 11

Creating New Shared Memory Variables

edit a *mc file, such as Player/Vision/vcm.lua, and add a new block

shared.block = {}; -- new block

and add to the new block, or add to an existing one

shared.block = {};
shared.block.num = vector.zeros(1); -- new number
shared.block.vec = vector.zeros(3); -- new vector
shared.camera = {};
shared.camera.select = vector.zeros(1);
shared.camera.command = vector.zeros(1);
shared.camera.str = ''; -- new string

Accessing Shared Memory

Lua Examples

Move into the Player directory and start lua. Make sure to initialize.

> dofile('init.lua')
numbers
> require('vcm')
shsize.image 635800
> print(vcm.get_goal_detect())
0
>vcm.set_goal_detect(1)
> print(vcm.get_goal_detect())
1
vectors
> print(vcm.get_ball_centroid())
{0, 0}
> vcm.set_ball_centroid({1,2})
> print(vcm.get_ball_centroid())
{1, 2}
strings
> require('gcm')
Speak: Player ID 3
> =gcm.get_game_s()

> gcm.set_game_s('hi')
WARNING: Input size 2 != current block size 0. Resizing s block.
> return gcm.get_game_s()
hi

Matlab Examples

First you must access the memory block. You do this by concatenating the name of the *mc file (ie 'vcm') and the name of the memory block, with the first letter capitalized (ie 'Ball'), and passing this string into a call of shm.m.

>> ball=shm('vcmBall')

ball =

        shmHandle: 3
            get_r: @()mexshm('get',h.shmHandle,k)
            set_r: @(val)mexshm('set',h.shmHandle,k,double(val))
            get_v: @()mexshm('get',h.shmHandle,k)
            set_v: @(val)mexshm('set',h.shmHandle,k,double(val))
           get_da: @()mexshm('get',h.shmHandle,k)
           set_da: @(val)mexshm('set',h.shmHandle,k,double(val))
           get_dr: @()mexshm('get',h.shmHandle,k)
           set_dr: @(val)mexshm('set',h.shmHandle,k,double(val))
       get_detect: @()mexshm('get',h.shmHandle,k)
       set_detect: @(val)mexshm('set',h.shmHandle,k,double(val))
     get_centroid: @()mexshm('get',h.shmHandle,k)
     set_centroid: @(val)mexshm('set',h.shmHandle,k,double(val))
    get_axisMajor: @()mexshm('get',h.shmHandle,k)
    set_axisMajor: @(val)mexshm('set',h.shmHandle,k,double(val))
    get_axisMinor: @()mexshm('get',h.shmHandle,k)
    set_axisMinor: @(val)mexshm('set',h.shmHandle,k,double(val))
 
numbers
>> ball=shm('vcmBall');
>> ball.get_detect()

ans =

     0

>> ball.set_detect(1)
>> ball.get_detect()

ans =

     1
 
vectors
>> ball.get_v()

ans =

     0     0     0     0

>> ball.set_v([1 2 3 4])
>> ball.get_v()        

ans =

     1     2     3     4
 
strings

when using strings, make sure to cast the return of the get_*() functions to a char array

>> game=shm('gcmGame');
>> char(game.get_s())

ans =

hi

>> game.set_s('hello')
WARNING: Input size 5 != current block size 2. Resizing s block.
>> char(game.get_s())

ans =

hello
 

Powered by PmWiki

Utilizes the Sinorca skin