|
|
@ -132,7 +132,7 @@ uint8_t motor_drive_set_packages_ctr(double position, int direction) { |
|
|
|
buffer[9] = checksum; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Send cmd |
|
|
|
uart_flush(uart_num); |
|
|
|
uart_write_bytes(uart_num, buffer, 10); |
|
|
@ -269,70 +269,75 @@ double motor_drive_read_single_turn_angle() { |
|
|
|
return ((double)turn_angle_data / 100.0); |
|
|
|
} |
|
|
|
|
|
|
|
// void motor_drive_set_motor_to_angle(uint8_t rotation_direction, double position, uint8_t speed_level) { |
|
|
|
// int position_int = 0; |
|
|
|
// uint8_t position_remainder = 0; |
|
|
|
// uint8_t position_buffer_size = 6; //从第五位开始(低位) |
|
|
|
// uint8_t checksum = 0; |
|
|
|
// uint32_t limit_speed = 0; |
|
|
|
// uint8_t buffer[14] = {0x3E, 0XA6, MOTOR_ID, 0X08, 0XED, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00}; |
|
|
|
// char *notify_err = "set size error"; |
|
|
|
|
|
|
|
// if ((rotation_direction == 0X00) || (rotation_direction == 0X01)) { |
|
|
|
// buffer[5] = rotation_direction; |
|
|
|
// checksum += rotation_direction; |
|
|
|
// } |
|
|
|
|
|
|
|
// position_int = position * 100; |
|
|
|
// position_int = position_int % 36000; |
|
|
|
|
|
|
|
// if (position_int != 0) { |
|
|
|
// while ((position_int / 0XFF) > 0) { |
|
|
|
// position_remainder = position_int & 0XFF; |
|
|
|
// buffer[position_buffer_size] = position_remainder; |
|
|
|
// position_buffer_size += 1; |
|
|
|
// position_int = position_int >> 8; |
|
|
|
// checksum += position_remainder; |
|
|
|
// } |
|
|
|
// buffer[position_buffer_size] = position_int; |
|
|
|
// checksum += position_int; |
|
|
|
// } |
|
|
|
|
|
|
|
// if (speed_level <= 9) { |
|
|
|
// limit_speed = speed_level * 360; |
|
|
|
// position_buffer_size = 9; |
|
|
|
// } |
|
|
|
|
|
|
|
// while (limit_speed != 0) { |
|
|
|
// while ((limit_speed / 0XFF) > 0) { |
|
|
|
// position_remainder = limit_speed & 0XFF; |
|
|
|
// buffer[position_buffer_size] = position_remainder; |
|
|
|
// position_buffer_size += 1; |
|
|
|
// limit_speed = limit_speed >> 8; |
|
|
|
// checksum += position_remainder; |
|
|
|
// } |
|
|
|
// buffer[position_buffer_size] = limit_speed; |
|
|
|
// checksum += limit_speed; |
|
|
|
// } |
|
|
|
|
|
|
|
// checksum = checksum & 0XFF; |
|
|
|
// buffer[13] = checksum; |
|
|
|
|
|
|
|
// Send cmd |
|
|
|
// uart_flush(uart_num); |
|
|
|
// uart_write_bytes(uart_num, buffer, 14); |
|
|
|
|
|
|
|
// position_buffer_size = 0; |
|
|
|
// memset(buffer, 0, sizeof(uint8_t) * 14); |
|
|
|
|
|
|
|
// Wait uart receive,if time out return error and output log |
|
|
|
// position_buffer_size = uart_read_bytes(uart_num, buffer, 13, uart_read_time_ms / portTICK_RATE_MS); |
|
|
|
// if (position_buffer_size != 13 || buffer[0] != 0X3E) { |
|
|
|
// ESP_LOGW(MOTOR_DRIVE, "set motor size error ,buffer_size:%d,buffer[0] = 0X%x", position_buffer_size, buffer[0]); |
|
|
|
// bluetooth_active_notify((uint8_t *)notify_err, strlen(notify_err)); |
|
|
|
// } |
|
|
|
|
|
|
|
// Parse receive |
|
|
|
// motor_drive_buffer_cmd_parse(buffer); |
|
|
|
// return; |
|
|
|
// } |
|
|
|
void motor_drive_set_motor_to_angle(int rotation_direction, double position, int speed_level) { |
|
|
|
int position_int = 0; |
|
|
|
uint8_t position_remainder = 0; |
|
|
|
uint8_t position_buffer_size = 6; //从第五位开始(低位) |
|
|
|
uint8_t checksum = 0; |
|
|
|
uint32_t limit_speed = 0; |
|
|
|
uint8_t buffer[14] = {0x3E, 0XA6, MOTOR_ID, 0X08, 0XED, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00}; |
|
|
|
char *notify_err = "set size error"; |
|
|
|
|
|
|
|
if ((rotation_direction >= 0) && (rotation_direction < 2)) { |
|
|
|
buffer[5] = rotation_direction; |
|
|
|
checksum += rotation_direction; |
|
|
|
} |
|
|
|
|
|
|
|
position_int = position * 100; |
|
|
|
position_int = position_int % 36000; |
|
|
|
|
|
|
|
if (position_int != 0) { |
|
|
|
while ((position_int / 0X100) > 0) { |
|
|
|
position_remainder = position_int & 0XFF; |
|
|
|
buffer[position_buffer_size] = position_remainder; |
|
|
|
position_buffer_size += 1; |
|
|
|
position_int = position_int >> 8; |
|
|
|
checksum += position_remainder; |
|
|
|
} |
|
|
|
buffer[position_buffer_size] = position_int; |
|
|
|
checksum += position_int; |
|
|
|
} |
|
|
|
|
|
|
|
if (speed_level <= 9) { |
|
|
|
limit_speed = speed_level * 360; |
|
|
|
position_buffer_size = 9; |
|
|
|
} |
|
|
|
|
|
|
|
for (uint8_t i = 0; i < 14; i++) { |
|
|
|
/* code */ |
|
|
|
ESP_LOGI(MOTOR_DRIVE, "buffer[%d] = %d", i, buffer[i]); |
|
|
|
} |
|
|
|
|
|
|
|
if (limit_speed != 0) { |
|
|
|
while ((limit_speed / 0X100) > 0) { |
|
|
|
position_remainder = limit_speed & 0XFF; |
|
|
|
buffer[position_buffer_size] = position_remainder; |
|
|
|
position_buffer_size += 1; |
|
|
|
limit_speed = limit_speed >> 8; |
|
|
|
checksum += position_remainder; |
|
|
|
} |
|
|
|
buffer[position_buffer_size] = limit_speed; |
|
|
|
checksum += limit_speed; |
|
|
|
} |
|
|
|
|
|
|
|
checksum = checksum & 0XFF; |
|
|
|
buffer[13] = checksum; |
|
|
|
|
|
|
|
// Send cmd |
|
|
|
uart_flush(uart_num); |
|
|
|
uart_write_bytes(uart_num, buffer, 14); |
|
|
|
|
|
|
|
position_buffer_size = 0; |
|
|
|
memset(buffer, 0, sizeof(uint8_t) * 14); |
|
|
|
|
|
|
|
// Wait uart receive, if time out return error and output log |
|
|
|
position_buffer_size = uart_read_bytes(uart_num, buffer, 13, uart_read_time_ms / portTICK_RATE_MS); |
|
|
|
if (position_buffer_size != 13 || buffer[0] != 0X3E) { |
|
|
|
ESP_LOGW(MOTOR_DRIVE, "set motor size error ,buffer_size:%d,buffer[0] = 0X%x", position_buffer_size, buffer[0]); |
|
|
|
bluetooth_active_notify((uint8_t *)notify_err, strlen(notify_err)); |
|
|
|
} |
|
|
|
|
|
|
|
// Parse receive |
|
|
|
motor_drive_buffer_cmd_parse(buffer); |
|
|
|
return; |
|
|
|
} |