Skip to content
Snippets Groups Projects

Device

Open Yusuke Tanaka requested to merge Suke/rocolib:Device into main
Files
20
+ 157
0
from rocolib.api.components import Component
from rocolib.api.composables import DiscreteComposable
#name of composable
DISCRETE = 'discrete'
#key names
DIMS = 'dims'
PARAMS = 'params'
TYPE = 'type'
# Helper functions
def getDim(obj, param):
return devices[obj][DIMS][param]
def isDim(obj):
return obj in devices
def getParam(obj, param):
try:
ret = devices[obj][PARAMS][param]
except KeyError:
ret = None
return
def getType(obj, option=None):
if option == 'Webots':
pass
# helper related to commons
def getDefaultDevice( objType):
return commons['default'][objType]
def getCommonsParm(obj, param):
return commons[obj][param]
def getCommonsMatch(obj, value):
match = None
for k, v in commons[obj].items():
if value in v:
match = k
return match
#device lib and common data storage
commons = {}
devices = {}
devices['ESP'] = {
DIMS: {
"length" : 59.5,
"width" : 44,
"height" : 13,
"nrows" : 15,
"ncols" : 2,
"rowsep" : 0.1 * 25.4,
"colsep" : 0.9 * 25.4},
PARAMS: {"price": 15,
"URL": "https://www.adafruit.com/product/2442",
"power": 100},
TYPE: "brain",
}
devices['nodeMCU'] = {
DIMS: {"length" : 59.5,
"width" : 44,
"height" : 13,
"nrows" : 15,
"ncols" : 2,
"rowsep" : 0.1 * 25.4,
"colsep" : 0.9 * 25.4},
PARAMS: {"price": 1},
TYPE: "brain"
}
devices['proMini'] = {
DIMS: {"length" : 39,
"width" : 19,
"height" : 9,
"nrows" : 12,
"ncols" : 2,
"rowsep" : 0.1 * 25.4,
"colsep" : 0.6 * 25.4,},
PARAMS: {"price": 1},
TYPE: "brain"
}
devices['tgy1370a'] = {
DIMS: {"motorlength" : 20,
"motorwidth" : 9,
"motorheight" : 14,
"shoulderlength": 4,
"hornlength" : 7,
"hornheight" : 10,
"hornoffset" : 4,
"horndepth" : 2},
PARAMS: {"price": 1},
TYPE: "servo"
}
devices['GPS_default'] = {
DIMS: {"length" : 13,
"width" : 15,
"height" : 13},
PARAMS: {"price": 10,
"name": "Global_GPS"},
TYPE: "gps",
}
devices['Compass_default'] = {
DIMS: {"length" : 1,
"width" : 1,
"height" : 1},
PARAMS: {"price": 2},
TYPE: "compass"
}
devices['fs90r'] = {
DIMS: {"motorlength" : 23,
"motorwidth" : 13,
"motorheight" : 19,
"shoulderlength": 5,
"hornlength" : 10,
"hornheight" : 16,
"hornoffset" : 8,
"horndepth" : 2},
PARAMS: {"price": 4.95,
"description": "Continuous servo",
"URL": "https://www.adafruit.com/product/2442"},
TYPE: "servo"
}
commons['webotsType']={
"sensor": ['gps', 'compass', 'lidar'],
"actuator": ['servo', 'linear servo'],
"cpu": ['brain']
}
commons['default']={
'gps': 'GPS_default',
'compass': 'Compass_default',
'lidar': 'Lidar_default',
'servo': 'fs90r',
'brain': 'nodeMCU'
}
class DiscreteComponent(Component):
def predefine(self, **kwargs):
super().predefine(**kwargs)
self.composables[DISCRETE] = DiscreteComposable()