Chargement...
 

Adding a costum dynamixel module to pypot

This howto show you how to use Rhoban Cell Load card with pypot.

IMG 20181108 092222612 Crop 614x614

First, you have to add your model into known models:

import pypot
from pypot.dynamixel import conversion as conv
conv.dynamixelModels[5004]='RhobanLoadBoard'


Then, we use _DxlControl :

import pypot
import pypot.dynamixel

from pypot.dynamixel.io.abstract_io import  _DxlControl,_DxlAccess

ports = pypot.dynamixel.get_available_ports()
dxl_io = pypot.dynamixel.DxlIO(ports[0])

# now we can create our own accessor

def dxl_to_loadvalue(value,model):
    return ((value[0]) | (value[1] << 8) | (value[2] << 16)) & 0xffffffff


control=_DxlControl(name,
                        address=0x24, length=1,nb_elem=3,
                        access=_DxlAccess.readonly,
                        models=['RhobanLoadBoard'],
                        dxl_to_si=dxl_to_loadvalue,
                        si_to_dxl=None,
                        getter_name="get_loadcell1",
                        setter_name=None)
dxl_io._generate_accessors(control)


For the rhoban board, each cell value is 3 bytes to read at adress 0x24, 0x27, 0x30 and 0x33. We can create an accessor for each cell using the following loop:

def dxl_to_loadvalue(value,model):
    return ((value[0]) | (value[1] << 8) | (value[2] << 16)) & 0xffffffff

for i in [1,2,3,4]:
    name="loadcell%d"%i
    getter="get_loadcell%d"%i
    control=_DxlControl(name,
                        address=0x24+3*(i-1), length=1,nb_elem=3,
                        access=_DxlAccess.readonly,
                        models=['RhobanLoadBoard'],
                        dxl_to_si=dxl_to_loadvalue,
                        si_to_dxl=None,
                        getter_name=getter,
                        setter_name=None)
    dxl_io._generate_accessors(control)


Now, we can read the value of each cell

dxl_io.get_loadcell1((123,))
dxl_io.get_loadcell2((123,))
dxl_io.get_loadcell3((123,))
dxl_io.get_loadcell4((123,))

The id of the board (here is 123) is retrieved using

dxl_io.scan()

Evénements

1)  2019-01-19 08:00 - 17:00
Robot Makers Day : First Lego League

Formations

Aucun enregistrement à afficher