@@ -171,6 +171,50 @@ const AP_Param::GroupInfo SRV_Channel::var_info[] = {
171171 // @RebootRequired: True
172172 AP_GROUPINFO (" FUNCTION" , 5 , SRV_Channel, function, 0 ),
173173
174+ #if AP_PERIPH_ACTUATOR_TELEM_ENABLED
175+ // @Param: TELEM_RATE
176+ // @DisplayName: Actuator Telemetry rate
177+ // @Description: Actuator Telemetry update rate in Hz for this servo channel.
178+ // @Units: Hz
179+ // @Range: 1 100
180+ // @User: Standard
181+ AP_GROUPINFO (" TELEM_RATE" , 6 , SRV_Channel, _telem_rate, AP_PERIPH_ACTUATOR_TELEM_RATE_DEFAULT),
182+
183+ // @Param: CURR_PIN
184+ // @DisplayName: Current sensing pin
185+ // @Description: Analog input pin number for current sensing on this servo channel. Set to -1 to disable current sensing.
186+ // @Values: -1:Disabled
187+ // @Range: -1 15
188+ // @User: Standard
189+ // @RebootRequired: True
190+ AP_GROUPINFO (" CURR_PIN" , 7 , SRV_Channel, _curr_pin, -1 ),
191+
192+ // @Param: AMP_OFFSET
193+ // @DisplayName: Current sensor offset
194+ // @Description: Voltage offset at zero current on the current sensor for this servo channel. Used to calibrate analog current sensors.
195+ // @Units: V
196+ // @Range: -10 10
197+ // @User: Standard
198+ AP_GROUPINFO (" AMP_OFFSET" , 8 , SRV_Channel, _curr_amp_offset, 0 ),
199+
200+ // @Param: AMP_PERVLT
201+ // @DisplayName: Amps per volt
202+ // @Description: Number of amps that a 1V reading on the current sensor corresponds to for this servo channel. This is the current sensor scale factor.
203+ // @Units: A/V
204+ // @Range: 0 100
205+ // @User: Standard
206+ AP_GROUPINFO (" AMP_PERVLT" , 9 , SRV_Channel, _curr_amp_per_volt, 0 ),
207+
208+
209+ // @Param: CURR_MAX
210+ // @DisplayName: Maximum current
211+ // @Description: Maximum expected current draw for this servo channel in amps. Used for scaling and safety limits.
212+ // @Units: A
213+ // @Range: 0 100
214+ // @User: Standard
215+ AP_GROUPINFO (" CURR_MAX" , 10 , SRV_Channel, _curr_max, 0 ),
216+ #endif
217+
174218 AP_GROUPEND
175219};
176220
@@ -399,3 +443,33 @@ int8_t SRV_Channel::get_motor_num(void) const
399443 }
400444 return -1 ;
401445}
446+
447+ #if AP_PERIPH_ACTUATOR_TELEM_ENABLED
448+ // return the current in amps for this channel
449+ float SRV_Channel::get_current_ampere (void ) const
450+ {
451+ // Check if ADC channel is configured
452+ if (_curr_pin > 0 && _curr_pin_analog_source == nullptr ) {
453+ _curr_pin_analog_source = hal.analogin ->channel (_curr_pin);
454+ if (_curr_pin_analog_source == nullptr ) {
455+ return 0 .0f ;
456+ }
457+ if (!_curr_pin_analog_source->set_pin (_curr_pin)) {
458+ return 0 .0f ;
459+ }
460+ } else if (_curr_pin <= 0 || _curr_pin_analog_source == nullptr ) {
461+ return 0 .0f ;
462+ }
463+
464+ float adc_voltage = _curr_pin_analog_source->voltage_average ();
465+ float current = (adc_voltage - _curr_amp_offset) * _curr_amp_per_volt;
466+
467+ return current;
468+ }
469+
470+ // return preset maximum current in amps for this channel
471+ float SRV_Channel::get_current_max_ampere (void ) const
472+ {
473+ return _curr_max;
474+ }
475+ #endif
0 commit comments