aboutsummaryrefslogtreecommitdiffstats
path: root/serial/serial.c
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2025-01-04 14:52:55 +0800
committerWe-unite <3205135446@qq.com>2025-01-04 14:52:55 +0800
commitab091cb4661aed9b9da997e58a8b5ec1f5853951 (patch)
tree0abdf7f99b5fc069536d975b39e1bcb8cf8e77b9 /serial/serial.c
parent6c06f515f18f5913a027ba2c84092c4861e8cf45 (diff)
downloadWheelCtrl-master.tar.gz
WheelCtrl-master.zip
Fix linking error caused by wrong lib pathHEADmaster
In the old commit, CMakeLists is set to find liblcm in ${CMAKE_SOURCE_ROOT}/libs, and there are two dirs: aarch64 and x86. When I compile it for x86-64 computer using the cmake on host machine, it will automatically find lib under ${CMAKE_SOURCE_ROOT}/lib/x86, and when compiling for arm using cmake/compiler provided by ohos, it will also find under ${CMAKE_SOURCE_ROOT}/lib/aarch64. Sounds good. But, this is just a feature of special version for cmake/make/binutils, causing error on other linux distributions. The path should be given, but tools wouldn't find libs there recursively, which means path should be spercific. So in this commit, I use runme.sh to compile. It will work depending on the argument(named arch) given by user, and pass it as a macro named OHOS_ARCH to cmake, which is used in linking path of CMakeLists. Besides, libpthread.so is not always default linked. So let's write it in CMakeLists. Last but not least, keeping source code clean is our duty. There's a .clang-format under ${CMAKE_SOURCE_ROOT} to help. Use it. Moving for the better!
Diffstat (limited to 'serial/serial.c')
-rw-r--r--serial/serial.c31
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
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}