From 43b23ec1adaf031021c5410f425af9b431c9169d Mon Sep 17 00:00:00 2001 From: FReenen Date: Sat, 10 Aug 2024 19:14:50 +0200 Subject: [PATCH] fix servo scaling --- index.html | 5 +++-- rx_esp32/src/commands.c | 4 ++-- rx_esp32/src/config.h | 4 ++-- rx_esp32/src/servos.c | 2 +- rx_esp32/src/servos.h | 2 +- rx_esp32/src/ws.c | 12 ------------ 6 files changed, 9 insertions(+), 20 deletions(-) diff --git a/index.html b/index.html index 66e31b9..f83b338 100644 --- a/index.html +++ b/index.html @@ -90,8 +90,9 @@ } function send(x,y,angle){ - x = Math.round((x + 200) * 81.92); - y = Math.round((y + 200) * 81.92); + factor = (2**16-1)/400 + x = Math.round((x + 200) * factor); + y = Math.round((y + 200) * factor); var data = clientId + ";d;" + x.toString() + "," + y.toString(); connection.send(data); } diff --git a/rx_esp32/src/commands.c b/rx_esp32/src/commands.c index 6ef7445..2461c8d 100644 --- a/rx_esp32/src/commands.c +++ b/rx_esp32/src/commands.c @@ -59,8 +59,8 @@ int cmd_contrl(char* line, void* cli) { readInt(arg, &ch_d[1]); - servo_set(0, (int16_t)ch_d[0]); - servo_set(1, (int16_t)ch_d[1]); + servo_set(0, (uint16_t)ch_d[0]); + servo_set(1, (uint16_t)ch_d[1]); snprintf(&msg[0], 40, "channel data: 0:%lu, 1:%lu\n", ch_d[0], ch_d[1]); CLI_stringOut((CLI_t*)cli, &msg[0]); } diff --git a/rx_esp32/src/config.h b/rx_esp32/src/config.h index 45127a7..38a4099 100644 --- a/rx_esp32/src/config.h +++ b/rx_esp32/src/config.h @@ -12,8 +12,8 @@ static uint8_t BoatId = 1; #define HISTORY // enable cli history -#define SERVOS_CH0 {LEDC_CHANNEL_0, 5}, -#define SERVOS_CH1 {LEDC_CHANNEL_1, 6} +#define SERVOS_CH0 {LEDC_CHANNEL_0, 7}, +#define SERVOS_CH1 {LEDC_CHANNEL_1, 21} #define SERVOS_CH2 #define SERVOS_CH3 #define SERVOS_CH4 diff --git a/rx_esp32/src/servos.c b/rx_esp32/src/servos.c index 8a23fbb..13f77b4 100644 --- a/rx_esp32/src/servos.c +++ b/rx_esp32/src/servos.c @@ -70,7 +70,7 @@ void servo_deinit(void) } } -void servo_set(uint8_t ch, int16_t pos) +void servo_set(uint8_t ch, uint16_t pos) { uint32_t duty = (uint32_t) ((double)pos * (double)SERVO_DUTY_DIFF/(double)INT16_MAX); duty += (SERVO_DUTY_MIN + SERVO_DUTY_DIFF/2); diff --git a/rx_esp32/src/servos.h b/rx_esp32/src/servos.h index 7cd458a..1069386 100644 --- a/rx_esp32/src/servos.h +++ b/rx_esp32/src/servos.h @@ -5,6 +5,6 @@ void servo_init(void); void servo_deinit(void); -void servo_set(uint8_t ch, int16_t pos); +void servo_set(uint8_t ch, uint16_t pos); #endif // SERVOS_H \ No newline at end of file diff --git a/rx_esp32/src/ws.c b/rx_esp32/src/ws.c index 5790d13..2f20905 100644 --- a/rx_esp32/src/ws.c +++ b/rx_esp32/src/ws.c @@ -121,18 +121,6 @@ ws_client_t ws_connect(char *url) const esp_websocket_client_config_t ws_conf = { .uri = url - // .disable_pingpong_discon = false, - // .ping_interval_sec = 2, - // .pingpong_timeout_sec = 1 - - // bool disable_auto_reconnect; /*!< Disable the automatic reconnect function when disconnected */ - // int buffer_size; /*!< Websocket buffer size */ - // bool keep_alive_enable; /*!< Enable keep-alive timeout */ - // int keep_alive_idle; /*!< Keep-alive idle time. Default is 5 (second) */ - // int keep_alive_interval; /*!< Keep-alive interval time. Default is 5 (second) */ - // int keep_alive_count; /*!< Keep-alive packet retry send count. Default is 3 counts */ - // int reconnect_timeout_ms; /*!< Reconnect after this value in miliseconds if disable_auto_reconnect is not enabled (defaults to 10s) */ - // int network_timeout_ms; /*!< Abort network operation if it is not completed after this value, in milliseconds (defaults to 10s) */ }; client->handle = esp_websocket_client_init(&ws_conf); esp_websocket_register_events(client->handle, WEBSOCKET_EVENT_ANY, ws_event_handler, (void *)client);