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:
|
class Robot:
|
||||||
def init(self):
|
def init(self):
|
||||||
Controls.init()
|
Controls.init()
|
||||||
|
def set_range(self, name:str, mini:int, maxi:int):
|
||||||
|
Controls.set_range(name,mini,maxi)
|
||||||
def translation(self, direction, vitesse):
|
def translation(self, direction, vitesse):
|
||||||
if direction == 'N':
|
if direction == 'N':
|
||||||
Controls.northTranslation(vitesse)
|
Controls.northTranslation(vitesse)
|
||||||
|
@ -31,13 +33,18 @@ class Robot:
|
||||||
else:
|
else:
|
||||||
print('error')
|
print('error')
|
||||||
return 'error'
|
return 'error'
|
||||||
|
def turbine(self, vitesse):
|
||||||
|
pass
|
||||||
|
def tuyau(self, axe, vitesse):
|
||||||
|
#axe : vertical / horizontal
|
||||||
|
pass
|
||||||
def stop(self):
|
def stop(self):
|
||||||
Controls.stop()
|
Controls.stop()
|
||||||
def easy(self, mode, direction, vitesse):
|
def easy(self, mode, direction, vitesse):
|
||||||
if mode=='R':
|
if mode=='R':
|
||||||
self.rotation(direction, vitesse)
|
self.rotation(direction, vitesse)
|
||||||
elif mode=='T':
|
elif mode=='T':
|
||||||
self.translation(diretion, vitesse)
|
self.translation(direction, vitesse)
|
||||||
else:
|
else:
|
||||||
print('error')
|
print('error')
|
||||||
return 'error'
|
return 'error'
|
||||||
|
|
|
@ -32,7 +32,8 @@ class MotorizedPlatform:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
escSlotsList= [12,13,8,9]
|
escSlotsList= [12,13,8,9]
|
||||||
|
def set_range(self, name:str, mini:int, maxi:int):
|
||||||
|
self.escMapping[name]['range'] = [mini,maxi]
|
||||||
def init(self):
|
def init(self):
|
||||||
if drive != None:
|
if drive != None:
|
||||||
for k,v in self.escMapping.items():
|
for k,v in self.escMapping.items():
|
||||||
|
@ -50,6 +51,8 @@ class MotorizedPlatform:
|
||||||
self.set_esc_speed(k, value)
|
self.set_esc_speed(k, value)
|
||||||
|
|
||||||
def set_esc_speed(self, esc_name, value):
|
def set_esc_speed(self, esc_name, value):
|
||||||
|
if value < 0:
|
||||||
|
value = value * 1.185
|
||||||
drive.setPwm(
|
drive.setPwm(
|
||||||
self.escMapping[esc_name]['slot'],
|
self.escMapping[esc_name]['slot'],
|
||||||
0,
|
0,
|
||||||
|
@ -73,7 +76,7 @@ class MotorizedPlatform:
|
||||||
})
|
})
|
||||||
|
|
||||||
def southTranslation(self, speed):
|
def southTranslation(self, speed):
|
||||||
self.northTranslation(-speed)
|
self.northTranslation(-speed*1.1)
|
||||||
|
|
||||||
def northTranslation(self, speed):
|
def northTranslation(self, speed):
|
||||||
self.setSpeed({
|
self.setSpeed({
|
||||||
|
@ -122,6 +125,52 @@ class MotorizedPlatform:
|
||||||
self.northWestTranslation(-speed)
|
self.northWestTranslation(-speed)
|
||||||
|
|
||||||
def stop(self):
|
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({
|
self.setSpeed({
|
||||||
'frontLeft': 0,
|
'frontLeft': 0,
|
||||||
'frontRight': 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:
|
try:
|
||||||
robot.rotation(arg,self.speed)
|
robot.rotation(arg,self.speed)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return 'error'
|
raise e
|
||||||
def set_speed(self,v):
|
def set_speed(self,v):
|
||||||
if v>=50:
|
if v>=50:
|
||||||
v = 50
|
v = 50
|
||||||
|
@ -57,6 +57,8 @@ class commandHandler:
|
||||||
v=v
|
v=v
|
||||||
self.speed=v
|
self.speed=v
|
||||||
return 'speed set to '+str(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()
|
cmd_handler = commandHandler()
|
||||||
|
@ -78,6 +80,8 @@ def commands(data):
|
||||||
res= cmd_handler.set_rotation(data["args"]['rotation'])
|
res= cmd_handler.set_rotation(data["args"]['rotation'])
|
||||||
elif(data['cmd']=='stop_robot'):
|
elif(data['cmd']=='stop_robot'):
|
||||||
res=cmd_handler.stop()
|
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'):
|
elif(data['cmd']=='init'):
|
||||||
res=cmd_handler.init()
|
res=cmd_handler.init()
|
||||||
elif(data['cmd']=='set_speed'):
|
elif(data['cmd']=='set_speed'):
|
||||||
|
|
Loading…
Reference in a new issue