diff --git a/Robot.py b/Robot.py index 85763fe..f41571a 100644 --- a/Robot.py +++ b/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' diff --git a/RobotCompletCode.py b/RobotCompletCode.py index f24b2d3..77387b0 100644 --- a/RobotCompletCode.py +++ b/RobotCompletCode.py @@ -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, diff --git a/__pycache__/Container.cpython-39.pyc b/__pycache__/Container.cpython-39.pyc new file mode 100644 index 0000000..385f0f2 Binary files /dev/null and b/__pycache__/Container.cpython-39.pyc differ diff --git a/__pycache__/PWMDriver.cpython-39.pyc b/__pycache__/PWMDriver.cpython-39.pyc new file mode 100644 index 0000000..deb33d4 Binary files /dev/null and b/__pycache__/PWMDriver.cpython-39.pyc differ diff --git a/__pycache__/Robot.cpython-39.pyc b/__pycache__/Robot.cpython-39.pyc new file mode 100644 index 0000000..fb3f111 Binary files /dev/null and b/__pycache__/Robot.cpython-39.pyc differ diff --git a/__pycache__/RobotCompletCode.cpython-39.pyc b/__pycache__/RobotCompletCode.cpython-39.pyc new file mode 100644 index 0000000..4265ef2 Binary files /dev/null and b/__pycache__/RobotCompletCode.cpython-39.pyc differ diff --git a/server.py b/server.py index 5ae9736..33e3946 100644 --- a/server.py +++ b/server.py @@ -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'):