aboutsummaryrefslogtreecommitdiffstats
path: root/serial
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
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')
-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;