Skip to content

Commit

Permalink
Add debug message for quadrotor attitude controller
Browse files Browse the repository at this point in the history
  • Loading branch information
shengwen-tw committed May 18, 2024
1 parent 1aa2f99 commit 4e7e801
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions msg/pid.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
float error_rpy[3] "error"
25 changes: 18 additions & 7 deletions user/tasks/examples/quadrotor.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "bsp_drv.h"
#include "debug_link_attitude_msg.h"
#include "debug_link_pid_msg.h"
#include "madgwick_filter.h"
#include "pwm.h"
#include "sbus.h"
Expand Down Expand Up @@ -57,16 +58,16 @@ static madgwick_t madgwick_ahrs;
static float rpy[3];

static pid_control_t pid_roll = {
.kp = 0,
.kd = 0,
.kp = 0.015f,
.kd = 0.003f,
.output_max = +1.0f, //+100%
.output_min = -1.0f, //-100%
.enable = true,
};

static pid_control_t pid_pitch = {
.kp = 0,
.kd = 0,
.kp = 0.015f,
.kd = 0.003f,
.output_max = +1.0f,
.output_min = -1.0f,
.enable = true,
Expand Down Expand Up @@ -358,15 +359,25 @@ void debug_link_task(void)
int debug_link_fd = open("/dev/dbglink", O_RDWR);

debug_link_msg_attitude_t msg;
debug_link_msg_pid_t pid_msg;
uint8_t buf[100];

while (1) {
size_t size = pack_debug_link_attitude_msg(&msg, buf);
write(debug_link_fd, buf, size);

msg.q[0] = madgwick_ahrs.q[0];
msg.q[1] = madgwick_ahrs.q[1];
msg.q[2] = madgwick_ahrs.q[2];
msg.q[3] = madgwick_ahrs.q[3];
msg.rpy[0] = rpy[0];
msg.rpy[1] = rpy[1];
msg.rpy[2] = rpy[2];
size_t size = pack_debug_link_attitude_msg(&msg, buf);
write(debug_link_fd, buf, size);

pid_msg.error_rpy[0] = pid_roll.output;
pid_msg.error_rpy[1] = pid_pitch.output;
pid_msg.error_rpy[2] = 0.0f;
size = pack_debug_link_pid_msg(&pid_msg, buf);
write(debug_link_fd, buf, size);

usleep(10000); /* 100Hz (10ms) */
}
Expand Down

0 comments on commit 4e7e801

Please sign in to comment.