2424from Basilisk .architecture import messaging
2525from 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 ]
@@ -151,12 +152,15 @@ def test_hingedJointArrayMotor(nonActForces, maxTorque, numJoints, numSpacecraft
151152 desJointStateInMsgData = messaging .JointArrayStateMsgPayload ()
152153 desTheta = [0.12 ] * (numJoints * numSpacecraft )
153154 desThetaDot = [0.05 ] * (numJoints * numSpacecraft )
155+ desThetaDDot = [0.002 ] * (numJoints * numSpacecraft )
154156 desJointStateInMsgData .states .clear ()
155157 desJointStateInMsgData .stateDots .clear ()
156158 for v in np .asarray (desTheta ).flatten ():
157159 desJointStateInMsgData .states .push_back (float (v ))
158160 for v in np .asarray (desThetaDot ).flatten ():
159161 desJointStateInMsgData .stateDots .push_back (float (v ))
162+ for v in np .asarray (desThetaDDot ).flatten ():
163+ desJointStateInMsgData .stateDDots .push_back (float (v ))
160164
161165 # create the joint reactions input message
162166 JointReactionsInMsgData = messaging .MJJointReactionsMsgPayload ()
@@ -252,6 +256,7 @@ def test_hingedJointArrayMotor(nonActForces, maxTorque, numJoints, numSpacecraft
252256 thetaDot_sc = thetaDot [0 :numJoints ]
253257 desTheta_sc = desTheta [sc * numJoints :(sc + 1 )* numJoints ]
254258 desThetaDot_sc = desThetaDot [sc * numJoints :(sc + 1 )* numJoints ]
259+ desThetaDDot_sc = desThetaDDot [sc * numJoints :(sc + 1 )* numJoints ]
255260 bias_sc = - reactionForces [startIdx :startIdx + 6 + numJoints ]
256261
257262 if maxTorque :
@@ -260,7 +265,8 @@ def test_hingedJointArrayMotor(nonActForces, maxTorque, numJoints, numSpacecraft
260265 uMax_sc = None
261266
262267 torques_sc = jointTorques (M_sc , K_sc , P_sc , theta_sc , thetaDot_sc ,
263- desTheta_sc , desThetaDot_sc , bias_sc , maxTorque = uMax_sc )
268+ desTheta_sc , desThetaDot_sc , desThetaDDot_sc ,
269+ bias_sc , maxTorque = uMax_sc )
264270 expectedTorques [sc * numJoints :(sc + 1 )* numJoints ] = torques_sc
265271
266272 # Assert the motor torques are correct
0 commit comments