Diferencia entre revisiones de «APIenglish»

De Proyecto Butiá
Saltar a: navegación, buscar
(The Butiá API in Python)
(The Butiá API in Python)
Línea 94: Línea 94:
 
     robot.setHack(pin, value) #pin number, value is 0 (GND) and 1 (VCC)
 
     robot.setHack(pin, value) #pin number, value is 0 (GND) and 1 (VCC)
 
     robot.setLed(port, on) #if on 1, turn on the LED, if 0, turn off
 
     robot.setLed(port, on) #if on 1, turn on the LED, if 0, turn off
 +
    robot.setMotorSpeed(idMotor, sense, speed) #idMotor 0 for left motor, 1 for right

Revisión del 06:07 27 feb 2013

See also API in Spanish. Note, the API now uses English syntax as from Turtlebots V17

Butiá can be used in many forms as a consumable service through the network as is the case of the bobot server directly using the bobot library or through various APIs such as C, Java, Python

The Butiá API in Python

Description of the function and various examples.

In a XO, for use from Python or Pippy begin your code with:

   import sys
   sys.path.insert(0, '/home/olpc/Activities/TurtleBots.activity/plugins/butia/pybot')

Now, import the usb4butia library:

   import usb4butia

Create an instance of the class:

   robot = usb4butia.USB4Butia()



Items in 'quotes' uncertain usage and syntax

'bb'
robot.callModule(modulename, function, params )
robot.close()                    #close communication with the bobot server
'debug'
'drivers_loaded'
'find_butias'
robot.getBatteryCharge()         #the battery charge, -1 if no motor connected
robot.getButton(port)            #port: to the connector that the button sensor is connected, J2 is port 1 etc.
robot.getDistance(port)
robot.getFirmwareVersion()       #return the version of the firmware inside the pic
robot.getGray(port)
'getHack'
robot.getLight(port)
'getResistance'
'getTemperature'
'getVersion'
'getVoltage'
'get_all_drivers'
'get_butia_count'
'get_driver'
robot.get_modules_list()          #returns the list of modules available in the Butia board's firmware
'hotplug'
robot.isPresent(modulename)       #Returns if the module is present
robot.loopBack(data)              #Send a message to the board and expect to receive exactly what was sent
'modeHack'
'modules'
'openables'
robot.reconnect(address, port)    #connect or reconnect to the bobot at address:port
'refresh'
robot.set2MotorSpeed(self, directionleft, speedleft, directionright, speedright)
'setHack'
'setLed'
robot.setMotorSpeed(self, idMotor, direction, speed)
dir(robot)                        #get all properties and functions

The new fucntions:

   robot._bb
   robot._drivers_loaded
   robot._debug
   robot._get_all_drivers()
   robot._get_driver()
   robot._hotplug()
   robot._modules()
   robot._openables
   robot.callModule(modulename, board_number, number, function, params)
   robot.close()
   robot.find_butias()
   robot.getBatteryCharge()
   robot.getButton(port)
   robot.getDistance(port)
   robot.getFirmwareVersion()
   robot.getGray(port)
   robot.getHack(number)
   robot.getLight(port)
   robot.getResistance(port)
   robot.getTemperature(port)
   robot.getVersion()
   robot.getVoltage(port)
   robot.get_butia_count() #the number of usb4butia board connected
   robot.get_modules_list() #the list of devices connected (in all boards)
   robot.isPresent(device) #check if device is present 
   robot.loopBack(data) #send 'data' to the board and read the return
   robot.modeHack(pin, mode) #pin number. mode 0 means input and 1 ouput
   robot.reconnect()
   robot.refresh()
   robot.set2MotorSpeed(leftSense, leftSpeed, rightSense, rightSpeed) #sense is 0 or 1, speed is between 0 and 1023
   robot.setHack(pin, value) #pin number, value is 0 (GND) and 1 (VCC)
   robot.setLed(port, on) #if on 1, turn on the LED, if 0, turn off
   robot.setMotorSpeed(idMotor, sense, speed) #idMotor 0 for left motor, 1 for right