Skip to content

Commit 3438f43

Browse files
committed
[#1379] update hingedJointArrayMotor unit test for tracking
1 parent 8c280db commit 3438f43

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/fswAlgorithms/effectorInterfaces/hingedJointArrayMotor/_UnitTest/test_hingedJointArrayMotor.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,21 @@
2424
from Basilisk.architecture import messaging
2525
from Basilisk.fswAlgorithms import hingedJointArrayMotor
2626

27-
def jointTorques(M, K, P, theta, thetaDot, desTheta, desThetaDot, bias, maxTorque=None):
27+
def jointTorques(M, K, P, theta, thetaDot, desTheta, desThetaDot, desThetaDDot, bias, maxTorque=None):
2828
M = np.asarray(M, dtype=float)
2929
K = np.asarray(K, dtype=float)
3030
P = np.asarray(P, dtype=float)
3131
theta = np.asarray(theta, dtype=float).reshape(-1)
3232
thetaDot = np.asarray(thetaDot, dtype=float).reshape(-1)
3333
desTheta = np.asarray(desTheta, dtype=float).reshape(-1)
3434
desThetaDot= np.asarray(desThetaDot, dtype=float).reshape(-1)
35+
desThetaDDot = np.asarray(desThetaDDot, dtype=float).reshape(-1)
3536
bias = np.asarray(bias, dtype=float).reshape(-1)
3637

3738
nj = theta.size
38-
e = theta - desTheta
39+
e = np.arctan2(np.sin(theta - desTheta), np.cos(theta - desTheta))
3940
edot = thetaDot - desThetaDot
40-
theta_ddot_des = -(K @ e) - (P @ edot)
41+
theta_ddot_des = desThetaDDot - (K @ e) - (P @ edot)
4142

4243
Mtt = M[0:3,0:3]
4344
Mtth = M[0:3,6:6+nj]
@@ -149,14 +150,18 @@ def test_hingedJointArrayMotor(nonActForces, maxTorque, numJoints, numSpacecraft
149150

150151
# create the desired joint state input message
151152
desJointStateInMsgData = messaging.JointArrayStateMsgPayload()
152-
desTheta = [0.12] * (numJoints * numSpacecraft)
153-
desThetaDot = [0.05] * (numJoints * numSpacecraft)
153+
desTheta = [0.12] * (numJoints * numSpacecraft) #[rad]
154+
desThetaDot = [0.05] * (numJoints * numSpacecraft) #[rad/s]
155+
desThetaDDot = [0.002] * (numJoints * numSpacecraft) #[rad/s^2]
154156
desJointStateInMsgData.states.clear()
155157
desJointStateInMsgData.stateDots.clear()
158+
desJointStateInMsgData.stateDDots.clear()
156159
for v in np.asarray(desTheta).flatten():
157160
desJointStateInMsgData.states.push_back(float(v))
158161
for v in np.asarray(desThetaDot).flatten():
159162
desJointStateInMsgData.stateDots.push_back(float(v))
163+
for v in np.asarray(desThetaDDot).flatten():
164+
desJointStateInMsgData.stateDDots.push_back(float(v))
160165

161166
# create the joint reactions input message
162167
JointReactionsInMsgData = messaging.MJJointReactionsMsgPayload()
@@ -252,6 +257,7 @@ def test_hingedJointArrayMotor(nonActForces, maxTorque, numJoints, numSpacecraft
252257
thetaDot_sc = thetaDot[0:numJoints]
253258
desTheta_sc = desTheta[sc*numJoints:(sc+1)*numJoints]
254259
desThetaDot_sc = desThetaDot[sc*numJoints:(sc+1)*numJoints]
260+
desThetaDDot_sc = desThetaDDot[sc*numJoints:(sc+1)*numJoints]
255261
bias_sc = -reactionForces[startIdx:startIdx+6+numJoints]
256262

257263
if maxTorque:
@@ -260,7 +266,8 @@ def test_hingedJointArrayMotor(nonActForces, maxTorque, numJoints, numSpacecraft
260266
uMax_sc = None
261267

262268
torques_sc = jointTorques(M_sc, K_sc, P_sc, theta_sc, thetaDot_sc,
263-
desTheta_sc, desThetaDot_sc, bias_sc, maxTorque=uMax_sc)
269+
desTheta_sc, desThetaDot_sc, desThetaDDot_sc,
270+
bias_sc, maxTorque=uMax_sc)
264271
expectedTorques[sc*numJoints:(sc+1)*numJoints] = torques_sc
265272

266273
# Assert the motor torques are correct

0 commit comments

Comments
 (0)