Skip to content

Commit e73bedc

Browse files
committed
docs(deprications)
Written by: V.S. Boon Committed on: 1-12-2021 Version: 1.0.0
1 parent 48f5cdf commit e73bedc

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

raspberry_pi/classes.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,20 @@ def __init__(self, lenData: int, joints: List[Joint], desAngles:
127127
should be removed and code refactored.
128128
"""
129129
self.lenData = lenData
130-
self.desAngle = desAngles
130+
self.desAngle = desAngles #Depricated
131131
self.joints = joints
132132
self.totCount = [0 for i in range(lenData)]
133133
self.rotDirCurr = [None for i in range(lenData)]
134134
self.current = [None for i in range(lenData)]
135135
self.homing = [None for i in range(lenData)]
136+
#Often used in the form SerialData.currAngle[:-1]
136137
self.currAngle = [0. for i in range(lenData)]
137138
self.prevAngle = [0. for i in range(lenData)]
138139
self.mSpeed = [0. for i in range(lenData)]
139140
self.rotDirDes = [0 for i in range(lenData)]
140-
self.dataOut = ['0|0|0' for i in range(lenData)]
141-
self.maxDeltaAngle = maxDeltaAngle
142-
self.angleTol = angleTol
141+
self.dataOut = ['0|0' for i in range(lenData)]
142+
self.maxDeltaAngle = maxDeltaAngle #Depricated
143+
self.angleTol = angleTol #Depricated
143144
self.limBool = [False for i in range(lenData)]
144145

145146
def ExtractVars(self, dataPacket: List[str]):
@@ -153,7 +154,7 @@ def ExtractVars(self, dataPacket: List[str]):
153154
"""
154155
for i in range(self.lenData):
155156
args = dataPacket[i].split('|')
156-
if len(args) == 3:
157+
if len(args) >= 3:
157158
self.homing[i] = args[2]
158159
self.homing[i] = int(self.homing[i])
159160
if len(args) == 4:
@@ -163,7 +164,6 @@ def ExtractVars(self, dataPacket: List[str]):
163164
self.totCount[i] = int(self.totCount[i])
164165
self.rotDirCurr[i] = int(self.rotDirCurr[i])
165166
self.prevAngle[i] = self.currAngle[i]
166-
#TODO: CHECK!!!
167167
if i == self.lenData-1:
168168
#Gripper doesn't have an 'angle'
169169
self.currAngle[i] = self.totCount[i]
@@ -194,6 +194,7 @@ def ExtractVars(self, dataPacket: List[str]):
194194

195195
def Dtheta2Mspeed(self, dtheta: "np.ndarray[float]",
196196
dthetaMax: List[float], PWMMin: int, PWMMax: int):
197+
#DEPRICATED!
197198
"""Translates desired motor velocities in rad/s to PWM.
198199
:param dtheta: Numpy array of motor velocities in [rad/s].
199200
:param dthetaMax: Angular velocity of each motor at a PWM of 255.
@@ -208,6 +209,7 @@ def Dtheta2Mspeed(self, dtheta: "np.ndarray[float]",
208209
for i in range(self.lenData-1)] #Rudimentary solution, PID will help!
209210

210211
def CheckCommFault(self) -> bool:
212+
#DEPRICATED
211213
"""Checks if data got corrupted using a maximum achievable
212214
change in angle between two timesteps.
213215
:return commFault: Boolean indicating if new angle is
@@ -229,6 +231,7 @@ def CheckCommFault(self) -> bool:
229231
return commFault
230232

231233
def CheckTolAng(self) -> bool:
234+
#DEPRICATED
232235
"""Determines if the desired angle has been reached within the
233236
given tolerance, and if the desired angle is reachable.
234237
If the desired angle is unreachable, the closest angle is chosen.
@@ -267,6 +270,7 @@ def CheckJointLim(self):
267270

268271

269272
def GetDir(self):
273+
#DEPRICATED
270274
"""Gives the desired direction of rotation.
271275
"""
272276
for i in range(self.lenData):
@@ -279,7 +283,8 @@ def GetDir(self):
279283
self.rotDirDes[i] = self.rotDirCurr[i]
280284

281285
def PControl1(self, i: int, mSpeedMax: int, mSpeedMin: int):
282-
"""Gives motor speed commands proportional to the angle error.
286+
#DEPRICATED
287+
"""Gives motor speed commands propor tional to the angle error.
283288
:param i: Current iteration number.
284289
:param mSpeedMax: Maximum rotational speed,
285290
portrayed in PWM [0, 255].

raspberry_pi/control/control.py

Lines changed: 1 addition & 1 deletion
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]) #EXPERIMENTAL!
91+
g = np.array([0,0,-9.81])
9292
FTip = np.zeros(6) #Position control, --> assume no end-effector force.
9393
tauPID = np.zeros(traj[0,:].size)
9494
n = -1 #iterator

raspberry_pi/experiments/hold_position.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pygame
1212
import matplotlib.pyplot as plt
1313
from dynamics.dynamics_funcs import FeedForward
14-
from robot_init import robotFric as Pegasus
14+
from robot_init import robot as Pegasus
1515
from settings import sett
1616
from typing import Tuple
1717
from classes import SerialData, Robot, PID
@@ -20,6 +20,7 @@
2020
from control.control import PosControl
2121
from main import HoldPos
2222

23+
dataMat = np.zeros((1,8)) #First three for encoder readings, second three for output torques
2324
serial = SerialData(6, Pegasus.joints)
2425
#port = FindSerial(askInput=True)[0]
2526
Teensy = StartComms('COM13') #TEMPORARY, REPLACE WITH port
@@ -31,26 +32,31 @@
3132
dtAct = sett['dtFF']*0.5
3233
dtComm = sett['dtComm']
3334
D = sett['D'] #Absolute rotational damper
34-
serial = SerialData(6, Pegasus.joints)
35+
SReadAndParse(serial, Teensy)
3536
thetaStart = np.array(serial.currAngle[:-1])
3637
#thetaDes = np.array([0*np.pi,0,0.5*np.pi,-0.5*np.pi,0.5*np.pi])
37-
thetaDes = np.array([0.2*np.pi,0,0,0,0])
38+
thetaDes = np.array([0.*np.pi,0.*np.pi,0*np.pi,0*np.pi,0])
3839
pygame.init()
3940
screen = pygame.display.set_mode([700, 500])
4041
background = pygame.image.load(os.path.join(parent,'control_overview.png'))
41-
PosControl(thetaStart, thetaDes, Pegasus, serial, 0.1, 0.1, 0.2, PIDObj, dtComm, dtAct, sett['dtFrame'], Teensy, screen, background)
42+
PosControl(thetaStart, thetaDes, Pegasus, serial, 0.1, 0.1, 0.1, PIDObj, dtComm, dtAct, sett['dtFrame'], Teensy, screen, background)
4243
lastHold = -100 #Last hold should run first
4344
lastComm = time.perf_counter()
4445
lastFrame = time.perf_counter()
4546
dtHold = sett['dtFF']
4647
dtFrame = sett['dtFrame']
4748
PWM = serial.mSpeed[:-1]
49+
newRow = np.zeros((1,8)) #TEMP
4850
print("Start holding")
4951
while True:
5052
if time.perf_counter() - lastHold >= dtHold:
51-
lastComm, lastFrame = HoldPos(serial, Teensy, Pegasus, PIDObj, thetaDes, lastComm, lastFrame, dtComm, dtHold, dtFrame, screen, background)
53+
lastComm, lastFrame, tau = HoldPos(serial, Teensy, Pegasus, PIDObj, thetaDes, lastComm, lastFrame, dtComm, dtHold, dtFrame, screen, background)
5254
lastHold = time.perf_counter()
55+
newRow[0,0:4] = np.array([np.array(serial.currAngle[1:-1]) - thetaDes[1:]])
56+
newRow[0,4:] = tau[1:]
57+
dataMat = np.vstack((dataMat, newRow))
5358
finally:
59+
np.savetxt("PIDDataLowAngle4.csv", dataMat, fmt="%.4f", delimiter=',')
5460
serial.dataOut = [f"{0|0}" for i in range(serial.lenData)]
5561
Teensy.write(f"{serial.dataOut}\n".encode('utf-8'))
5662
Teensy.__del__()

0 commit comments

Comments
 (0)