Skip to content

Commit 635b856

Browse files
authored
Merge pull request #145 from Pitt-RAS/yaw-hold
Hack the heading to straight ahead
2 parents 1d0dc66 + befaa96 commit 635b856

8 files changed

Lines changed: 36 additions & 13 deletions

cfg/LowLevelMotion.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ gen.add('roll_accumulator_max', double_t, 0, '', 0.0, 0.0, 100.0)
3030
gen.add('roll_accumulator_min', double_t, 0, '', 0.0, 0.0, 100.0)
3131
gen.add('roll_accumulator_enable_threshold', double_t, 0, '', 0.0, 0.0, 100.0)
3232

33+
gen.add('yaw_p', double_t, 0, '', 0.0, 0.0, 100.0)
34+
3335
exit(gen.generate(PACKAGE, "iarc7_motion", "LowLevelMotion"))

include/iarc7_motion/LandPlanner.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class LandPlanner
6868

6969
LandState state_;
7070

71+
double requested_x_;
72+
double requested_y_;
7173
double requested_height_;
7274
double cushion_height_;
7375

include/iarc7_motion/QuadVelocityController.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class QuadVelocityController
5151
double pitch_pid_settings[6],
5252
double roll_pid_settings[6],
5353
double (&position_p)[3],
54+
double yaw_p,
5455
const ThrustModel& thrust_model,
5556
const ThrustModel& thrust_model_side,
5657
const ros::Duration& battery_timeout,
@@ -121,6 +122,9 @@ class QuadVelocityController
121122
// P terms for the position control
122123
double (&position_p_)[3];
123124

125+
// P term for yaw hold
126+
double yaw_p_;
127+
124128
// Last time an update was successful
125129
ros::Time last_update_time_;
126130

param/low_level_motion_2.0.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The PID constants are applied to positional errors in the map frame
2-
position_p_x: 0.0
3-
position_p_y: 0.0
2+
position_p_x: 1.0
3+
position_p_y: 1.0
44
position_p_z: 1.5
55

66
# PID values are positive for forward acting PID loops and negative for
@@ -36,6 +36,8 @@ roll_accumulator_max: 5.0
3636
roll_accumulator_min: -5.0
3737
roll_accumulator_enable_threshold: 10.0
3838

39+
yaw_p: 0.4
40+
3941
min_side_thrust: 0.1
4042
max_side_thrust: 10.0
4143

@@ -45,11 +47,11 @@ throttle_max_rate : 200.0
4547

4648
pitch_max : 0.175
4749
pitch_min : -0.175
48-
pitch_max_rate : 1.0
50+
pitch_max_rate : 2.0
4951

5052
roll_max : 0.175
5153
roll_min : -0.175
52-
roll_max_rate : 1.0
54+
roll_max_rate : 2.0
5355

5456
yaw_max : 0.5
5557
yaw_min : -0.5

param/low_level_motion_sim.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The PID constants are applied to positional errors in the map frame
2-
position_p_x: 0.0
3-
position_p_y: 0.0
2+
position_p_x: 1.0
3+
position_p_y: 1.0
44
position_p_z: 5.0
55

66
# PID values are positive for forward acting PID loops and negative for
@@ -36,6 +36,8 @@ roll_accumulator_max: 5.0
3636
roll_accumulator_min: -5.0
3737
roll_accumulator_enable_threshold: 10.0
3838

39+
yaw_p: 0.4
40+
3941
min_side_thrust: 0.0
4042
max_side_thrust: 0.0
4143

src/LandPlanner.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ LandPlanner::LandPlanner(
2323
landing_detected_message_received_(false),
2424
transform_wrapper_(),
2525
state_(LandState::DONE),
26+
requested_x_(0.0),
27+
requested_y_(0.0),
2628
requested_height_(0.0),
2729
cushion_height_(0.0),
2830
actual_descend_rate_(0.0),
@@ -44,7 +46,7 @@ LandPlanner::LandPlanner(
4446
"startup_timeout")),
4547
update_timeout_(ros_utils::ParamUtils::getParam<double>(
4648
private_nh,
47-
"update_timeout")),
49+
"update_timeout")),
4850
uav_arm_client_(nh.serviceClient<iarc7_msgs::Arm>("uav_arm"))
4951
{
5052
landing_detected_subscriber_ = nh.subscribe("landing_detected",
@@ -83,10 +85,12 @@ bool LandPlanner::prepareForTakeover(const ros::Time& time)
8385
return false;
8486
}
8587

86-
requested_height_ = transform.transform.translation.z;
88+
requested_x_ = transform.transform.translation.x;
89+
requested_y_ = transform.transform.translation.y;
90+
requested_height_ = transform.transform.translation.z;
8791

8892
// height determined by the ratio of landing accelerations
89-
cushion_height_ = std::min(0.5 * (std::pow(descend_rate_,2)/cushion_acceleration_),
93+
cushion_height_ = std::min(0.5 * (std::pow(descend_rate_,2)/cushion_acceleration_),
9094
requested_height_ * ( 1 - ( 1 / ( 1 - descend_acceleration_/cushion_acceleration_))));
9195
actual_descend_rate_ = 0.0;
9296

@@ -133,7 +137,7 @@ bool LandPlanner::getTargetMotionPoint(const ros::Time& time,
133137
+ (cushion_acceleration_
134138
* (time - last_update_time_).toSec()));
135139
}
136-
140+
137141
requested_height_ = std::max(0.0, requested_height_
138142
+ (actual_descend_rate_
139143
* (time - last_update_time_).toSec()));
@@ -169,6 +173,8 @@ bool LandPlanner::getTargetMotionPoint(const ros::Time& time,
169173
// Fill in the uav_command's information
170174
motion_point.header.stamp = time;
171175

176+
motion_point.motion_point.pose.position.x = requested_x_;
177+
motion_point.motion_point.pose.position.y = requested_y_;
172178
motion_point.motion_point.pose.position.z = requested_height_;
173179
motion_point.motion_point.twist.linear.z = actual_descend_rate_;
174180

src/LowLevelMotionController.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ int main(int argc, char **argv)
9494
double pitch_pid[pid_param_array_size];
9595
double roll_pid[pid_param_array_size];
9696
double position_p[3];
97+
double yaw_p;
9798

9899
ThrustModel thrust_model(private_nh, "thrust_model");
99100
ThrustModel thrust_model_side;
@@ -140,6 +141,8 @@ int main(int argc, char **argv)
140141
position_p[1] = config.position_p_y;
141142
position_p[2] = config.position_p_z;
142143

144+
yaw_p = config.yaw_p;
145+
143146
dynamic_reconfigure_called = true;
144147
};
145148
dynamic_reconfigure_server.setCallback(dynamic_reconfigure_settings_callback);
@@ -193,6 +196,7 @@ int main(int argc, char **argv)
193196
pitch_pid,
194197
roll_pid,
195198
position_p,
199+
yaw_p,
196200
thrust_model,
197201
thrust_model_side,
198202
ros::Duration(battery_timeout),

src/QuadVelocityController.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ QuadVelocityController::QuadVelocityController(
3535
double vx_pid_settings[6],
3636
double vy_pid_settings[6],
3737
double (&position_p)[3],
38+
double yaw_p,
3839
const ThrustModel& thrust_model,
3940
const ThrustModel& thrust_model_side,
4041
const ros::Duration& battery_timeout,
@@ -60,6 +61,7 @@ QuadVelocityController::QuadVelocityController(
6061
private_nh,
6162
"xy_mixer")),
6263
position_p_(position_p),
64+
yaw_p_(yaw_p),
6365
startup_timeout_(ros_utils::ParamUtils::getParam<double>(
6466
private_nh,
6567
"startup_timeout")),
@@ -346,9 +348,8 @@ bool QuadVelocityController::update(const ros::Time& time,
346348
col_height)
347349
/ voltage;
348350

349-
// Yaw rate needs no correction because the input and output are both
350-
// velocities
351-
uav_command.data.yaw = -setpoint_.motion_point.twist.angular.z;
351+
// Hack heading to straight ahead
352+
uav_command.data.yaw = -yaw_p_ * (0.0 - current_yaw);
352353

353354
// Check that the PID loops did not return invalid values before returning
354355
if (!std::isfinite(uav_command.throttle)

0 commit comments

Comments
 (0)