55#define DBG_LEVEL DBG_LOG
66#include <rtdbg.h>
77
8- #define DEFAULT_VELOCITY_LINEAR_X 0.2
9- #define DEFAULT_VELOCITY_LINEAR_Y 0.2
10- #define DEFAULT_VELOCITY_ANGULAR_Z 1
11-
128chassis_t chassis_create (wheel_t * c_wheels , kinematics_t c_kinematics )
139{
1410 // Malloc memory for new chassis
@@ -25,8 +21,10 @@ chassis_t chassis_create(wheel_t* c_wheels, kinematics_t c_kinematics)
2521 return new_chassis ;
2622}
2723
28- void chassis_destroy (chassis_t chas )
24+ rt_err_t chassis_destroy (chassis_t chas )
2925{
26+ RT_ASSERT (chas != RT_NULL );
27+
3028 for (int i = 0 ; i < chas -> c_kinematics -> total_wheels ; i ++ )
3129 {
3230 LOG_I ("Free wheel %d" , i );
@@ -35,10 +33,14 @@ void chassis_destroy(chassis_t chas)
3533 kinematics_destroy (chas -> c_kinematics );
3634
3735 rt_free (chas );
36+
37+ return RT_EOK ;
3838}
3939
4040rt_err_t chassis_enable (chassis_t chas )
4141{
42+ RT_ASSERT (chas != RT_NULL );
43+
4244 for (int i = 0 ; i < chas -> c_kinematics -> total_wheels ; i ++ )
4345 {
4446 LOG_I ("Enabling wheel %d" , i );
@@ -50,20 +52,35 @@ rt_err_t chassis_enable(chassis_t chas)
5052
5153rt_err_t chassis_disable (chassis_t chas )
5254{
53- // TODO
55+ RT_ASSERT (chas != RT_NULL );
56+
57+ for (int i = 0 ; i < chas -> c_kinematics -> total_wheels ; i ++ )
58+ {
59+ LOG_I ("Disabling wheel %d" , i );
60+ wheel_disable (chas -> c_wheels [i ]);
61+ }
5462
5563 return RT_EOK ;
5664}
5765
5866rt_err_t chassis_reset (chassis_t chas )
5967{
60- // TODO
68+ RT_ASSERT (chas != RT_NULL );
69+
70+ for (int i = 0 ; i < chas -> c_kinematics -> total_wheels ; i ++ )
71+ {
72+ LOG_I ("Reset wheel %d" , i );
73+ wheel_reset (chas -> c_wheels [i ]);
74+ }
75+ kinematics_reset (chas -> c_kinematics );
6176
6277 return RT_EOK ;
6378}
6479
6580rt_err_t chassis_set_velocity (chassis_t chas , struct velocity target_velocity )
6681{
82+ RT_ASSERT (chas != RT_NULL );
83+
6784 rt_int16_t * res_rpm = kinematics_get_rpm (* chas -> c_kinematics , target_velocity );
6885 chassis_set_rpm (chas , res_rpm );
6986
@@ -72,24 +89,22 @@ rt_err_t chassis_set_velocity(chassis_t chas, struct velocity target_velocity)
7289
7390rt_err_t chassis_set_rpm (chassis_t chas , rt_int16_t target_rpm [])
7491{
92+ RT_ASSERT (chas != RT_NULL );
93+
7594 // Set new speed
7695 for (int i = 0 ; i < chas -> c_kinematics -> total_wheels ; i ++ )
7796 {
7897 LOG_I ("Set wheel %d speed %d rpm" , i , target_rpm [i ]);
7998 wheel_set_rpm (chas -> c_wheels [i ], target_rpm [i ]);
8099 }
81100
82- for (int i = 0 ; i < chas -> c_kinematics -> total_wheels ; i ++ )
83- {
84- wheel_update (chas -> c_wheels [i ]);
85- }
86-
87101 return RT_EOK ;
88102}
89103
90104rt_err_t chassis_update (chassis_t chas )
91105{
92- // TODO
106+ RT_ASSERT (chas != RT_NULL );
107+
93108 for (int i = 0 ; i < chas -> c_kinematics -> total_wheels ; i ++ )
94109 {
95110 wheel_update (chas -> c_wheels [i ]);
@@ -99,6 +114,8 @@ rt_err_t chassis_update(chassis_t chas)
99114
100115rt_err_t chassis_straight (chassis_t chas , float linear_x )
101116{
117+ RT_ASSERT (chas != RT_NULL );
118+
102119 struct velocity target_velocity = {
103120 .linear_x = linear_x ,
104121 .linear_y = 0.0f ,
@@ -110,6 +127,8 @@ rt_err_t chassis_straight(chassis_t chas, float linear_x)
110127
111128rt_err_t chassis_move (chassis_t chas , float linear_y )
112129{
130+ RT_ASSERT (chas != RT_NULL );
131+
113132 struct velocity target_velocity = {
114133 .linear_x = 0.0f ,
115134 .linear_y = linear_y ,
@@ -121,6 +140,8 @@ rt_err_t chassis_move(chassis_t chas, float linear_y)
121140
122141rt_err_t chassis_rotate (chassis_t chas , float angular_z )
123142{
143+ RT_ASSERT (chas != RT_NULL );
144+
124145 struct velocity target_velocity = {
125146 .linear_x = 0.0f ,
126147 .linear_y = 0.0f ,
@@ -129,3 +150,30 @@ rt_err_t chassis_rotate(chassis_t chas, float angular_z)
129150 rt_int16_t * res_rpm = kinematics_get_rpm (* chas -> c_kinematics , target_velocity );
130151 return chassis_set_rpm (chas , res_rpm );
131152}
153+
154+ rt_err_t chassis_set_velocity_x (chassis_t chas , float linear_x )
155+ {
156+ RT_ASSERT (chas != RT_NULL );
157+
158+ chas -> c_velocity .linear_x = linear_x ;
159+ rt_int16_t * res_rpm = kinematics_get_rpm (* chas -> c_kinematics , chas -> c_velocity );
160+ return chassis_set_rpm (chas , res_rpm );
161+ }
162+
163+ rt_err_t chassis_set_velocity_y (chassis_t chas , float linear_y )
164+ {
165+ RT_ASSERT (chas != RT_NULL );
166+
167+ chas -> c_velocity .linear_y = linear_y ;
168+ rt_int16_t * res_rpm = kinematics_get_rpm (* chas -> c_kinematics , chas -> c_velocity );
169+ return chassis_set_rpm (chas , res_rpm );
170+ }
171+
172+ rt_err_t chassis_set_velocity_z (chassis_t chas , float angular_z )
173+ {
174+ RT_ASSERT (chas != RT_NULL );
175+
176+ chas -> c_velocity .angular_z = angular_z ;
177+ rt_int16_t * res_rpm = kinematics_get_rpm (* chas -> c_kinematics , chas -> c_velocity );
178+ return chassis_set_rpm (chas , res_rpm );
179+ }
0 commit comments