update
This commit is contained in:
parent
ef00cd438d
commit
dbda82b076
7 changed files with 68 additions and 8 deletions
9
Robot.py
9
Robot.py
|
@ -3,6 +3,8 @@ Controls = RobotCompletCode.MotorizedPlatform()
|
|||
class Robot:
|
||||
def init(self):
|
||||
Controls.init()
|
||||
def set_range(self, name:str, mini:int, maxi:int):
|
||||
Controls.set_range(name,mini,maxi)
|
||||
def translation(self, direction, vitesse):
|
||||
if direction == 'N':
|
||||
Controls.northTranslation(vitesse)
|
||||
|
@ -31,13 +33,18 @@ class Robot:
|
|||
else:
|
||||
print('error')
|
||||
return 'error'
|
||||
def turbine(self, vitesse):
|
||||
pass
|
||||
def tuyau(self, axe, vitesse):
|
||||
#axe : vertical / horizontal
|
||||
pass
|
||||
def stop(self):
|
||||
Controls.stop()
|
||||
def easy(self, mode, direction, vitesse):
|
||||
if mode=='R':
|
||||
self.rotation(direction, vitesse)
|
||||
elif mode=='T':
|
||||
self.translation(diretion, vitesse)
|
||||
self.translation(direction, vitesse)
|
||||
else:
|
||||
print('error')
|
||||
return 'error'
|
||||
|
|
|
@ -32,7 +32,8 @@ class MotorizedPlatform:
|
|||
}
|
||||
}
|
||||
escSlotsList= [12,13,8,9]
|
||||
|
||||
def set_range(self, name:str, mini:int, maxi:int):
|
||||
self.escMapping[name]['range'] = [mini,maxi]
|
||||
def init(self):
|
||||
if drive != None:
|
||||
for k,v in self.escMapping.items():
|
||||
|
@ -50,11 +51,13 @@ class MotorizedPlatform:
|
|||
self.set_esc_speed(k, value)
|
||||
|
||||
def set_esc_speed(self, esc_name, value):
|
||||
if value < 0:
|
||||
value = value * 1.185
|
||||
drive.setPwm(
|
||||
self.escMapping[esc_name]['slot'],
|
||||
0,
|
||||
self.convert_speed_to_esc(value, self.escMapping[esc_name]['range'])
|
||||
)
|
||||
self.escMapping[esc_name]['slot'],
|
||||
0,
|
||||
self.convert_speed_to_esc(value, self.escMapping[esc_name]['range'])
|
||||
)
|
||||
|
||||
# équivalent de la fonction map() de arduino
|
||||
def mappyt(self, x, inMin, inMax, outMin, outMax):
|
||||
|
@ -73,7 +76,7 @@ class MotorizedPlatform:
|
|||
})
|
||||
|
||||
def southTranslation(self, speed):
|
||||
self.northTranslation(-speed)
|
||||
self.northTranslation(-speed*1.1)
|
||||
|
||||
def northTranslation(self, speed):
|
||||
self.setSpeed({
|
||||
|
@ -122,6 +125,52 @@ class MotorizedPlatform:
|
|||
self.northWestTranslation(-speed)
|
||||
|
||||
def stop(self):
|
||||
realescMapping = {
|
||||
'frontLeft': {
|
||||
'slot': 12, # 7
|
||||
'range': [307, 410]
|
||||
},
|
||||
'frontRight': {
|
||||
'slot': 13,
|
||||
'range': [307, 410]
|
||||
},
|
||||
'backLeft': {
|
||||
'slot': 8,
|
||||
'range': [307, 410]
|
||||
},
|
||||
'backRight': {
|
||||
'slot': 9,
|
||||
'range': [307, 410]
|
||||
}
|
||||
}
|
||||
motornamelist = ['frontLeft','frontRight','backLeft','backRight']
|
||||
for i in range(len(motornamelist)):
|
||||
esc_name = motornamelist[i]
|
||||
drive.setPwm(
|
||||
realescMapping[esc_name]['slot'],
|
||||
0,
|
||||
self.convert_speed_to_esc(0, realescMapping[esc_name]['range'])
|
||||
)
|
||||
|
||||
def oldstop(self):
|
||||
self.escMapping = {
|
||||
'frontLeft': {
|
||||
'slot': 12, # 7
|
||||
'range': [307, 410]
|
||||
},
|
||||
'frontRight': {
|
||||
'slot': 13,
|
||||
'range': [307, 410]
|
||||
},
|
||||
'backLeft': {
|
||||
'slot': 8,
|
||||
'range': [307, 410]
|
||||
},
|
||||
'backRight': {
|
||||
'slot': 9,
|
||||
'range': [307, 410]
|
||||
}
|
||||
}
|
||||
self.setSpeed({
|
||||
'frontLeft': 0,
|
||||
'frontRight': 0,
|
||||
|
|
BIN
__pycache__/Container.cpython-39.pyc
Normal file
BIN
__pycache__/Container.cpython-39.pyc
Normal file
Binary file not shown.
BIN
__pycache__/PWMDriver.cpython-39.pyc
Normal file
BIN
__pycache__/PWMDriver.cpython-39.pyc
Normal file
Binary file not shown.
BIN
__pycache__/Robot.cpython-39.pyc
Normal file
BIN
__pycache__/Robot.cpython-39.pyc
Normal file
Binary file not shown.
BIN
__pycache__/RobotCompletCode.cpython-39.pyc
Normal file
BIN
__pycache__/RobotCompletCode.cpython-39.pyc
Normal file
Binary file not shown.
|
@ -49,7 +49,7 @@ class commandHandler:
|
|||
try:
|
||||
robot.rotation(arg,self.speed)
|
||||
except Exception as e:
|
||||
return 'error'
|
||||
raise e
|
||||
def set_speed(self,v):
|
||||
if v>=50:
|
||||
v = 50
|
||||
|
@ -57,6 +57,8 @@ class commandHandler:
|
|||
v=v
|
||||
self.speed=v
|
||||
return 'speed set to '+str(v)
|
||||
def set_range(self, name:str, mini:int, maxi:int):
|
||||
robot.set_range(name, mini, maxi)
|
||||
|
||||
|
||||
cmd_handler = commandHandler()
|
||||
|
@ -78,6 +80,8 @@ def commands(data):
|
|||
res= cmd_handler.set_rotation(data["args"]['rotation'])
|
||||
elif(data['cmd']=='stop_robot'):
|
||||
res=cmd_handler.stop()
|
||||
elif(data['cmd']=='set_range'):
|
||||
res=cmd_handler.set_range(data['args']['name'],data['args']['min'],data['args']['max'])
|
||||
elif(data['cmd']=='init'):
|
||||
res=cmd_handler.init()
|
||||
elif(data['cmd']=='set_speed'):
|
||||
|
|
Loading…
Reference in a new issue