Exemple #1
0
name = sys.argv[1]
registry = rotorc.RemoteRegistry( name )
options  = registry.options()


registry.registerMessageType( "JOYSTICK", joystickDefinition )
frequency = options.getDouble( name, "frequency", 10 )



joystickInfo = rotorc.Structure( "Joystick", None, registry )

pygame.init()
pygame.joystick.init()
joystick = pygame.joystick.Joystick( 0 )
joystick.init()
time = rotorc.seconds()

while True:
  delta   = rotorc.seconds()
  time = delta
  pygame.event.pump()
  joystickInfo.axesCount = joystick.get_numaxes()
  for i in xrange( joystickInfo.axesCount ):
    joystickInfo.axes[i] = joystick.get_axis( i )
  joystickInfo.buttonCount = joystick.get_numbuttons()
  for i in xrange( joystickInfo.buttonCount ):
    joystickInfo.buttons[i] = joystick.get_button( i )
  registry.sendStructure( "JOYSTICK", joystickInfo )
  rotorc.Thread.sleep( 0.1 )
Exemple #2
0
    uint8_t * buttons;
  };
'''

name = sys.argv[1]
options  = rotorc.BaseOptions()
options.setString( "BOOTSTRAP", "server", "localhost" )
registry = rotorc.Registry.load( "CarmenRegistry", name, options, "/usr/lib" )

registry.registerType( joystickDefinition )
registry.registerMessage( "JOYSTICK", "Joystick" )
registry.subscribeToMessage( "JOYSTICK" )

registry.registerMessageType( "carmen_base_velocity", baseVelocityDefinition )
command = rotorc.Structure( "Command", None, registry )

oldTime = 0

while True:
  message = registry.receiveMessage()
  time    = rotorc.seconds()
  joystick = message.data
  command.tv = -joystick.axes[1] * 0.4;
  command.rv = -joystick.axes[0] * 1;
  command.timestamp = rotorc.microseconds();
  command.host  = "ventisca"
  registry.sendStructure( "carmen_base_velocity", command )
  sys.stdout.write( "\r%f\t%f \t%f" % ( command.tv, command.rv, time - oldTime )  )
  sys.stdout.flush()
  oldTime = time