From 101ada7ae42f9845afeff42b970eee2f56d92a51 Mon Sep 17 00:00:00 2001 From: zwsd Date: Wed, 3 Aug 2022 15:03:56 +0800 Subject: [PATCH] update --- main/main.c | 11 +++++++---- main/motor_drive.c | 39 ++------------------------------------- 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/main/main.c b/main/main.c index 142c912..2113f76 100644 --- a/main/main.c +++ b/main/main.c @@ -19,6 +19,7 @@ #define ble_uart_rx_size 128 static uint8_t bluetooth_tx_buffer[ble_uart_tx_size] = {0}; static uint8_t bluetooth_rx_buffer[ble_uart_rx_size] = {0}; + bleuart_t ble_uart_init_struct = { .txbuf = bluetooth_tx_buffer, .txbufsize = sizeof(bluetooth_tx_buffer), @@ -32,7 +33,7 @@ bleuart_t ble_uart_init_struct = { motor_t ble_uart_motor_structer = {.uartNum = UART_NUM_1}; void process_setPosition(cJSON *rxjson) { - // { "order": "setPosition", "index": 0, "speedLevel": 1, "position": 120.3, "direction": 0 } + // { "order": "setPosition", "ble_uart_index": 0, "speedLevel": 1, "position": 120.3, "direction": 0 } int index = 0; int speedLevel = 0; float position = 0; @@ -50,7 +51,7 @@ void process_setPosition(cJSON *rxjson) { if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "direction"))) { direction = cJSON_GetNumberValue(cJSON_GetObjectItem(rxjson, "direction")); } - motor_run_to_postion(1, position, index); + motor_run_to_postion(1, position, 1); } void processrxjson(cJSON *rxjson) { @@ -62,7 +63,9 @@ void processrxjson(cJSON *rxjson) { if (strcmp(order, "setPosition") == 0) { process_setPosition(rxjson); + } else if (strcmp(order, "getStatus") == 0) { + } } @@ -85,8 +88,8 @@ void motor_on_event(motor_event_t event) { uint8_t buffer[128] = {0}; //组包 //上报 - //{ "order": "deviceStatusReport", "index": 0, "deviceState": "running", "position":13.9, "deviceException": 0, "deviceExceptionInfo": "", } - sprintf((char *)buffer, "{ \"order\": \"receipt\", \"code\": 0, \"info\": \"success\", \"index\": %d }", 0); + //{ "order": "deviceStatusReport", "ble_uart_index": 0, "deviceState": "running", "position":13.9, "deviceException": 0, "deviceExceptionInfo": "", } + sprintf((char *)buffer, "{ \"order\": \"receipt\", \"code\": 0, \"info\": \"success\", \"index\": %d }", 1); bleuart_notify_send(buffer,sizeof(buffer)); } } diff --git a/main/motor_drive.c b/main/motor_drive.c index e5200ae..1680e7f 100644 --- a/main/motor_drive.c +++ b/main/motor_drive.c @@ -18,7 +18,6 @@ static motor_t *motor_init_structer; static motor_on_event_t s_onevent; -static bool notify_send_flag = false; static double motor_position; /** @@ -178,7 +177,6 @@ void motor_run_to_postion(int rotation_direction, double position, int speed_lev return; } - notify_send_flag = true; motor_position = position; // Parse receive @@ -305,42 +303,9 @@ static uint8_t motor_drive_set_packages_ctr(double position, int direction) { * */ void motor_module_schedule() { - static uint32_t time = 0; - //读取角度是否到达想要角度,到达上报(每隔500ms读取一次) - if ((notify_send_flag == true) && (port_haspassedms(time) > 500)) { - double now_position_degree = motor_get_position_degree(); - double maximum = 0.0; - double minimum = 0.0; - - if (motor_position == 0){ - motor_position = 360; - } - - if ((motor_position + angular_error) > 360.0) { - maximum = (motor_position + angular_error) - 360.0; - } else { - maximum = motor_position + angular_error; - } + // s_onevent(kRunToPosition); //组包,主动上报 - if ((motor_position - angular_error) < 0.0) { - minimum = (motor_position - angular_error) + 360.0; - } else { - minimum = motor_position - angular_error; - } - - if (maximum < minimum) { - maximum = maximum + 360; - } - - if ((now_position_degree >= minimum) && (now_position_degree <= maximum)) { //读取角度是否到达 - s_onevent(kRunToPosition); //组包,主动上报 - notify_send_flag = false; - } - - // ESP_LOGI("=======", "now:%lf,run to:%lf,minimum = %lf,maximum = %lf", now_position_degree, motor_position, minimum, maximum); - - time = port_get_ticket(); - } + // time = port_get_ticket(); return; } \ No newline at end of file