aboutsummaryrefslogtreecommitdiffstats
path: root/serial/serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'serial/serial.c')
-rw-r--r--serial/serial.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/serial/serial.c b/serial/serial.c
index 57b432c..61be0aa 100644
--- a/serial/serial.c
+++ b/serial/serial.c
@@ -3,7 +3,7 @@
3lcm_t *lcm; 3lcm_t *lcm;
4 4
5int curStatus = -1, curSpeed = 0; // 这里的速度指百分比速度 5int curStatus = -1, curSpeed = 0; // 这里的速度指百分比速度
6double curOmega; 6double curOmega = 0.0;
7// 临界区数据 7// 临界区数据
8pthread_mutex_t curPoseMutex; 8pthread_mutex_t curPoseMutex;
9clock_t lastTime; 9clock_t lastTime;
@@ -20,6 +20,7 @@ int main() {
20 } 20 }
21 21
22 // 订阅来自手机端的轮控消息 22 // 订阅来自手机端的轮控消息
23 lastTime = clock();
23 path_ctrl_t_subscribe(lcm, "wheel_ctrl", parseCmd, NULL); 24 path_ctrl_t_subscribe(lcm, "wheel_ctrl", parseCmd, NULL);
24 // 订阅来自算法模块的路径规划消息 25 // 订阅来自算法模块的路径规划消息
25 path_t_subscribe(lcm, "PATH", parsePath, NULL); 26 path_t_subscribe(lcm, "PATH", parsePath, NULL);
@@ -45,6 +46,8 @@ err:
45void parseCmd(const lcm_recv_buf_t *rbuf, const char *channel, 46void parseCmd(const lcm_recv_buf_t *rbuf, const char *channel,
46 const path_ctrl_t *msg, void *userdata) { 47 const path_ctrl_t *msg, void *userdata) {
47 byte status = msg->cmd, speed = msg->speed; 48 byte status = msg->cmd, speed = msg->speed;
49 // 手机端在转弯过程中只能设置状态,速度是默认的
50 // 所以对于转弯,只需要判断状态是否改变
48 if (curStatus == status && curSpeed == speed) { 51 if (curStatus == status && curSpeed == speed) {
49 return; 52 return;
50 } 53 }
@@ -124,12 +127,17 @@ void sendCurPose() {
124 while (true) { 127 while (true) {
125 renewCurPose(); 128 renewCurPose();
126 pthread_mutex_lock(&curPoseMutex); 129 pthread_mutex_lock(&curPoseMutex);
127 pose.pos[0] = curPose[0]; 130 // pose.pos[0] = curPose[0];
128 pose.pos[1] = curPose[1]; 131 // pose.pos[1] = curPose[1];
129 pose.pos[2] = curPose[2]; 132 // pose.pos[2] = curPose[2];
133 pose.pos[0] = 0.0;
134 pose.pos[1] = 0.0;
135 pose.pos[2] = 0.0;
130 pthread_mutex_unlock(&curPoseMutex); 136 pthread_mutex_unlock(&curPoseMutex);
131 pose_t_publish(lcm, "POSE", &pose); 137 pose_t_publish(lcm, "POSE", &pose);
132 usleep(16); 138 // printf("sent (%lf, %lf, %lf)\n", pose.pos[0], pose.pos[1],
139 // pose.pos[2]);
140 usleep(15 * 1000);
133 } 141 }
134} 142}
135 143
@@ -142,6 +150,6 @@ void renewCurPose() {
142 curPose[0] += speed * cos(curPose[2]) * dt; 150 curPose[0] += speed * cos(curPose[2]) * dt;
143 curPose[1] += speed * sin(curPose[2]) * dt; 151 curPose[1] += speed * sin(curPose[2]) * dt;
144 curPose[2] += curOmega * dt; 152 curPose[2] += curOmega * dt;
145 lastTime = curTime; 153 lastTime = clock();
146 pthread_mutex_unlock(&curPoseMutex); 154 pthread_mutex_unlock(&curPoseMutex);
147} \ No newline at end of file 155} \ No newline at end of file