From e24b555dea9546a830c76ddaa63f5f1544db6080 Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Sun, 10 Aug 2014 22:48:31 +0200 Subject: [PATCH] Some fixes --- applications/app_uartcomm.c | 2 +- buffer.c | 12 ++++++------ mcpwm.c | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/applications/app_uartcomm.c b/applications/app_uartcomm.c index 9d65fbfb..0c27294c 100644 --- a/applications/app_uartcomm.c +++ b/applications/app_uartcomm.c @@ -136,7 +136,7 @@ static void process_packet(unsigned char *buffer, unsigned char len) { switch (buffer[0]) { case UARTCOMM_CMD_SET_DUTY: - mcpwm_set_duty((float)buffer_get_int16(buffer, &ind) / 1000.0); + mcpwm_set_duty((float)buffer_get_int32(buffer, &ind) / 100000.0); last_uart_update_time = chTimeNow(); break; diff --git a/buffer.c b/buffer.c index e69069fb..436967ed 100644 --- a/buffer.c +++ b/buffer.c @@ -64,18 +64,18 @@ uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) { int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) { int32_t res = ((uint32_t) buffer[*index]) << 24 | - ((uint32_t) buffer[*index]) << 16 | - ((uint32_t) buffer[*index]) << 8 | - ((uint32_t) buffer[*index + 1]); + ((uint32_t) buffer[*index + 1]) << 16 | + ((uint32_t) buffer[*index + 2]) << 8 | + ((uint32_t) buffer[*index + 3]); *index += 4; return res; } uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) { uint32_t res = ((uint32_t) buffer[*index]) << 24 | - ((uint32_t) buffer[*index]) << 16 | - ((uint32_t) buffer[*index]) << 8 | - ((uint32_t) buffer[*index + 1]); + ((uint32_t) buffer[*index + 1]) << 16 | + ((uint32_t) buffer[*index + 2]) << 8 | + ((uint32_t) buffer[*index + 3]); *index += 4; return res; } diff --git a/mcpwm.c b/mcpwm.c index 8dc222a8..cc380f78 100644 --- a/mcpwm.c +++ b/mcpwm.c @@ -588,8 +588,7 @@ void mcpwm_set_brake_current(float current) { if (state != MC_STATE_RUNNING) { // In case the motor is already spinning, set the state to running // so that it can be ramped down before the full brake is applied. - // TODO: The number 500 is a hack... - if (fabsf(rpm_now) > 500) { + if (fabsf(rpm_now) > MCPWM_CURR_MIN_RPM_FBRAKE) { state = MC_STATE_RUNNING; } else { full_brake_ll(); @@ -853,7 +852,7 @@ static void set_duty_cycle_hl(float dutyCycle) { } else { // In case the motor is already spinning, set the state to running // so that it can be ramped down before the full brake is applied. - if (fabsf(rpm_now) > MCPWM_MIN_RPM) { + if (fabsf(rpm_now) > MCPWM_CURR_MIN_RPM_FBRAKE) { state = MC_STATE_RUNNING; } else { full_brake_ll();