Hi,
I would like to propose a CAN command that would return the latest current reading of the motor. I'm okay creating the PR myself if it's accepted.
I'm using two VESCs to control two brushed motors over CAN. I'm doing the speed control myself and sending the PWM duty cycle commands every millisecond, and to get a complete view, also read the currents.
I've already implemented this change in my local tree for a while and have used it. It works, but with each vesc fw release I need to change the command id of the "get-current" command based on how the enum grows. Having it part of the standard set would simplify it for myself, and maybe it would be useful to others as well.
I'll paste the diff I have for v7.0.0 as a reference for what I want and to discuss the idea, whereas any code review can be done in the eventual PR.
Thanks!
diff --git a/comm/comm_can.c b/comm/comm_can.c
index 81811e5e..50a2b70c 100644
--- a/comm/comm_can.c
+++ b/comm/comm_can.c
@@ -2255,6 +2255,16 @@ static void decode_msg(uint32_t eid, uint8_t *data8, int len, bool is_replaced)
}
} break;
+ case CAN_PACKET_GET_CURRENT:
+ {
+ int32_t send_index = 0;
+ uint8_t buffer[2];
+ buffer_append_int16(buffer, (int16_t)(mc_interface_get_tot_current_filtered() * 100.0), &send_index);
+ comm_can_transmit_eid(app_get_configuration()->controller_id |
+ ((uint32_t)CAN_PACKET_GET_CURRENT << 8), buffer, send_index);
+ }
+ break;
+
default:
break;
}
diff --git a/datatypes.h b/datatypes.h
index c7e9b4bd..fa287057 100644
--- a/datatypes.h
+++ b/datatypes.h
@@ -1213,6 +1213,7 @@ typedef enum {
CAN_PACKET_BMS_STATUS_3 = 66,
CAN_PACKET_BMS_STATUS_4 = 67,
CAN_PACKET_BMS_STATUS_5 = 68,
+ CAN_PACKET_GET_CURRENT = 128,
CAN_PACKET_MAKE_ENUM_32_BITS = 0xFFFFFFFF,
} CAN_PACKET_ID;

