Diferencia entre revisiones de «APIenglish»

De Proyecto Butiá
Saltar a: navegación, buscar
(The Butiá API in Python)
(Useful commands in python)
 
(No se muestran 26 ediciones intermedias de 2 usuarios)
Línea 7: Línea 7:
 
Description of the function and various examples.
 
Description of the function and various examples.
  
 +
In a XO, for use from Python or Pippy begin your code with:
  
'''Instanciate the class:'''
+
    import sys
 +
    sys.path.insert(0, '/home/olpc/Activities/TurtleBots.activity/plugins/butia/pybot')
  
<syntaxhighlight lang="python">
+
Now, import the usb4butia library:
robot = butiaAPI.robot()
+
</syntaxhighlight>
+
  
 +
    import usb4butia
  
'''Other'''
+
Create an instance of the class:
  
Items in 'quotes' uncertain syntax
+
    robot = usb4butia.USB4Butia()
  
'bb'
+
==Functions and properties==
robot.callModule(modulename, function, params )
+
 
robot.close()                   #close communication with the bobot server
+
Private properties:
'debug'
+
    robot._bb
'drivers_loaded'
+
    robot._drivers_loaded
'find_butias'
+
    robot._debug                            #debug flag, by default is False
robot.getBatteryCharge()         #the battery charge, -1 if no motor connected
+
    robot._get_all_drivers()
robot.getButton(port)
+
    robot._get_driver()
robot.getDistance(port)
+
    robot._hotplug
robot.getFirmwareVersion()
+
    robot._modules
robot.getGray(port)
+
    robot._openables
'getHack'
+
 
robot.getLight(port)
+
Usefull functions
'getResistance'
+
 
'getTemperature'
+
    robot.close()                           #close all open boards
'getVersion'
+
    robot.find_butias()                      #search for connected boards and open
  'getVoltage'
+
    robot.getBatteryCharge()                 #return the battery charge level (if no motors-> -1)
'get_all_drivers'
+
    robot.getFirmwareVersion()               #return the version of the firmware inside the pic
'get_butia_count'
+
    robot.getVersion()                      #return the version of butia module (arduino: 20, usb4butia:22)
'get_driver'
+
    robot.get_butia_count()                 #the number of usb4butia board connected
'get_modules_list'
+
    robot.get_modules_list()                #the list of devices connected (in all boards)
'hotplug'
+
    robot.isPresent(device)                 #check if device is present
robot.isPresent(modulename)       #Returns if the module is present
+
    robot.loopBack(data)                    #send 'data' to the board and read the return
robot.loopBack(data)             #Send a message to the board and expect to receive exactly what was sent
+
    robot.reconnect()                        #do nothing
'modeHack'
+
    robot.refresh()                          #check if the board is connected
'modules'
+
    robot.callModule(modulename, board_number, number, function, params) #generic call
'openables'
+
 
robot.reconnect(address, port)   #connect or reconnect to the bobot at address:port
+
Sensors
'refresh'
+
 
robot.set2MotorSpeed(self, directionleft, speedleft, directionright, speedright)
+
    robot.getButton(port)                    #get the value por button sensor connected on port
'setHack'
+
    robot.getDistance(port)                  #get the value por distance sensor connected on port
'setLed'
+
    robot.getGray(port)                     #get the value por gray sensor connected on port
robot.setMotorSpeed(self, idMotor, direction, speed)
+
    robot.getLight(port)                     #get the value por light sensor connected on port
 +
    robot.getResistance(port)                #get the value por resistance sensor connected on port
 +
    robot.getTemperature(port)              #get the value por temperature sensor connected on port
 +
    robot.getVoltage(port)                   #get the value por voltage sensor connected on port
 +
    robot.setLed(port, on)                  #if on 1, turn on the LED, if 0, turn off
 +
 
 +
Hack pins
 +
 
 +
    robot.modeHack(pin, mode)               #pin number. mode 0 means input and 1 ouput
 +
    robot.setHack(pin, value)                #pin number, value is 0 (GND) and 1 (VCC)
 +
    robot.getHack(pin)                      #read the value of the pin
 +
 
 +
Motors
 +
 
 +
    robot.set2MotorSpeed(leftSense, leftSpeed, rightSense, rightSpeed)  #sense is 0 or 1, speed is between 0 and 1023
 +
    robot.setMotorSpeed(idMotor, sense, speed)                           #idMotor 0 for left motor, 1 for right
 +
 
 +
==Useful commands in python==
 +
 
 +
To get a list of functions and properties of a object, for example robot:
 +
 
 +
    dir(robot)                        #get all properties and functions
 +
 
 +
[[Archivo:Dir_robot.png]]
 +
 
 +
To get a more detail, use the help function (available on Python interprete):
 +
 
 +
    help(robot)
 +
 
 +
The result:
 +
 
 +
[[Archivo:Help_robot.png]]

Revisión actual del 07:33 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()

Functions and properties

Private properties:

   robot._bb
   robot._drivers_loaded
   robot._debug                            #debug flag, by default is False
   robot._get_all_drivers()
   robot._get_driver()
   robot._hotplug
   robot._modules
   robot._openables

Usefull functions

   robot.close()                            #close all open boards
   robot.find_butias()                      #search for connected boards and open
   robot.getBatteryCharge()                 #return the battery charge level (if no motors-> -1)
   robot.getFirmwareVersion()               #return the version of the firmware inside the pic
   robot.getVersion()                       #return the version of butia module (arduino: 20, usb4butia:22)
   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.reconnect()                        #do nothing
   robot.refresh()                          #check if the board is connected
   robot.callModule(modulename, board_number, number, function, params)  #generic call

Sensors

   robot.getButton(port)                    #get the value por button sensor connected on port
   robot.getDistance(port)                  #get the value por distance sensor connected on port
   robot.getGray(port)                      #get the value por gray sensor connected on port
   robot.getLight(port)                     #get the value por light sensor connected on port
   robot.getResistance(port)                #get the value por resistance sensor connected on port
   robot.getTemperature(port)               #get the value por temperature sensor connected on port
   robot.getVoltage(port)                   #get the value por voltage sensor connected on port
   robot.setLed(port, on)                   #if on 1, turn on the LED, if 0, turn off

Hack pins

   robot.modeHack(pin, mode)                #pin number. mode 0 means input and 1 ouput
   robot.setHack(pin, value)                #pin number, value is 0 (GND) and 1 (VCC)
   robot.getHack(pin)                       #read the value of the pin

Motors

   robot.set2MotorSpeed(leftSense, leftSpeed, rightSense, rightSpeed)   #sense is 0 or 1, speed is between 0 and 1023
   robot.setMotorSpeed(idMotor, sense, speed)                           #idMotor 0 for left motor, 1 for right

Useful commands in python

To get a list of functions and properties of a object, for example robot:

   dir(robot)                        #get all properties and functions

Dir robot.png

To get a more detail, use the help function (available on Python interprete):

   help(robot)

The result:

Help robot.png