diff options
Diffstat (limited to 'serial/serial.c')
-rw-r--r-- | serial/serial.c | 31 |
1 files changed, 29 insertions, 2 deletions
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 | ||
3 | lcm_t *lcm; | 4 | lcm_t *lcm; |
4 | 5 | ||
6 | // TODO 屏蔽停止指令 | ||
7 | bool stopFlag = false; | ||
8 | //////////////////////// | ||
9 | |||
5 | int curStatus = -1, curSpeed = 0; // 这里的速度指百分比速度 | 10 | int curStatus = -1, curSpeed = 0; // 这里的速度指百分比速度 |
6 | double curOmega = 0.0; | 11 | double 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 | ||
86 | void parsePath(const lcm_recv_buf_t *rbuf, const char *channel, | 108 | void 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 | ||
130 | void sendCurPose() { | 157 | void *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 | } |