aboutsummaryrefslogtreecommitdiffstats
path: root/serial
diff options
context:
space:
mode:
Diffstat (limited to 'serial')
-rw-r--r--serial/CMakeLists.txt2
-rw-r--r--serial/serial.c31
-rw-r--r--serial/serial.h6
-rw-r--r--serial/wheel.c7
4 files changed, 39 insertions, 7 deletions
diff --git a/serial/CMakeLists.txt b/serial/CMakeLists.txt
index 5ded98c..c0bc05a 100644
--- a/serial/CMakeLists.txt
+++ b/serial/CMakeLists.txt
@@ -8,4 +8,4 @@ aux_source_directory(${CMAKE_SOURCE_DIR}/lcmtype DIR_SRCS)
8add_executable(serial ${DIR_SRCS}) 8add_executable(serial ${DIR_SRCS})
9 9
10# 添加链接库 10# 添加链接库
11target_link_libraries(serial lcm) \ No newline at end of file 11target_link_libraries(serial lcm pthread)
diff --git a/serial/serial.c b/serial/serial.c
index a2f253a..6163703 100644
--- a/serial/serial.c
+++ b/serial/serial.c
@@ -1,7 +1,12 @@
1#include "serial.h" 1#include "serial.h"
2#include <math.h>
2 3
3lcm_t *lcm; 4lcm_t *lcm;
4 5
6// TODO 屏蔽停止指令
7bool stopFlag = false;
8////////////////////////
9
5int curStatus = -1, curSpeed = 0; // 这里的速度指百分比速度 10int curStatus = -1, curSpeed = 0; // 这里的速度指百分比速度
6double curOmega = 0.0; 11double curOmega = 0.0;
7// 临界区数据 12// 临界区数据
@@ -72,6 +77,23 @@ void parseCmd(const lcm_recv_buf_t *rbuf, const char *channel,
72 curOmega = (double)-DEFAULT_SPEED * FULLSPEED / 100 / RADIUS; 77 curOmega = (double)-DEFAULT_SPEED * FULLSPEED / 100 / RADIUS;
73 curSpeed = 0; 78 curSpeed = 0;
74 break; 79 break;
80 // TODO 屏蔽停止指令
81 case 4:
82 wheelSend(0x00, 0x00, 0x00, 0x00);
83 curOmega = 0;
84 curSpeed = 0;
85 stopFlag = true;
86 printf("Stop for 2 seconds\n");
87 break;
88 // 取消屏蔽
89 case 5:
90 wheelSend(0x00, 0x00, 0x00, 0x00);
91 curOmega = 0;
92 curSpeed = 0;
93 stopFlag = false;
94 printf("Stop but can recieve cmd\n");
95 break;
96 ////////////////////////////////////
75 case 0: 97 case 0:
76 default: 98 default:
77 wheelSend(0x00, 0x00, 0x00, 0x00); 99 wheelSend(0x00, 0x00, 0x00, 0x00);
@@ -85,6 +107,11 @@ void parseCmd(const lcm_recv_buf_t *rbuf, const char *channel,
85 107
86void parsePath(const lcm_recv_buf_t *rbuf, const char *channel, 108void parsePath(const lcm_recv_buf_t *rbuf, const char *channel,
87 const path_t *msg, void *userdata) { 109 const path_t *msg, void *userdata) {
110 // TODO
111 if (stopFlag) {
112 return;
113 }
114 /////////////////
88 int16_t length = msg->length; 115 int16_t length = msg->length;
89 double v, w; 116 double v, w;
90 int8_t vWheels[2]; 117 int8_t vWheels[2];
@@ -127,7 +154,7 @@ void setCurPose(const lcm_recv_buf_t *rbuf, const char *channel,
127 pthread_mutex_unlock(&curPoseMutex); 154 pthread_mutex_unlock(&curPoseMutex);
128} 155}
129 156
130void sendCurPose() { 157void *sendCurPose(void *args) {
131 pose_t pose; 158 pose_t pose;
132 while (true) { 159 while (true) {
133 renewCurPose(); 160 renewCurPose();
@@ -152,4 +179,4 @@ void renewCurPose() {
152 curPose[2] += curOmega * dt; 179 curPose[2] += curOmega * dt;
153 lastTime = clock(); 180 lastTime = clock();
154 pthread_mutex_unlock(&curPoseMutex); 181 pthread_mutex_unlock(&curPoseMutex);
155} \ No newline at end of file 182}
diff --git a/serial/serial.h b/serial/serial.h
index 3563557..2fbf870 100644
--- a/serial/serial.h
+++ b/serial/serial.h
@@ -19,7 +19,7 @@
19// TODO: 两个待测数据 19// TODO: 两个待测数据
20#define RADIUS 0.13 // 两轮之间的距离的一半,米 20#define RADIUS 0.13 // 两轮之间的距离的一半,米
21#define FULLSPEED 0.60 // 轮子全速,m/s 21#define FULLSPEED 0.60 // 轮子全速,m/s
22#define fabs(x) ((x) > 0 ? (x) : -(x)) 22// #define fabs(x) ((x) > 0 ? (x) : -(x))
23typedef unsigned char byte; 23typedef unsigned char byte;
24 24
25int identify_device(const char *port); 25int identify_device(const char *port);
@@ -34,6 +34,6 @@ void parsePath(const lcm_recv_buf_t *rbuf, const char *channel,
34void setCurPose(const lcm_recv_buf_t *rbuf, const char *channel, 34void setCurPose(const lcm_recv_buf_t *rbuf, const char *channel,
35 const pose_t *msg, void *userdata); 35 const pose_t *msg, void *userdata);
36void renewCurPose(); 36void renewCurPose();
37void sendCurPose(); 37void *sendCurPose(void *args);
38 38
39#endif \ No newline at end of file 39#endif
diff --git a/serial/wheel.c b/serial/wheel.c
index 8155734..c470234 100644
--- a/serial/wheel.c
+++ b/serial/wheel.c
@@ -5,7 +5,8 @@ char *portname; // 串口设备名
5struct termios tty; 5struct termios tty;
6 6
7bool whellInit() { 7bool whellInit() {
8 portname = findUSBDev("wheel"); 8 // portname = findUSBDev("wheel");
9 portname = "/dev/ttyUSB1"; // "/dev/ttyUSB1
9 if (portname == NULL) { 10 if (portname == NULL) {
10 fprintf(stderr, "Error: Failed to find wheel serial port\n"); 11 fprintf(stderr, "Error: Failed to find wheel serial port\n");
11 return false; 12 return false;
@@ -55,6 +56,10 @@ bool wheelSend(byte a, byte a_v, byte b, byte b_v) {
55 unsigned char data[7] = {0x53, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00}; 56 unsigned char data[7] = {0x53, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00};
56 byte checksum = 0; 57 byte checksum = 0;
57 data[2] = a; 58 data[2] = a;
59 // TODO: 速度转换
60 int temp = ((int)a_v + 2);
61 a_v = (byte)temp;
62 ////////////////////////
58 data[3] = a_v; 63 data[3] = a_v;
59 data[4] = b; 64 data[4] = b;
60 data[5] = b_v; 65 data[5] = b_v;