aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2024-06-24 22:10:01 +0800
committerWe-unite <3205135446@qq.com>2024-06-24 22:10:01 +0800
commit6c06f515f18f5913a027ba2c84092c4861e8cf45 (patch)
tree56ecdd968a78ba7dcc641efd9f8d119d5288793b
parent692b77cc3b1bb030ed83416d76b561d11a57d1e0 (diff)
downloadWheelCtrl-6c06f515f18f5913a027ba2c84092c4861e8cf45.tar.gz
WheelCtrl-6c06f515f18f5913a027ba2c84092c4861e8cf45.zip
Update sth && add "cancel target"
- set sita as rad - fix the change between little to big end - sth else
-rw-r--r--serial/serial.c16
-rw-r--r--serial/serial.h4
-rw-r--r--udp2lcm/udp2lcm.c13
3 files changed, 20 insertions, 13 deletions
diff --git a/serial/serial.c b/serial/serial.c
index 61be0aa..a2f253a 100644
--- a/serial/serial.c
+++ b/serial/serial.c
@@ -95,12 +95,16 @@ void parsePath(const lcm_recv_buf_t *rbuf, const char *channel,
95 } 95 }
96 v = msg->xyr[0][0]; 96 v = msg->xyr[0][0];
97 w = msg->xyr[0][1]; 97 w = msg->xyr[0][1];
98 printf("v: %f m/s, w: %f rad/s\n", v, w);
98 if (fabs(v) <= 0.01 && fabs(w) <= 0.01) { 99 if (fabs(v) <= 0.01 && fabs(w) <= 0.01) {
99 wheelSend(0x00, 0x00, 0x00, 0x00); 100 wheelSend(0x00, 0x00, 0x00, 0x00);
100 renewCurPose(); 101 renewCurPose();
101 curSpeed = 0; 102 curSpeed = 0;
102 curOmega = 0; 103 curOmega = 0;
103 } else { 104 } else {
105 if (w <= 0.2) {
106 w *= 2;
107 }
104 vWheels[0] = (int8_t)((double)(v - w * RADIUS) / FULLSPEED * 100); 108 vWheels[0] = (int8_t)((double)(v - w * RADIUS) / FULLSPEED * 100);
105 vWheels[1] = (int8_t)((double)(v + w * RADIUS) / FULLSPEED * 100); 109 vWheels[1] = (int8_t)((double)(v + w * RADIUS) / FULLSPEED * 100);
106 bWheels[0] = vWheels[0] > 0 ? 0x01 : 0x02; 110 bWheels[0] = vWheels[0] > 0 ? 0x01 : 0x02;
@@ -110,6 +114,7 @@ void parsePath(const lcm_recv_buf_t *rbuf, const char *channel,
110 curSpeed = (int8_t)((double)v / FULLSPEED * 100); 114 curSpeed = (int8_t)((double)v / FULLSPEED * 100);
111 curOmega = (int8_t)w; 115 curOmega = (int8_t)w;
112 } 116 }
117 printf("curSpeed: %d, curOmega: %f\n", curSpeed, curOmega);
113} 118}
114 119
115void setCurPose(const lcm_recv_buf_t *rbuf, const char *channel, 120void setCurPose(const lcm_recv_buf_t *rbuf, const char *channel,
@@ -127,16 +132,11 @@ void sendCurPose() {
127 while (true) { 132 while (true) {
128 renewCurPose(); 133 renewCurPose();
129 pthread_mutex_lock(&curPoseMutex); 134 pthread_mutex_lock(&curPoseMutex);
130 // pose.pos[0] = curPose[0]; 135 pose.pos[0] = curPose[0];
131 // pose.pos[1] = curPose[1]; 136 pose.pos[1] = curPose[1];
132 // pose.pos[2] = curPose[2]; 137 pose.pos[2] = curPose[2];
133 pose.pos[0] = 0.0;
134 pose.pos[1] = 0.0;
135 pose.pos[2] = 0.0;
136 pthread_mutex_unlock(&curPoseMutex); 138 pthread_mutex_unlock(&curPoseMutex);
137 pose_t_publish(lcm, "POSE", &pose); 139 pose_t_publish(lcm, "POSE", &pose);
138 // printf("sent (%lf, %lf, %lf)\n", pose.pos[0], pose.pos[1],
139 // pose.pos[2]);
140 usleep(15 * 1000); 140 usleep(15 * 1000);
141 } 141 }
142} 142}
diff --git a/serial/serial.h b/serial/serial.h
index 7f09bf8..3563557 100644
--- a/serial/serial.h
+++ b/serial/serial.h
@@ -17,8 +17,8 @@
17#define MAX_BUFFER_SIZE 1024 17#define MAX_BUFFER_SIZE 1024
18#define DEFAULT_SPEED 0x15 // 默认速度,百分比 18#define DEFAULT_SPEED 0x15 // 默认速度,百分比
19// TODO: 两个待测数据 19// TODO: 两个待测数据
20#define RADIUS 0.26 // 两轮之间的距离的一半,米 20#define RADIUS 0.13 // 两轮之间的距离的一半,米
21#define FULLSPEED 1.5 // 轮子全速,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
diff --git a/udp2lcm/udp2lcm.c b/udp2lcm/udp2lcm.c
index 9ac380f..36100da 100644
--- a/udp2lcm/udp2lcm.c
+++ b/udp2lcm/udp2lcm.c
@@ -116,14 +116,22 @@ void parseCmd(const char *buffer, int bytesReceived) {
116 x = swapEndian(*(int16_t *)&buffer[3]); 116 x = swapEndian(*(int16_t *)&buffer[3]);
117 y = swapEndian(*(int16_t *)&buffer[5]); 117 y = swapEndian(*(int16_t *)&buffer[5]);
118 sita = 0; 118 sita = 0;
119 // printf("End point: x: %d, y: %d, sita: %d\n", x, y, sita);
120 // printf("Original buffer: ", buffer);
121 robotCtrlInit(&robotCtrlData, 0, 20, 0, 3, 0, 0, 0); 119 robotCtrlInit(&robotCtrlData, 0, 20, 0, 3, 0, 0, 0);
122 robotCtrlData.dparams[0] = (double)x / 20; 120 robotCtrlData.dparams[0] = (double)x / 20;
123 robotCtrlData.dparams[1] = (double)y / 20; 121 robotCtrlData.dparams[1] = (double)y / 20;
124 robotCtrlData.dparams[2] = sita; 122 robotCtrlData.dparams[2] = sita;
125 robot_control_t_publish(lcm, "ROBOT_CONTROL", &robotCtrlData); 123 robot_control_t_publish(lcm, "ROBOT_CONTROL", &robotCtrlData);
126 freeRobotCtrl(&robotCtrlData); 124 freeRobotCtrl(&robotCtrlData);
125 } else if (buffer[0] == 4) {
126 // 取消导航,删除上一个目标点
127 robotCtrlInit(&robotCtrlData, 0, 23, 0, 0, 0, 0, 0);
128 robot_control_t_publish(lcm, "ROBOT_CONTROL", &robotCtrlData);
129 } else {
130 fprintf(stderr, "Error: Invalid command: ");
131 for (int i = 0; i < 9; i++) {
132 fprintf(stderr, "%02hhx ", buffer[i]);
133 }
134 fprintf(stderr, "\n");
127 } 135 }
128} 136}
129 137
@@ -147,7 +155,6 @@ void poseHandler(const lcm_recv_buf_t *rbuf, const char *channel,
147 heartBeat[7] = sita >> 8; 155 heartBeat[7] = sita >> 8;
148 heartBeat[8] = sita; 156 heartBeat[8] = sita;
149 pthread_mutex_unlock(&heartBeatMutex); 157 pthread_mutex_unlock(&heartBeatMutex);
150 printf("curpose: x: %d, y: %d, sita: %d\n", x, y, sita);
151} 158}
152 159
153int16_t swapEndian(int16_t val) { return (val << 8) | ((val >> 8) & 0xFF); } \ No newline at end of file 160int16_t swapEndian(int16_t val) { return (val << 8) | ((val >> 8) & 0xFF); } \ No newline at end of file