Add get_adc_voltage()

This commit is contained in:
Malaphor
2022-08-18 20:18:04 -07:00
parent f04c36538a
commit 73b15f2fe6
2 changed files with 25 additions and 1 deletions
+21
View File
@@ -151,6 +151,9 @@ void CANSimple::do_command(Axis& axis, const can_Message_t& msg) {
case MSG_SET_VEL_GAINS:
set_vel_gains_callback(axis, msg);
break;
case MSG_GET_ADC_VOLTAGE:
get_adc_voltage_callback(axis, msg);
break;
default:
break;
}
@@ -345,6 +348,24 @@ bool CANSimple::get_vbus_voltage_callback(const Axis& axis) {
return canbus_->send_message(txmsg);
}
bool CANSimple::get_adc_voltage_callback(const Axis& axis, const can_Message_t& msg) {
can_Message_t txmsg;
txmsg.id = axis.config_.can.node_id << NUM_CMD_ID_BITS;
txmsg.id += MSG_GET_ADC_VOLTAGE;
txmsg.isExt = axis.config_.can.is_extended;
txmsg.len = 8;
auto gpio_num = can_getSignal<uint8_t>(msg, 0, 8, true);
if (gpio_num < GPIO_COUNT) {
auto voltage = get_adc_voltage(get_gpio(gpio_num));
can_setSignal<float>(txmsg, voltage, 0, 32, true);
return canbus_->send_message(txmsg);
} else {
return false;
}
}
void CANSimple::clear_errors_callback(Axis& axis, const can_Message_t& msg) {
odrv.clear_errors(); // TODO: might want to clear axis errors only
}
+4 -1
View File
@@ -35,6 +35,7 @@ class CANSimple {
MSG_SET_LINEAR_COUNT,
MSG_SET_POS_GAIN,
MSG_SET_VEL_GAINS,
MSG_GET_ADC_VOLTAGE,
MSG_CO_HEARTBEAT_CMD = 0x700, // CANOpen NMT Heartbeat SEND
};
@@ -62,6 +63,8 @@ class CANSimple {
bool get_iq_callback(const Axis& axis);
bool get_sensorless_estimates_callback(const Axis& axis);
bool get_vbus_voltage_callback(const Axis& axis);
// msg.rtr bit must NOT be set
bool get_adc_voltage_callback(const Axis& axis, const can_Message_t& msg);
// Set functions
static void set_axis_nodeid_callback(Axis& axis, const can_Message_t& msg);
@@ -106,4 +109,4 @@ class CANSimple {
bool extended_node_ids_[AXIS_COUNT];
};
#endif
#endif