33 * See <https://www.gnu.org/licenses/> for details.
44 * Author: Dmitry Ponomarev <ponomarevda96@gmail.com>
55 * Author: Anastasiia Stepanova <asiiapine@gmail.com>
6+ * Author: Ilia Kliantsevich <iliawork112005@gmail.com>
67 */
78
89#include " feedback.hpp"
910#include " peripheral/pwm/pwm.hpp"
1011#include " peripheral/adc/circuit_periphery.hpp"
1112#include " drivers/rcpwm/rcpwm.hpp"
13+ #include " modules/rcout/dronecan_frontend/dronecan_frontend.hpp"
1214#include " params.hpp"
15+ #include " logging.hpp"
1316
1417REGISTER_MODULE (DronecanFeedbackModule)
1518
@@ -22,6 +25,7 @@ void DronecanFeedbackModule::update_params() {
2225 feedback_esc_enabled = static_cast <bool >(paramsGetIntegerValue (IntParamsIndexes::PARAM_FEEDBACK_ESC_ENABLE));
2326 feedback_actuator_enabled = static_cast <bool >(paramsGetIntegerValue (IntParamsIndexes::PARAM_FEEDBACK_ACTUATOR_ENABLE));
2427 feedback_hardpoint_enabled = static_cast <bool >(paramsGetIntegerValue (IntParamsIndexes::PARAM_FEEDBACK_HARDPOINT_ENABLE));
28+ feedback_gimbal_enabled = static_cast <Gimbal_enable>(paramsGetIntegerValue (IntParamsIndexes::PARAM_FEEDBACK_GIMBAL_ENABLE));
2529}
2630
2731void DronecanFeedbackModule::spin_once () {
@@ -42,11 +46,18 @@ void DronecanFeedbackModule::spin_once() {
4246 publish_hardpoint_status (pin_idx);
4347 }
4448 }
49+
50+ if (feedback_gimbal_enabled == Gimbal_enable::ENABLE_DEG){
51+ publish_gimbal_status_rpy ();
52+ }
53+ if (feedback_gimbal_enabled == Gimbal_enable::ENABLE_QUAT){
54+ publish_gimbal_status_quaternion ();
55+ }
4556}
4657
4758void DronecanFeedbackModule::publish_esc_status (uint8_t pin_idx) {
4859 esc_status.msg = {
49- .error_count = esc_status.msg .error_count + 1 ,
60+ .error_count = esc_status.msg .error_count + 1 , // FIXME: implement proper error counting
5061 .voltage = CircuitPeriphery::voltage_vin (),
5162 .current = CircuitPeriphery::current (),
5263 .temperature = static_cast <float >(CircuitPeriphery::temperature ()),
@@ -68,7 +79,6 @@ void DronecanFeedbackModule::publish_actuator_status(uint8_t pin_idx) {
6879 .force = CircuitPeriphery::current (),
6980 .speed = static_cast <float >(CircuitPeriphery::temperature ()),
7081
71- .reserved = 0 ,
7282 .power_rating_pct = Driver::RCPWM::get_pin_percent (pin_idx),
7383 };
7484
@@ -89,3 +99,58 @@ void DronecanFeedbackModule::publish_hardpoint_status(uint8_t pin_idx) {
8999 // Hardpoint serialization has a bug, let's skip it until it is fixed
90100 // hardpoint_status.publish();
91101}
102+
103+ void DronecanFeedbackModule::publish_gimbal_status_rpy () {
104+
105+ gimbal_status_pub.msg .gimbal_id = 0 ; //
106+ gimbal_status_pub.msg .mode .command_mode = 1 ;
107+
108+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [0 ] = 0 ; // X
109+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [1 ] = 0 ; // Y
110+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [2 ] = 0 ; // Z
111+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [3 ] = 1 ; // W
112+
113+ float roll_deg = 0 , pitch_deg = 0 , yaw_deg = 0 ;
114+ for (size_t i = 0 ; i < Driver::RCPWM::get_pins_amount (); ++i) {
115+ switch (Driver::RCPWM::get_pin_channel (i)) {
116+ case 0 : // Roll
117+ roll_deg = Driver::RCPWM::get_current_angle (gimbal::get_max_servos_angle (), i);
118+ break ;
119+ case 1 : // Pitch
120+ pitch_deg = Driver::RCPWM::get_current_angle (gimbal::get_max_servos_angle (), i);
121+ break ;
122+ case 2 : // Yaw
123+ yaw_deg = Driver::RCPWM::get_current_angle (gimbal::get_max_servos_angle (), i);
124+ break ;
125+ default :
126+ break ;
127+ }
128+ }
129+
130+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [0 ] = roll_deg; // X
131+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [1 ] = pitch_deg; // Y
132+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [2 ] = yaw_deg; // Z
133+
134+ gimbal_status_pub.publish ();
135+ }
136+
137+ void DronecanFeedbackModule::publish_gimbal_status_quaternion () {
138+
139+ gimbal_status_pub.msg .gimbal_id = 0 ;
140+ gimbal_status_pub.msg .mode .command_mode = 1 ;
141+
142+ // Set default values for safety
143+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [0 ] = 0 ; // X
144+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [1 ] = 0 ; // Y
145+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [2 ] = 0 ; // Z
146+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [3 ] = 1 ; // W
147+
148+ const float * q = gimbal::get_quaternion ();
149+
150+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [0 ] = q[0 ]; // X
151+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [1 ] = q[1 ]; // Y
152+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [2 ] = q[2 ]; // Z
153+ gimbal_status_pub.msg .camera_orientation_in_body_frame_xyzw [3 ] = q[3 ]; // W
154+
155+ gimbal_status_pub.publish ();
156+ }
0 commit comments