Browse Source

成功下发指令,舵机可以转动

master
tianjialong 2 years ago
parent
commit
2f259fdc1a
  1. BIN
      app/a.exe
  2. 5
      app/main.c
  3. 34
      app/steering_gear.c
  4. 3
      app/steering_gear.h

BIN
app/a.exe

5
app/main.c

@ -9,6 +9,7 @@ PORT serial_port;
int serial_com_id;
int main(int argc, char *argv[]) {
int i = 0;
/* 参数判断 */
if (argc != 2) {
printf("please input com id\n");
@ -27,7 +28,9 @@ int main(int argc, char *argv[]) {
serial_port = serial_init(serial_com_id, 115200, 8, 1, 0);
while (1) {
Serial_SendData(serial_port, "hello finny", 12);
steering_gear_set_position(serial_port, (i % 5));
i = i + 1;
printf("i:%d\n", i);
Sleep(1000);
}

34
app/steering_gear.c

@ -0,0 +1,34 @@
#include "steering_gear.h"
#include <stdio.h>
void steering_gear_set_position(PORT serial_com, int switch_position_mode) {
char buf_position_0[] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x2a, 0x00, 0x00, 0x00, 0x00, 0xca};
char buf_position_1024[] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x2a, 0x04, 0x00, 0x00, 0x00, 0xc6};
char buf_position_2048[] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x2a, 0x08, 0x00, 0x00, 0x00, 0xc2};
char buf_position_3071[] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x2a, 0x0b, 0xff, 0x00, 0x00, 0xc0};
char buf_position_4095[] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x2a, 0x0f, 0xff, 0x00, 0x00, 0xbc};
printf("switch:%d\n", switch_position_mode);
switch (switch_position_mode) {
case 0:
Serial_SendData(serial_com, buf_position_0, sizeof(buf_position_0));
break;
case 1:
Serial_SendData(serial_com, buf_position_1024, sizeof(buf_position_1024));
break;
case 2:
Serial_SendData(serial_com, buf_position_2048, sizeof(buf_position_2048));
break;
case 3:
Serial_SendData(serial_com, buf_position_3071, sizeof(buf_position_3071));
break;
case 4:
Serial_SendData(serial_com, buf_position_4095, sizeof(buf_position_4095));
break;
default:
break;
}
}

3
app/steering_gear.h

@ -0,0 +1,3 @@
#include "serial.h"
void steering_gear_set_position(PORT serial_com, int switch_position_mode);
Loading…
Cancel
Save