Skip to content

Commit 48f5cdf

Browse files
committed
fix(limPID): removed PID limiter for small angles
Written by: V.S. Boon Committed on: 19-12-2021 Version: 1.0.0
1 parent ae06e99 commit 48f5cdf

File tree

4 files changed

+33
-36
lines changed

4 files changed

+33
-36
lines changed

raspberry_pi/control/control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def PosControl(sConfig: Union[np.ndarray, List], eConfig: Union[np.ndarray, List
8888
timeScaling=5)
8989
print(f"Total estimated time for trajectory: {round(dt*traj[:,0].size, 2)} s")
9090
traj, velTraj, accTraj = TrajDerivatives(traj, method, robot, dt)
91-
g = np.array([0,0,-9.81*2]) #EXPERIMENTAL!
91+
g = np.array([0,0,-9.81]) #EXPERIMENTAL!
9292
FTip = np.zeros(6) #Position control, --> assume no end-effector force.
9393
tauPID = np.zeros(traj[0,:].size)
9494
n = -1 #iterator
@@ -136,7 +136,7 @@ def PosControl(sConfig: Union[np.ndarray, List], eConfig: Union[np.ndarray, List
136136
#Take care of communication on an interval basis:
137137
if (time.perf_counter() - lastWrite >= dtComm):
138138
SReadAndParse(serial, localMu)
139-
serial.mSpeed[:-1] = [abs(val) for val in PWM]
139+
serial.mSpeed[:-1] = [abs(val) if abs(val) < 255 else 255 for val in PWM]
140140
serial.rotDirDes = [np.sign(PWM[i]) if
141141
np.sign(PWM[i]) == 1 else 0 for i in
142142
range(serial.lenData-1)]

raspberry_pi/main.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

312311
if __name__ == "__main__":
313312
robotSelected = False

raspberry_pi/robot_init.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,17 @@
8888

8989
"""Here, we add a friction model to our joints for a second (hopefully
9090
more accurate) instance of the robot. Values should be experimentally confirmed!"""
91-
PWMMinWormGear = 80 #Can be confirmed & adjusted!
92-
PWMMinSprocket = 40 #Should be confirmed & adjusted!
9391
eff = [0.2, 0.2, 0.6, 0.6, 0.6]
94-
tauStat0 = 3 #Determined practically (trial-and-error)
95-
tauStat1 = 2 #Determined practically (trial-and-error)
96-
tauStat2 = 1.35 #Experimentally determined, tweaked practically
97-
tauStat3 = 1.3 #Determined practically (trial-and-error)
98-
tauStat4 = 0.7 #Determined practically (trial-and-error)
99-
#tauStat0 = 5
100-
#tauStat1 = 5
101-
#tauStat2 = 2
102-
#tauStat3 = 2
103-
#tauStat4 = 2
92+
# tauStat0 = 3 #Determined practically (trial-and-error)
93+
# tauStat1 = 2 #Determined practically (trial-and-error)
94+
# tauStat2 = 1.35 #Experimentally determined, tweaked practically
95+
# tauStat3 = 1.3 #Determined practically (trial-and-error)
96+
# tauStat4 = 0.7 #Determined practically (trial-and-error)
97+
tauStat0 = 0
98+
tauStat1 = 1.35
99+
tauStat2 = 1.35
100+
tauStat3 = 0.2
101+
tauStat4 = 0.2
104102

105103
tauStat = [tauStat0, tauStat1, tauStat2, tauStat3, tauStat4]
106104
tauKin = [0.2*stat for stat in tauStat]

raspberry_pi/settings.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
settings related to main.py, kindly do so here and in robot_init.py."""
66
sett = dict()
77
#Time between refreshing frames for the UI [s].
8-
sett['dtFrame'] = 0.1
8+
sett['dtFrame'] = 0.05
99
#Time between PID updates. Note: higher dtPID leads to more instability! [s].
1010
sett['dtPID'] = 0.05
1111
#Data communication interval with Teensy [s].
1212
sett['dtComm'] = 0.05 #Ensure equal to one in Teensy code [s].
1313
#Time between FF updates [s].
14-
sett['dtFF'] = 0.05
14+
sett['dtFF'] = 0.05
1515
#Time interval between trajectory sub-configurations [s].
1616
sett['dtPosConfig'] = 0.05
1717
#Interval for updating the FF & PID while holding a position [s].
@@ -21,19 +21,19 @@
2121
#Maximum rotational velocity of the joints in position control [rad/s].
2222
sett['wMax'] = 0.04*np.pi
2323
#Proportional gain for position control [(N/m)/rad].
24-
sett['kPP'] = np.diag(np.array([14,22,28,6,6]))
24+
sett['kPP'] = np.diag(np.array([14,28,26,6,6]))
2525
#Integral gain for position control [(N/m)*s/rad].
26-
sett['kIP'] = np.diag(np.array([4,6,10,6,6]))
26+
sett['kIP'] = np.diag(np.array([4,6,12,3,3]))
2727
#Derivative gain for position control [(N/m)/(rad*s)].
28-
sett['kDP'] = np.diag(np.array([2,2,4,3,3]))
28+
sett['kDP'] = np.diag(np.array([2,2,4,1,1]))
2929
#Proportional gain for velocity control [(N/m)/(rad/s)].
3030
sett['kPV'] = np.diag(np.array([0,0,0,0,0]))
3131
#Integral gain for velocity control [(N/m)*s/(rad/s)].
3232
sett['kIV'] = np.diag(np.array([0,0,0,0,0]))
3333
#Derivative gain for velocity control [(N/m)/(rad)].
3434
sett['kDV'] = np.diag(np.array([0,0,0,0,0]))
3535
#PID object for position control.
36-
sett['PIDP'] = PID(sett['kPP'], sett['kIP'], sett['kDP'], ILim=np.array([7,7,7,7,7]))
36+
sett['PIDP'] = PID(sett['kPP'], sett['kIP'], sett['kDP'], ILim=np.array([2,2,2,2,2]))
3737
#PID object for velocity control
3838
sett['PIDV'] = PID(sett['kPV'], sett['kIV'], sett['kDV'], ILim=np.array([5,5,5,5,5]))
3939
#Joint speed increase for joint velocity control when pressing the

0 commit comments

Comments
 (0)