|
|
@ -46,6 +46,8 @@ config::Config UGV::DefaultConfig() { |
|
|
|
|
|
|
|
|
|
|
|
c.set_min_target_dist(10.0); |
|
|
|
c.set_min_target_dist(10.0); |
|
|
|
c.set_min_flip_pitch(90.0); |
|
|
|
c.set_min_flip_pitch(90.0); |
|
|
|
|
|
|
|
c.set_drive_power(0.3); |
|
|
|
|
|
|
|
c.set_mag_declination(11.5); |
|
|
|
return c; |
|
|
|
return c; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -82,6 +84,15 @@ void UGV::UpdateAHRS() { |
|
|
|
io::Vec3f &g = inputs_.mpu.gyro_rate, &a = inputs_.mpu.accel, |
|
|
|
io::Vec3f &g = inputs_.mpu.gyro_rate, &a = inputs_.mpu.accel, |
|
|
|
&m = inputs_.mpu.mag; |
|
|
|
&m = inputs_.mpu.mag; |
|
|
|
ahrs_.update(g.x, g.y, g.z, a.x, a.y, a.z, m.x, m.y, m.z); |
|
|
|
ahrs_.update(g.x, g.y, g.z, a.x, a.y, a.z, m.x, m.y, m.z); |
|
|
|
|
|
|
|
yaw_ = ahrs_.getYaw() + conf_.mag_declination(); |
|
|
|
|
|
|
|
while (yaw_ > 360.) { |
|
|
|
|
|
|
|
yaw_ -= 360.; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
while (yaw_ < 0.) { |
|
|
|
|
|
|
|
yaw_ += 360.; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pitch_ = ahrs_.getPitch(); |
|
|
|
|
|
|
|
roll_ = ahrs_.getRoll(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UGV::DoDebugPrint() { |
|
|
|
void UGV::DoDebugPrint() { |
|
|
@ -89,16 +100,16 @@ void UGV::DoDebugPrint() { |
|
|
|
ESP_LOGD(TAG, "inputs: acc=(%f, %f, %f) gyro=(%f, %f, %f) mag=(%f, %f, %f)", |
|
|
|
ESP_LOGD(TAG, "inputs: acc=(%f, %f, %f) gyro=(%f, %f, %f) mag=(%f, %f, %f)", |
|
|
|
mpu.accel.x, mpu.accel.y, mpu.accel.z, mpu.gyro_rate.x, |
|
|
|
mpu.accel.x, mpu.accel.y, mpu.accel.z, mpu.gyro_rate.x, |
|
|
|
mpu.gyro_rate.y, mpu.gyro_rate.z, mpu.mag.x, mpu.mag.y, mpu.mag.z); |
|
|
|
mpu.gyro_rate.y, mpu.gyro_rate.z, mpu.mag.x, mpu.mag.y, mpu.mag.z); |
|
|
|
//ESP_LOGD(TAG, "ahrs: yaw=%f, pitch=%f, roll=%f", ahrs_.getYaw(),
|
|
|
|
ESP_LOGD(TAG, "ahrs: yaw=%f, pitch=%f, roll=%f", yaw_, pitch_, roll_); |
|
|
|
// ahrs_.getPitch(), ahrs_.getRoll());
|
|
|
|
ESP_LOGD(TAG, "target angle: %f", angle_controller_.Setpoint()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UGV::ReadComms() { |
|
|
|
void UGV::ReadComms() { |
|
|
|
comms->Lock(); |
|
|
|
comms->Lock(); |
|
|
|
UpdateLocationFromGPS(*(comms->status.mutable_location()), inputs_.gps); |
|
|
|
UpdateLocationFromGPS(*(comms->status.mutable_location()), inputs_.gps); |
|
|
|
comms->status.set_yaw_angle(ahrs_.getYaw()); |
|
|
|
comms->status.set_yaw_angle(yaw_); |
|
|
|
comms->status.set_pitch_angle(ahrs_.getPitch()); |
|
|
|
comms->status.set_pitch_angle(pitch_); |
|
|
|
comms->status.set_roll_angle(ahrs_.getRoll()); |
|
|
|
comms->status.set_roll_angle(roll_); |
|
|
|
UGV_State comms_ugv_state = comms->status.state(); |
|
|
|
UGV_State comms_ugv_state = comms->status.state(); |
|
|
|
if (comms_ugv_state != current_state_) { |
|
|
|
if (comms_ugv_state != current_state_) { |
|
|
|
ESP_LOGI(TAG, "Comms updated UGV state to %d", comms_ugv_state); |
|
|
|
ESP_LOGI(TAG, "Comms updated UGV state to %d", comms_ugv_state); |
|
|
@ -135,12 +146,12 @@ void UGV::OnTick() { |
|
|
|
ReadComms(); |
|
|
|
ReadComms(); |
|
|
|
next_state_ = current_state_; |
|
|
|
next_state_ = current_state_; |
|
|
|
|
|
|
|
|
|
|
|
angle_controller_.Input(ahrs_.getYaw()); |
|
|
|
angle_controller_.Input(yaw_); |
|
|
|
float drive_power = 0.; |
|
|
|
float drive_power = 0.; |
|
|
|
outputs_.left_motor = 0.0; |
|
|
|
outputs_.left_motor = 0.0; |
|
|
|
outputs_.right_motor = 0.0; |
|
|
|
outputs_.right_motor = 0.0; |
|
|
|
|
|
|
|
|
|
|
|
float pitch = ahrs_.getRoll(); // TODO: fix quaternion -> YPR
|
|
|
|
float pitch = roll_; // TODO: fix quaternion -> YPR
|
|
|
|
auto min_flip_pitch = conf_.min_flip_pitch(); |
|
|
|
auto min_flip_pitch = conf_.min_flip_pitch(); |
|
|
|
bool is_upside_down = (pitch > min_flip_pitch) || (pitch < -min_flip_pitch); |
|
|
|
bool is_upside_down = (pitch > min_flip_pitch) || (pitch < -min_flip_pitch); |
|
|
|
|
|
|
|
|
|
|
@ -217,6 +228,7 @@ void UGV::OnTick() { |
|
|
|
float tgt_bearing = current_pos.bearing_toward(target_); |
|
|
|
float tgt_bearing = current_pos.bearing_toward(target_); |
|
|
|
angle_controller_.Enable(); |
|
|
|
angle_controller_.Enable(); |
|
|
|
angle_controller_.Setpoint(tgt_bearing); |
|
|
|
angle_controller_.Setpoint(tgt_bearing); |
|
|
|
|
|
|
|
drive_power = conf_.drive_power(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case UGV_State::STATE_TEST: |
|
|
|
case UGV_State::STATE_TEST: |
|
|
|