Added handbrake function to the simple CAN interface

This commit is contained in:
Benjamin Vedder 2018-03-02 11:48:49 +01:00
parent bf27cb673e
commit f7d0897c73
25 changed files with 74 additions and 6 deletions

View File

@ -1,3 +1,6 @@
=== FW 3.36 ===
* Added handbrake current commands to the simple CAN interface.
=== FW 3.35 ===
* Added option to disable nRF transmission (option in Transmit Power parameter).
* Fixed servo output driver for all hardwares and removed software servo driver.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -171,31 +171,31 @@ static THD_FUNCTION(cancom_process_thread, arg) {
switch (cmd) {
case CAN_PACKET_SET_DUTY:
ind = 0;
mc_interface_set_duty((float)buffer_get_int32(rxmsg.data8, &ind) / 100000.0);
mc_interface_set_duty(buffer_get_float32(rxmsg.data8, 1e5, &ind));
timeout_reset();
break;
case CAN_PACKET_SET_CURRENT:
ind = 0;
mc_interface_set_current((float)buffer_get_int32(rxmsg.data8, &ind) / 1000.0);
mc_interface_set_current(buffer_get_float32(rxmsg.data8, 1e3, &ind));
timeout_reset();
break;
case CAN_PACKET_SET_CURRENT_BRAKE:
ind = 0;
mc_interface_set_brake_current((float)buffer_get_int32(rxmsg.data8, &ind) / 1000.0);
mc_interface_set_brake_current(buffer_get_float32(rxmsg.data8, 1e3, &ind));
timeout_reset();
break;
case CAN_PACKET_SET_RPM:
ind = 0;
mc_interface_set_pid_speed((float)buffer_get_int32(rxmsg.data8, &ind));
mc_interface_set_pid_speed(buffer_get_float32(rxmsg.data8, 1e0, &ind));
timeout_reset();
break;
case CAN_PACKET_SET_POS:
ind = 0;
mc_interface_set_pid_pos((float)buffer_get_int32(rxmsg.data8, &ind) / 1000000.0);
mc_interface_set_pid_pos(buffer_get_float32(rxmsg.data8, 1e6, &ind));
timeout_reset();
break;
@ -263,6 +263,18 @@ static THD_FUNCTION(cancom_process_thread, arg) {
timeout_reset();
break;
case CAN_PACKET_SET_CURRENT_HANDBRAKE:
ind = 0;
mc_interface_set_handbrake(buffer_get_float32(rxmsg.data8, 1e3, &ind));
timeout_reset();
break;
case CAN_PACKET_SET_CURRENT_HANDBRAKE_REL:
ind = 0;
mc_interface_set_handbrake_rel(buffer_get_float32(rxmsg.data8, 1e5, &ind));
timeout_reset();
break;
default:
break;
}
@ -539,6 +551,40 @@ void comm_can_set_current_brake_rel(uint8_t controller_id, float current_rel) {
((uint32_t)CAN_PACKET_SET_CURRENT_BRAKE_REL << 8), buffer, send_index);
}
/**
* Set handbrake current.
*
* @param controller_id
* The ID of the VESC to set the handbrake current on.
*
* @param current_rel
* The handbrake current value
*/
void comm_can_set_handbrake(uint8_t controller_id, float current) {
int32_t send_index = 0;
uint8_t buffer[4];
buffer_append_float32(buffer, current, 1e3, &send_index);
comm_can_transmit_eid(controller_id |
((uint32_t)CAN_PACKET_SET_CURRENT_HANDBRAKE << 8), buffer, send_index);
}
/**
* Set handbrake current relative to the minimum current limit.
*
* @param controller_id
* The ID of the VESC to set the handbrake current on.
*
* @param current_rel
* The relative handbrake current value, range [0.0 1.0]
*/
void comm_can_set_handbrake_rel(uint8_t controller_id, float current_rel) {
int32_t send_index = 0;
uint8_t buffer[4];
buffer_append_float32(buffer, current_rel, 1e5, &send_index);
comm_can_transmit_eid(controller_id |
((uint32_t)CAN_PACKET_SET_CURRENT_HANDBRAKE_REL << 8), buffer, send_index);
}
/**
* Get status message by index.
*

View File

@ -498,7 +498,9 @@ typedef enum {
CAN_PACKET_PROCESS_SHORT_BUFFER,
CAN_PACKET_STATUS,
CAN_PACKET_SET_CURRENT_REL,
CAN_PACKET_SET_CURRENT_BRAKE_REL
CAN_PACKET_SET_CURRENT_BRAKE_REL,
CAN_PACKET_SET_CURRENT_HANDBRAKE,
CAN_PACKET_SET_CURRENT_HANDBRAKE_REL
} CAN_PACKET_ID;
// Logged fault data

View File

@ -466,6 +466,12 @@ void mc_interface_set_brake_current_rel(float val) {
mc_interface_set_brake_current(val * m_conf.lo_current_motor_max_now);
}
/**
* Set open loop current vector to brake motor.
*
* @param current
* The current value.
*/
void mc_interface_set_handbrake(float current) {
if (mc_interface_try_input()) {
return;
@ -487,6 +493,16 @@ void mc_interface_set_handbrake(float current) {
}
}
/**
* Set handbrake brake current relative to the minimum current limit.
*
* @param current
* The relative current value, range [0.0 1.0]
*/
void mc_interface_set_handbrake_rel(float val) {
mc_interface_set_handbrake(val * fabsf(m_conf.lo_current_motor_min_now));
}
void mc_interface_brake_now(void) {
mc_interface_set_duty(0.0);
}

View File

@ -43,6 +43,7 @@ void mc_interface_set_brake_current(float current);
void mc_interface_set_current_rel(float val);
void mc_interface_set_brake_current_rel(float val);
void mc_interface_set_handbrake(float current);
void mc_interface_set_handbrake_rel(float val);
void mc_interface_brake_now(void);
void mc_interface_release_motor(void);
float mc_interface_get_duty_cycle_set(void);