@@ -45,14 +45,11 @@ extern const AP_HAL::HAL &hal;
4545#define AP_PERIPH_ACTUATOR_TELEM_CURR_MAX_DEFAULT 2 .5f
4646#endif
4747
48+ #if AP_SERVO_TELEM_ENABLED == 0
49+ #error "AP_PERIPH_ACTUATOR_TELEM_ENABLED requires AP_SERVO_TELEM_ENABLED"
50+ #endif
51+
4852const AP_Param::GroupInfo ActuatorTelem::var_info[] = {
49- // @Param: _TELEM_RATE
50- // @DisplayName: Actuator Telemetry rate
51- // @Description: Actuator Telemetry update rate in Hz. Set to 0 to disable.
52- // @Units: Hz
53- // @Range: 0 100
54- // @User: Standard
55- AP_GROUPINFO (" _TELEM_RATE" , 1 , ActuatorTelem, rate, AP_PERIPH_ACTUATOR_TELEM_RATE_DEFAULT),
5653
5754 // @Param: _NUM_CHANS
5855 // @DisplayName: Number of actuator channels
@@ -129,71 +126,51 @@ void ActuatorTelem::send_telemetry(uint8_t channel_index, uint8_t actuator_id)
129126 return ;
130127 }
131128 // Read current from analog input
132- float current_amp = 0 ;
133- float adc_voltage = source->voltage_average ();
134- current_amp = (adc_voltage - curr_amp_offset) * curr_amp_per_volt;
135-
136- uavcan_equipment_actuator_Status pkt {};
137-
138- pkt.actuator_id = actuator_id;
139- pkt.position = nanf (" " ); // Not available
140- pkt.force = nanf (" " ); // Not available
141- pkt.speed = nanf (" " ); // Not available
129+ const float adc_voltage = source->voltage_average ();
130+ const float current_amp = (adc_voltage - curr_amp_offset) * curr_amp_per_volt;
142131
143132 // Calculate power rating percentage from current
144133 const float max_current = curr_max.get ();
145- if (max_current > 0 && current_amp > = 0 ) {
146- pkt. power_rating_pct = constrain_int16 (current_amp / max_current * 100 . 0f , 0 , 100 );
147- } else {
148- pkt. power_rating_pct = UAVCAN_EQUIPMENT_ACTUATOR_STATUS_POWER_RATING_PCT_UNKNOWN ;
134+ uint8_t duty_cycle = 0 ;
135+ const bool have_duty_cycle = (max_current > 0 ) && (current_amp >= 0 );
136+ if (have_duty_cycle) {
137+ duty_cycle = constrain_float (current_amp / max_current * 100 . 0f , 0 , 100 ) ;
149138 }
150139
151- // encode and broadcast
152- uint8_t buffer[UAVCAN_EQUIPMENT_ACTUATOR_STATUS_MAX_SIZE];
153- uint16_t total_size = uavcan_equipment_actuator_Status_encode (&pkt, buffer, !periph.canfdout ());
140+ const AP_Servo_Telem::TelemetryData telem_data {
141+ .current = current_amp,
142+ .duty_cycle = duty_cycle,
143+ .present_types = AP_Servo_Telem::TelemetryData::Types::CURRENT |
144+ have_duty_cycle ? AP_Servo_Telem::TelemetryData::Types::DUTY_CYCLE : 0
145+ };
146+
147+ periph.servo_telem .lib .update_telem_data (channel_index, telem_data);
154148
155- periph.canard_broadcast (UAVCAN_EQUIPMENT_ACTUATOR_STATUS_SIGNATURE,
156- UAVCAN_EQUIPMENT_ACTUATOR_STATUS_ID,
157- CANARD_TRANSFER_PRIORITY_LOW,
158- &buffer[0 ],
159- total_size);
160149}
161150
162151void ActuatorTelem::update ()
163152{
164- // Check global telemetry rate
165- const float telem_rate = rate.get ();
166- if (telem_rate <= 0 ) {
167- return ; // telemetry disabled
168- }
169-
170- const uint32_t now = AP_HAL::millis ();
171- if (now - last_telem_update_ms < 1000 .0f / telem_rate) {
153+ const int8_t num_chans_val = num_chans.get ();
154+ if (num_chans_val <= 0 ) {
172155 return ;
173156 }
174- last_telem_update_ms = now;
175157
176- #if HAL_PWM_COUNT > 0
177- const int8_t num_chans_val = num_chans.get ();
178- if (num_chans_val > 0 ) {
179- for (uint8_t i = 0 ; i < MIN (HAL_PWM_COUNT, num_chans_val); i++) {
180- const auto *srv_channel = periph.servo_channels .srv_channel (i);
181- if (srv_channel == nullptr ) {
182- continue ;
183- }
158+ for (uint8_t i = 0 ; i < MIN (HAL_PWM_COUNT, num_chans_val); i++) {
159+ const auto *srv_channel = periph.servo_channels .srv_channel (i);
160+ if (srv_channel == nullptr ) {
161+ continue ;
162+ }
184163
185- const SRV_Channel::Function function = srv_channel->get_function ();
186- // Only send for configured actuator functions
187- if (function < SRV_Channel::k_rcin1 || function > SRV_Channel::k_rcin16) {
188- continue ;
189- }
164+ const SRV_Channel::Function function = srv_channel->get_function ();
165+ // Only send for configured actuator functions
166+ if (function < SRV_Channel::k_rcin1 || function > SRV_Channel::k_rcin16) {
167+ continue ;
168+ }
190169
191- const uint8_t actuator_id = function - SRV_Channel::k_rcin1 + 1 ;
170+ const uint8_t actuator_id = function - SRV_Channel::k_rcin1 + 1 ;
192171
193- send_telemetry (i, actuator_id);
194- }
172+ send_telemetry (i, actuator_id);
195173 }
196- #endif
197174}
198175
199176#endif // AP_PERIPH_ACTUATOR_TELEM_ENABLED
0 commit comments