From 7769abf8a4d585d13f337c108321ba28ee206418 Mon Sep 17 00:00:00 2001 From: Luca Bascetta Date: Fri, 5 Apr 2024 16:37:56 +0200 Subject: [PATCH] Cast from uint to int added to motor currents --- src/protocol_v1/agilex_msg_parser_v1.c | 5 ++--- src/protocol_v2/agilex_msg_parser_v2.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/protocol_v1/agilex_msg_parser_v1.c b/src/protocol_v1/agilex_msg_parser_v1.c index c5fed8da..bcf59561 100644 --- a/src/protocol_v1/agilex_msg_parser_v1.c +++ b/src/protocol_v1/agilex_msg_parser_v1.c @@ -78,9 +78,8 @@ bool DecodeCanFrameV1(const struct can_frame *rx_frame, AgxMessage *msg) { msg->type = AgxMsgActuatorStateV1; msg->body.v1_actuator_state_msg.motor_id = rx_frame->can_id - CAN_MSG_ACTUATOR1_STATE_ID; - msg->body.v1_actuator_state_msg.current = - ((((uint16_t)rx_frame->data[0]) << 8) | (uint16_t)rx_frame->data[1]) / - 10.0f; + msg->body.v1_actuator_state_msg.current = (int16_t)(( + ((uint16_t)rx_frame->data[0]) << 8) | (uint16_t)rx_frame->data[1]) * 0.1; msg->body.v1_actuator_state_msg.rpm = (int16_t)(( (((uint16_t)rx_frame->data[2]) << 8) | (uint16_t)rx_frame->data[3])); msg->body.v1_actuator_state_msg.driver_temp = rx_frame->data[4]; diff --git a/src/protocol_v2/agilex_msg_parser_v2.c b/src/protocol_v2/agilex_msg_parser_v2.c index a9ae451d..13ec1654 100644 --- a/src/protocol_v2/agilex_msg_parser_v2.c +++ b/src/protocol_v2/agilex_msg_parser_v2.c @@ -158,9 +158,8 @@ bool DecodeCanFrameV2(const struct can_frame *rx_frame, AgxMessage *msg) { (int16_t)((uint16_t)(frame->rpm.low_byte) | (uint16_t)(frame->rpm.high_byte) << 8); msg->body.actuator_hs_state_msg.current = - ((uint16_t)(frame->current.low_byte) | - (uint16_t)(frame->current.high_byte) << 8) * - 0.1; + (int16_t)((uint16_t)(frame->current.low_byte) | + (uint16_t)(frame->current.high_byte) << 8) * 0.1; msg->body.actuator_hs_state_msg.pulse_count = (int32_t)((uint32_t)(frame->pulse_count.lsb) | (uint32_t)(frame->pulse_count.low_byte) << 8 |