Browse Source

update

master
zwsd 3 years ago
parent
commit
101ada7ae4
  1. 11
      main/main.c
  2. 39
      main/motor_drive.c

11
main/main.c

@ -19,6 +19,7 @@
#define ble_uart_rx_size 128 #define ble_uart_rx_size 128
static uint8_t bluetooth_tx_buffer[ble_uart_tx_size] = {0}; static uint8_t bluetooth_tx_buffer[ble_uart_tx_size] = {0};
static uint8_t bluetooth_rx_buffer[ble_uart_rx_size] = {0}; static uint8_t bluetooth_rx_buffer[ble_uart_rx_size] = {0};
bleuart_t ble_uart_init_struct = { bleuart_t ble_uart_init_struct = {
.txbuf = bluetooth_tx_buffer, .txbuf = bluetooth_tx_buffer,
.txbufsize = sizeof(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}; motor_t ble_uart_motor_structer = {.uartNum = UART_NUM_1};
void process_setPosition(cJSON *rxjson) { 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 index = 0;
int speedLevel = 0; int speedLevel = 0;
float position = 0; float position = 0;
@ -50,7 +51,7 @@ void process_setPosition(cJSON *rxjson) {
if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "direction"))) { if (cJSON_IsNumber(cJSON_GetObjectItem(rxjson, "direction"))) {
direction = cJSON_GetNumberValue(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) { void processrxjson(cJSON *rxjson) {
@ -62,7 +63,9 @@ void processrxjson(cJSON *rxjson) {
if (strcmp(order, "setPosition") == 0) { if (strcmp(order, "setPosition") == 0) {
process_setPosition(rxjson); process_setPosition(rxjson);
} else if (strcmp(order, "getStatus") == 0) { } else if (strcmp(order, "getStatus") == 0) {
} }
} }
@ -85,8 +88,8 @@ void motor_on_event(motor_event_t event) {
uint8_t buffer[128] = {0}; 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)); bleuart_notify_send(buffer,sizeof(buffer));
} }
} }

39
main/motor_drive.c

@ -18,7 +18,6 @@
static motor_t *motor_init_structer; static motor_t *motor_init_structer;
static motor_on_event_t s_onevent; static motor_on_event_t s_onevent;
static bool notify_send_flag = false;
static double motor_position; static double motor_position;
/** /**
@ -178,7 +177,6 @@ void motor_run_to_postion(int rotation_direction, double position, int speed_lev
return; return;
} }
notify_send_flag = true;
motor_position = position; motor_position = position;
// Parse receive // Parse receive
@ -305,42 +303,9 @@ static uint8_t motor_drive_set_packages_ctr(double position, int direction) {
* *
*/ */
void motor_module_schedule() { 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; return;
} }
Loading…
Cancel
Save