@@ -57,7 +57,8 @@ def WrapperMain_function(target_folder, controller_type, wrapper_control_paramet
5757 global angular_error_dot , u2 , u3 , u4 , mu_baseline_tran , mu_adaptive_tran , Moment_baseline , Moment_adaptive
5858 global mu_PD_baseline_tran , Moment_baseline_PI , e_tran , integral_eQe_tran , e_rot , integral_eQe_rot
5959 global epsilon_tran , integral_epsQeps_tran , epsilon_rot , integral_epsQeps_rot , e_transient_tran
60- global integral_etQet_tran , e_transient_rot , integral_etQet_rot , omega_ref_dot
60+ global integral_etQet_tran , e_transient_rot , integral_etQet_rot , omega_ref_dot , omega_cmd , omega_cmd_dot
61+ global Jacobian_matrix , Jacobian_matrix_dot
6162
6263 #%% File settings
6364
@@ -336,7 +337,8 @@ def WrapperMain_function(target_folder, controller_type, wrapper_control_paramet
336337 mfloor = chrono .ChBodyEasyBox (50 , 0.1 , 50 , 1000 ,True ,True , contact_material_floor )
337338 mfloor .SetName ('Floor' )
338339 mfloor .SetBodyFixed (True )
339- mfloor .SetPos (chrono .ChVectorD (0 ,- 0.3 ,0 ))
340+ mfloor_Yposition = 0.3
341+ mfloor .SetPos (chrono .ChVectorD (0 ,- mfloor_Yposition ,0 ))
340342 # mfloor.SetPos(chrono.ChVectorD(0,-0.5,0))
341343 mfloor .GetVisualShape (0 ).SetTexture (chrono .GetChronoDataFile ("textures/light_gray.png" ))
342344 # mfloor.GetVisualShape(0).SetTexture(chrono.GetChronoDataFile("textures/concrete.jpg"))
@@ -900,13 +902,34 @@ def WrapperMain_function(target_folder, controller_type, wrapper_control_paramet
900902 ####################################################################################################################################################################
901903
902904 elif trajectory_type == 'piecewisePolynomial_trajectory' :
903- pp_coefficients = np .loadtxt (open ("trajectory_PolynomialCoefficientMatrix.csv" ,
904- "rb" ), delimiter = "," , skiprows = 0 )
905+ pp_coefficients = np .loadtxt (open (
906+ "trajectory_PolynomialCoefficientMatrix.csv" ,
907+ "rb" ), delimiter = "," , skiprows = 0 )
905908 waypointTimes = np .loadtxt (open ("trajectory_WaypointTimes.csv" , "rb" ),
906909 delimiter = "," , skiprows = 0 )
907910
908911 trajectory_instance = piecewisePolynomial_trajectory ()
909- trajectory_instance .set_parameters (pp_coefficients )
912+ trajectory_instance .set_parameters (pp_coefficients , waypointTimes )
913+
914+ # Create a ChLinePath geometry, and insert sub-paths
915+ mpath = chrono .ChLinePath ()
916+ [pos_x , pos_y , pos_z ] = trajectory_instance .ComputePositionVector (0.01 )
917+
918+ for i in range (pos_x .size - 1 ):
919+ mpath .AddSubLine (chrono .ChLineSegment (
920+ chrono .ChVectorD (pos_x [i ],
921+ - pos_z [i ] + mfloor_Yposition ,
922+ pos_y [i ]),
923+ chrono .ChVectorD (pos_x [i + 1 ],
924+ - pos_z [i + 1 ] + mfloor_Yposition ,
925+ pos_y [i + 1 ])))
926+
927+ # Create a ChLineShape, a visualization asset for lines.
928+ # The ChLinePath is a special type of ChLine and it can be visualized.
929+ mpathasset = chrono .ChLineShape ()
930+ mpathasset .SetLineGeometry (mpath )
931+ mpathasset .SetColor (chrono .ChColor (0 ,0 ,0 ))
932+ mfloor .AddVisualShape (mpathasset )
910933
911934 #%% Controller Inizialization
912935
@@ -926,6 +949,11 @@ def WrapperMain_function(target_folder, controller_type, wrapper_control_paramet
926949 Moment_adaptive = np .zeros ((3 ,1 ))
927950
928951 omega_ref_dot = np .zeros ((3 ,1 ))
952+ omega_ref = np .zeros ((3 ,1 ))
953+ omega_cmd = np .zeros ((3 ,1 ))
954+ omega_cmd_dot = np .zeros ((3 ,1 ))
955+ Jacobian_matrix = np .matrix (np .zeros ((3 ,3 )))
956+ Jacobian_matrix_dot = np .matrix (np .zeros ((3 ,3 )))
929957
930958
931959 # Maximum thrust produced by a single motor = 1355 grams = 1.355 kg = 1.355 kg * 9.81 m/s^2 = 13.28 N
@@ -1260,7 +1288,8 @@ def MRACwithBASELINE(t, y):
12601288 global mu_x , mu_y , mu_z , u1 , roll_ref , pitch_ref , roll_ref_dot , pitch_ref_dot , roll_ref_ddot , pitch_ref_ddot
12611289 global angular_position_ref_dot , angular_position_ref_ddot , Jacobian_matrix_inverse , angular_position_dot
12621290 global angular_error_dot , u2 , u3 , u4 , mu_baseline_tran , mu_adaptive_tran , Moment_baseline , Moment_adaptive
1263- global mu_PD_baseline_tran , Moment_baseline_PI , omega_ref_dot
1291+ global mu_PD_baseline_tran , Moment_baseline_PI , omega_ref_dot , omega_cmd , omega_cmd_dot , Jacobian_matrix
1292+ global Jacobian_matrix_dot
12641293
12651294
12661295 state_phi_ref_diff = y [0 :2 ] # State of the differentiator for phi_ref (roll_ref)
@@ -3104,7 +3133,8 @@ def MRACwithBASELINE_SafetyMechanism(t, y):
31043133 global mu_x , mu_y , mu_z , u1 , roll_ref , pitch_ref , roll_ref_dot , pitch_ref_dot , roll_ref_ddot , pitch_ref_ddot
31053134 global angular_position_ref_dot , angular_position_ref_ddot , Jacobian_matrix_inverse , angular_position_dot
31063135 global angular_error_dot , u2 , u3 , u4 , mu_baseline_tran , mu_adaptive_tran , Moment_baseline , Moment_adaptive
3107- global mu_PD_baseline_tran , Moment_baseline_PI , omega_ref_dot
3136+ global mu_PD_baseline_tran , Moment_baseline_PI , omega_ref_dot , omega_cmd , omega_cmd_dot , Jacobian_matrix
3137+ global Jacobian_matrix_dot
31083138
31093139
31103140 state_phi_ref_diff = y [0 :2 ] # State of the differentiator for phi_ref (roll_ref)
@@ -3263,7 +3293,7 @@ def MRACwithBASELINE_SafetyMechanism(t, y):
32633293 Jacobian_matrix = np .matrix ([[1 , 0 , - math .sin (pitch )],
32643294 [0 , math .cos (roll ), math .sin (roll ) * math .cos (pitch )],
32653295 [0 , - math .sin (roll ), math .cos (roll ) * math .cos (pitch )]])
3266-
3296+ print ( 'HELLO Jacobian_matrix' )
32673297 omega_cmd = Jacobian_matrix * (- KP_rot * angular_error + angular_position_ref_dot )
32683298 omega_cmd_dot = Jacobian_matrix_dot * (- KP_rot * angular_error + angular_position_ref_dot ) + Jacobian_matrix * (- KP_rot * angular_error_dot + angular_position_ref_ddot )
32693299
@@ -3673,8 +3703,7 @@ def MRACwithBASELINE_SafetyMechanism(t, y):
36733703 [translational_position_in_I_user ,
36743704 translational_velocity_in_I_user ,
36753705 translational_acceleration_in_I_user ] = (trajectory_instance .
3676- user_defined_trajectory (time_now - controller_start_time ,
3677- waypointTimes ))
3706+ user_defined_trajectory (time_now - controller_start_time ))
36783707 [yaw_ref ,
36793708 yaw_ref_dot ,
36803709 yaw_ref_ddot ] = trajectory_instance .user_defined_yaw ()
@@ -4657,7 +4686,16 @@ def MRACwithBASELINE_SafetyMechanism(t, y):
46574686 print ('\n Simulation time: ' , time_now )
46584687
46594688
4660- print ('omega_ref_dot: ' , omega_ref_dot )
4689+ print ('omega_ref_dot: ' , '%.4f' % omega_ref_dot [0 ], '%.4f' % omega_ref_dot [1 ], '%.4f' % omega_ref_dot [2 ])
4690+ print ('omega_ref: ' , '%.4f' % omega_ref [0 ], '%.4f' % omega_ref [1 ], '%.4f' % omega_ref [2 ])
4691+ print ('omega_cmd_dot: ' , '%.8f' % omega_cmd_dot [0 ],
4692+ '%.8f' % omega_cmd_dot [1 ],
4693+ '%.8f' % omega_cmd_dot [2 ])
4694+ print ('omega_cmd: ' , '%.4f' % omega_cmd [0 ], '%.4f' % omega_cmd [1 ], '%.4f' % omega_cmd [2 ])
4695+ print ('Jacobian_matrix_dot: ' , Jacobian_matrix_dot )
4696+ print ('Jacobian_matrix: ' , Jacobian_matrix )
4697+
4698+
46614699 # print('z - z_ref: ', pos_pixhawk_LOC_to_GLOB_NED.z - z_ref)
46624700 print ('Z_onboard: ' , '%.4f' % pos_pixhawk_LOC_to_GLOB_NED .z )
46634701 # print('(G_acc - controller_z_output)*mass_total: ', (G_acc + controller_z_output)*mass_total)
@@ -4709,11 +4747,13 @@ def MRACwithBASELINE_SafetyMechanism(t, y):
47094747
47104748
47114749 # print('Pixhawk LOCAL Position: ', chvector_to_list(pos_pixhawk_LOC))
4712- print ('Pixhawk GLOBAL Position: ' , chcoordsys_to_list (coord_pixhawk_GLOB )[0 ])
4750+ print ('Pixhawk GLOBAL Position: ' , '%.4f' % chcoordsys_to_list (coord_pixhawk_GLOB )[0 ][0 ],
4751+ '%.4f' % chcoordsys_to_list (coord_pixhawk_GLOB )[0 ][1 ],
4752+ '%.4f' % chcoordsys_to_list (coord_pixhawk_GLOB )[0 ][2 ])
47134753 # print('Pixhawk GLOBAL Velocity: ', chcoordsys_to_list(coord_dt_pixhawk_GLOB)[0])
47144754 # print('Pixhawk LOCAL Velocity_T: ', chvector_to_list(vel_pixhawk_LOC_T))
47154755 # print('Pixhawk LOCAL Velocity: ', chvector_to_list(vel_pixhawk_LOC))
4716- print ('Pixhawk GLOBAL Velocity NORM: ' , LA .norm (np .asarray (chcoordsys_to_list (coord_dt_pixhawk_GLOB )[0 ])))
4756+ print ('Pixhawk GLOBAL Velocity NORM: ' , '%.4f' % LA .norm (np .asarray (chcoordsys_to_list (coord_dt_pixhawk_GLOB )[0 ])))
47174757 # print('Pixhawk LOCAL Velocity_T NORM: ', LA.norm(np.asarray(chvector_to_list(vel_pixhawk_LOC_T))))
47184758 # print('Pixhawk LOCAL Velocity NORM: ', LA.norm(np.asarray(chvector_to_list(vel_pixhawk_LOC))),'\n')
47194759
0 commit comments