@@ -262,36 +262,35 @@ def HoldPos(serial: SerialData, Teensy: serial.Serial, robot: Robot, PIDObj: PID
262262 g = np .array ([0 ,0 ,- 9.81 ])
263263 tauFF = FeedForward (robot , thetaDes , np .zeros (5 ), np .zeros (5 ), g , FTip )
264264 tauPID = PIDObj .Execute (thetaDes , thetaCurr , dtHold )
265- for i in range (thetaCurr .size ):
266- if abs (thetaCurr [i ] - thetaDes [i ]) < eLim [i ]:
267- tauPID [i ] = 0
268265 tau = tauFF + tauPID
269266 tauFric = np .zeros (5 )
270267 for i in range (tau .size ):
271268 """Compute joint friction based on friction model of joint."""
272- if not np .isclose (tauPID [i ], 0 , atol = 1e-05 ) and np .isclose (dthetaCurr [i ], 0 , atol = 1e-01 ):
273- tauStat = robot .joints [i ].fricPar ['stat' ]
274- tauFric [i ] = tauStat * np .sign (tau [i ])
275- elif np .isclose (tauPID [i ], 0 , atol = 1e-05 ) and not np .isclose (dthetaCurr [i ],0 ,atol = 1e-01 ):
276- tauKin = robot .joints [i ].fricPar ['kin' ]
277- tauFric [i ] = tauKin * np .sign (tau [i ])
269+ # if not np.isclose(tauPID[i], 0, atol=1e-05) and np.isclose(dthetaCurr[i], 0, atol=1e-01):
270+ # tauStat = robot.joints[i].fricPar['stat']
271+ # tauFric[i] = tauStat*np.sign(tau[i])
272+ # elif np.isclose(tauPID[i], 0, atol=1e-05) and not np.isclose(dthetaCurr[i],0,atol=1e-01):
273+ # tauKin = robot.joints[i].fricPar['kin']
274+ # tauFric[i] = tauKin*np.sign(tau[i])
275+ tauStat = robot .joints [i ].fricPar ['stat' ]
276+ tauFric [i ] = tauStat
278277 tau += tauFric
279278 #Diff-drive properties:
280- tauJ4 = tau [3 ]
281- tauJ5 = tau [4 ]
279+ tauJ4 = tau [3 ]. copy ()
280+ tauJ5 = tau [4 ]. copy ()
282281 tau [3 ] = (- tauJ4 * 1.1 - tauJ5 ) #This motor struggle more than the other
283282 tau [4 ] = tauJ4 - tauJ5
284- PWM = tau * 33.78
285- PWM = np .round (LimDamping (thetaCurr , PWM , robot .limList , k = 20 ))
283+ PWM = np . round ( tau * 33.78 )
284+ # PWM = np.round(LimDamping(thetaCurr, PWM, robot.limList, k=20)) #DEBUG COMMENTED
286285
287286 if time .perf_counter () - lastComm >= dtComm :
288287 SReadAndParse (serial , Teensy )
289- serial .mSpeed [:- 1 ] = [abs (val ) for val in PWM ]
288+ serial .mSpeed [:- 1 ] = [abs (val ) if abs ( val ) < 255 else 255 for val in PWM ]
290289 serial .rotDirDes = [np .sign (PWM [i ]) if
291290 np .sign (PWM [i ]) == 1 else 0 for i in
292291 range (serial .lenData - 1 )]
293292 for i in range (serial .lenData - 1 ): #TODO: Add Gripper function
294- serial .dataOut [i ] = f"{ abs ( serial .mSpeed [i ]) } |" + \
293+ serial .dataOut [i ] = f"{ serial .mSpeed [i ]} |" + \
295294 f"{ serial .rotDirDes [i ]} "
296295 print (f"HoldPos: { serial .dataOut } " )
297296 #TODO: Replace last entry w/ gripper commands
@@ -307,7 +306,7 @@ def HoldPos(serial: SerialData, Teensy: serial.Serial, robot: Robot, PIDObj: PID
307306 screen .blit (background , (0 ,0 ))
308307 pygame .display .update ()
309308 lastFrame = time .perf_counter ()
310- return lastComm , lastFrame
309+ return lastComm , lastFrame , tau #TAU IS TEMP!
311310
312311if __name__ == "__main__" :
313312 robotSelected = False
0 commit comments