Skip to content

Commit 4bea518

Browse files
authored
Merge pull request #11 from wuhanstudio/add-structure
Add controller structure
2 parents 07800e4 + b452e33 commit 4bea518

File tree

18 files changed

+103
-43
lines changed

18 files changed

+103
-43
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ modules.order
5050
Module.symvers
5151
Mkfile.old
5252
dkms.conf
53+
<<<<<<< HEAD
54+
55+
=======
5356
.vscode/
57+
>>>>>>> add-structure

chassis/chassis.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,47 @@ rt_err_t chassis_update(chassis_t chas)
9191
}
9292
return RT_EOK;
9393
}
94+
95+
rt_err_t chassis_parse_command(chassis_t chas, rt_int8_t cmd, void *args)
96+
{
97+
// TODO
98+
struct velocity target_vel;
99+
100+
LOG_D("received command: cmd:%d arg:%d", cmd, *((rt_uint8_t *)args));
101+
102+
switch (cmd)
103+
{
104+
case CHASSIS_FORWARD_ANALOG:
105+
target_vel.linear_x = (float)*((rt_uint8_t *)args) / 100.0f; // m/s
106+
target_vel.linear_y = 0;
107+
target_vel.angular_z = 0;
108+
break;
109+
case CHASSIS_BACKWARD_ANALOG:
110+
target_vel.linear_x = -(float)*((rt_uint8_t *)args) / 100.0f;
111+
target_vel.linear_y = 0;
112+
target_vel.angular_z = 0;
113+
break;
114+
case CHASSIS_TURN_LEFT_ANALOG:
115+
target_vel.linear_x = 0.00f;
116+
target_vel.linear_y = 0;
117+
target_vel.angular_z = (float)*((rt_uint8_t *)args);
118+
break;
119+
case CHASSIS_TURN_RIGHT_ANALOG:
120+
target_vel.linear_x = 0.00f;
121+
target_vel.linear_y = 0;
122+
target_vel.angular_z = -(float)*((rt_uint8_t *)args);
123+
break;
124+
case CHASSIS_STOP:
125+
target_vel.linear_x = 0.00f;
126+
target_vel.linear_y = 0;
127+
target_vel.angular_z = 0;
128+
break;
129+
default:
130+
return RT_ERROR;
131+
break;
132+
}
133+
134+
chassis_set_velocity(chas, target_vel);
135+
136+
return RT_EOK;
137+
}

chassis/chassis.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
#include <kinematics.h>
55
#include <wheel.h>
66

7+
enum chassis_command
8+
{
9+
CHASSIS_FORWARD_ANALOG,
10+
CHASSIS_BACKWARD_ANALOG,
11+
CHASSIS_TURN_LEFT_ANALOG,
12+
CHASSIS_TURN_RIGHT_ANALOG,
13+
CHASSIS_STOP,
14+
};
15+
716
typedef struct chassis *chassis_t;
817

918
struct chassis
@@ -25,4 +34,6 @@ rt_err_t chassis_set_rpm(chassis_t chas, rt_int16_t target_rpm[]);
2534

2635
rt_err_t chassis_update(chassis_t chas);
2736

37+
rt_err_t chassis_parse_command(chassis_t chas, rt_int8_t cmd, void *args);
38+
2839
#endif

encoder/encoder_AB.c

Whitespace-only changes.

encoder/encoder_AB.h

Whitespace-only changes.

encoder/encoder_single.c

Whitespace-only changes.

encoder/encoder_single.h

Whitespace-only changes.

modules/SConscript

Lines changed: 0 additions & 12 deletions
This file was deleted.

modules/motor/SConscript

Lines changed: 0 additions & 14 deletions
This file was deleted.

modules/sensors/SConscript

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)