From dbda82b076868fdbb101cd5f195b0f2c00725f31 Mon Sep 17 00:00:00 2001 From: GZod01 Date: Sat, 25 Mar 2023 11:55:37 +0100 Subject: [PATCH] update --- Robot.py | 9 ++- RobotCompletCode.py | 61 ++++++++++++++++++-- __pycache__/Container.cpython-39.pyc | Bin 0 -> 834 bytes __pycache__/PWMDriver.cpython-39.pyc | Bin 0 -> 1590 bytes __pycache__/Robot.cpython-39.pyc | Bin 0 -> 2199 bytes __pycache__/RobotCompletCode.cpython-39.pyc | Bin 0 -> 4631 bytes server.py | 6 +- 7 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 __pycache__/Container.cpython-39.pyc create mode 100644 __pycache__/PWMDriver.cpython-39.pyc create mode 100644 __pycache__/Robot.cpython-39.pyc create mode 100644 __pycache__/RobotCompletCode.cpython-39.pyc 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 0000000000000000000000000000000000000000..385f0f24cda14f7f501ca4e3609f1de610b7a9c4 GIT binary patch literal 834 zcmZuvv2NQi5IvHTO}lmiWC)rcD4?Nr;I2WDB14hIOEwJ=6p?LR*iuT$EgE=B_I`(d ziED>`K(|i4C)Ku+_JBJ+@<_h-MCIf0kT||y|191Lq92%aL-FLC(;snpM}~}e;JlY9 z8F@vCDtP@-NS>W@`cp2JQeh~Sb4ryFMm|s)8D%0KV-uSmk3G{jn#aBw@O{HDxTwlH zpO@AZAm0Ws@`BSJa9PVWeWJBEV^LSM5wnd5gL&!eyezCwREWG?ybn>CFKy7<#)h2c z!@pllK2}RRxt&kGT36jv_4IT)eaYqZWXJ#N_FGWi))6RSi^Sb{-{nrxtfIpKjBFG> zXRsDf_(iw_C~Vc9Fml-CU?!0+2JWFiS6c>*g8E?VJ_C;?iJ^!dv2(ZJ2ipbkjva4W zgHhazzkG=dYGF$UGaJ#;K4FZDYE{-F-mrChxOdz1{$T`b;};^~uO5evWE zzS3cb>v+%A-7-sb&{>98%(5`dvSnpf3*b?feO~2@w$u1>@a>+V;16-QzQfb z-)zQyr^VtBSbPC0-Ud@l@q`Vy&pG>wDNBhgvM5mTEg5=EktkEO9$UQe4yh|qkjOC|b|Fhvi7_wvkm>bGT*yi)c5La7DuJ$8 zBd*_5{KCkU*n+*XDhcfaC17dYWfdTG%!)@9^vc>|$5Q8|Pu9_SrqM!n?%venbNB0X6ry{s0f3u_MG-0Ye8qh{EN8m7a3`;kn|IIs^6+qbd;7+z zNV0P7Q)Vu@yPqB<(Y7WaYpSN_)UrIwqgtxCS89q=+qsU@vKGV|gD}s}O1(lG%^5tr zhNeCO4~XyEfMyc;%lQ;2-Ea{3&Dp}Y^I-xQ5n`rnjU1hMCUjomf-x?68{_~L66D}p z=bL;Lv*dTIMU2dy{{s(#3RTd+V;uqt&aQaH(ONMt_zT|kEOQtA2222dx`)0E=8LS~ z_pK~_IoAe`J2)BKflWb=h4J&%oBr%fH+uxm`5>A8KqiwnAy5vRtgRG$CvAQ-X8TpqYUl1WoqO~E%vIXfKi(KzvH$=8 literal 0 HcmV?d00001 diff --git a/__pycache__/Robot.cpython-39.pyc b/__pycache__/Robot.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fb3f11193680618ab483b6c0d9b27a21ddfa6f53 GIT binary patch literal 2199 zcma)7%Wfk@6s<=)Z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Z|WC_;%D8aj`Hc+F>AI~$G%+O`pdc>UYVW+pw=>M8o@i_8pt XRr?EfNpj&{Va=CR3pr&D#PNRtgeb+7 literal 0 HcmV?d00001 diff --git a/__pycache__/RobotCompletCode.cpython-39.pyc b/__pycache__/RobotCompletCode.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4265ef28c5d79e150660a0cf013ba840ebe49494 GIT binary patch literal 4631 zcmbVP-*4N-9ltx0G9}BltjLLfq)n5wY1B1#>TKACWlgtqSTQ6t#Fn^ z`AEl!AY;Is_dT!kgWWg(7sLJxzV69S!&Y<;!`k)pJxU5iGH6f={NC|&M}F>epYQj+ z*PNRxFC7NL~gWKEfT`gpo}04(oDDY2!F1%n)QC8$4 z%95cYd;Ac`?F?iN4FNKrW?=77;<(C zoSuCSb1EV;==fn|sb;V3p3Tv}Hkl$!-BdFu6t${(G7HpdL}stqbtALu^*q?-Gp}Xh zkMTuyQp#Q2!FiaW7#eLcWPe~oz5>-fu4)}ox*|9N% zKrufdjT3{j-Kw6Yxus??Qqg-AQHvQ`Qj7i^o+8T&-EI&SfZ)M?w{9pn9*g)+#GmRZ z$A)N(Oz<7PgIYkK7`J&<49;gKL)}_>uG9?|t%!wN&*KUzLw?LO`Wn!S17paJIjzzO zylvMe+^2l2F4PM8Msq|CR;Us5T~|UB8e!pSv$N+0Y7Je~MKZKN3A8qbJ)#lsqdm|9 z5fwgI&Eg$*oWe}pPcXlQ2hz_m*QhH8P}8vhVy+RF2(fw-oxq=F)!cEP2kKJXqVZZ9 zZwxnubcQC_>~uar_ZTRj=Yy48pwzEL*v1#t$yqeFAEH7k*kP)IQq-7M1_yRvg*FV* zKd?h9lQwgOod{Bl){C{JrPBV-^-ur&_pknaCsvPk6jLqZ{c4qro@K4&_Yge8cx4)) zPs=oxkWEWQj;gNGfay7FYJPDB8*QVF3bsGhbID2Y557VC3j9dbk`_$|5YnIuECxBvlTG}a`Vt>CI2bvUMMgFR}iG5b^<^K<^WfAAC*# zl)PO7CD#MZ8l>bkHU@~`-~RkBbp7iNHh@acSK*Tc3blcOX{eO|+DP`=LZ`6`u4GZB zyJuj&g3p-MB%kUA!C5Dh158oi_$^@>^H$)6Zw5Jt($mZ!GVm5n9BqGN;>M)K5soX$ zzVdKH3;XWWT0SOBqfIYo6;r*Zz|aa#=%ImF{umu| zxm{}ZLho)GB1MNW!|!H6<&K#GHpMgf=QPifgYn7sOuVW3Ed{u5*G_-V3H?_1bj*44=)VyQZD@@wA?I3FJu6Ik57E zWMEB1O?xSkjr|z06L*4G^;5$2Du0h+22 zDT>)kE%A^5eg}K0Aye6~h4FMg)bZ(0sL;+Sk=aZ0NJuMDFC^+SiMoAc9&jAM>@Rf2 z93oRV}(AhN;^%upaZ;zMLbvWUBcH8Nr2mf3NxwEG*KEtR+8BMJpxMQNBK zgsBrt>>e+(aGgw9`tT7M9k-WAt0-R8ExlVh^U7^@ko1gBCeB=!4q%i~b-W;qxTmhs zx26*-oL)k||3~~0ya&S!fvv!_GWN?t)#eqQb(Nr&>eqRRJiTga2`CSl2>1aWzRwa2 zS%ZYnWpVVwvWz22z4ZEo#z~RRMB@<8<18aZ$c*2SG?BjoZa|E^niIR4@SL3dd-SHQ z`dVZ+bZ*;dM5RWf>&v~4i+Z`y*xhS(XpI^TXKs?QHjof%piUWWk8t7*?$H_=L8v0b z>xJq9aH%)QP{O3%CPT*uo$STinBI2j6sY%mb&G0xyZ8y!bR@e?HSLvj5>US&^Gh-> zIngyb&M6B0B-!8|j4j3?qhM#m63a(RrYh_i+pkNrlUV2U**rXveLLpyLt0pU#4KB7UJ%~`xntka literal 0 HcmV?d00001 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'):