Skip to content

Commit 1d0dc66

Browse files
authored
Merge pull request #144 from Pitt-RAS/xy-pterm
P terms on XY position in addition to Z
2 parents 1a83da3 + cd0a4be commit 1d0dc66

6 files changed

Lines changed: 41 additions & 23 deletions

File tree

cfg/LowLevelMotion.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ from dynamic_reconfigure.parameter_generator_catkin import *
55

66
gen = ParameterGenerator()
77

8-
gen.add('height_p', double_t, 0, '', 0.0, 0.0, 100.0)
8+
gen.add('position_p_x', double_t, 0, '', 0.0, 0.0, 100.0)
9+
gen.add('position_p_y', double_t, 0, '', 0.0, 0.0, 100.0)
10+
gen.add('position_p_z', double_t, 0, '', 0.0, 0.0, 100.0)
911

1012
gen.add('throttle_p', double_t, 0, '', 0.0, 0.0, 20.0)
1113
gen.add('throttle_i', double_t, 0, '',0.0, 0.0, 20.0)

include/iarc7_motion/QuadVelocityController.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class QuadVelocityController
5050
QuadVelocityController(double throttle_pid_settings[6],
5151
double pitch_pid_settings[6],
5252
double roll_pid_settings[6],
53-
double& height_p,
53+
double (&position_p)[3],
5454
const ThrustModel& thrust_model,
5555
const ThrustModel& thrust_model_side,
5656
const ros::Duration& battery_timeout,
@@ -118,8 +118,8 @@ class QuadVelocityController
118118
// The XY plan mixer to use
119119
std::string xy_mixer_;
120120

121-
// P term for the position control
122-
double& height_p_;
121+
// P terms for the position control
122+
double (&position_p_)[3];
123123

124124
// Last time an update was successful
125125
ros::Time last_update_time_;

param/low_level_motion_2.0.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# The PID constants are applied to positional errors in the map frame
2+
position_p_x: 0.0
3+
position_p_y: 0.0
4+
position_p_z: 1.5
5+
16
# PID values are positive for forward acting PID loops and negative for
27
# reverse acting PID loops. P, I, and D should all be the same sign.
3-
height_p: 1.5
48
throttle_p: 2.5
59
throttle_i: 0.2
610
throttle_d: 0.4

param/low_level_motion_sim.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# The PID constants are applied to positional errors in the map frame
2+
position_p_x: 0.0
3+
position_p_y: 0.0
4+
position_p_z: 5.0
5+
16
# PID values are positive for forward acting PID loops and negative for
27
# reverse acting PID loops. P, I, and D should all be the same sign.
3-
height_p: 5.0
48
throttle_p: 5.0
59
throttle_i: 0.5
610
throttle_d: 0.5

src/LowLevelMotionController.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int main(int argc, char **argv)
9393
double throttle_pid[pid_param_array_size];
9494
double pitch_pid[pid_param_array_size];
9595
double roll_pid[pid_param_array_size];
96-
double height_p = 0.0;
96+
double position_p[3];
9797

9898
ThrustModel thrust_model(private_nh, "thrust_model");
9999
ThrustModel thrust_model_side;
@@ -136,7 +136,9 @@ int main(int argc, char **argv)
136136
roll_pid[4] = config.roll_accumulator_min;
137137
roll_pid[5] = config.roll_accumulator_enable_threshold;
138138

139-
height_p = config.height_p;
139+
position_p[0] = config.position_p_x;
140+
position_p[1] = config.position_p_y;
141+
position_p[2] = config.position_p_z;
140142

141143
dynamic_reconfigure_called = true;
142144
};
@@ -190,7 +192,7 @@ int main(int argc, char **argv)
190192
QuadVelocityController quadController(throttle_pid,
191193
pitch_pid,
192194
roll_pid,
193-
height_p,
195+
position_p,
194196
thrust_model,
195197
thrust_model_side,
196198
ros::Duration(battery_timeout),
@@ -292,7 +294,7 @@ int main(int argc, char **argv)
292294

293295
//cancellation inputs
294296
if(server.isPreemptRequested()) {
295-
297+
296298
if(motion_state == MotionState::PASSTHROUGH) {
297299
ROS_INFO("Transitioning out of PASSTHROUGH");
298300
bool success = quadController.prepareForTakeover();
@@ -391,7 +393,7 @@ int main(int argc, char **argv)
391393
iarc7_msgs::OrientationThrottleStamped uav_command;
392394

393395
// Check for a safety state in which case we should execute our safety response
394-
if(safety_client.isSafetyActive()
396+
if(safety_client.isSafetyActive()
395397
&& !safety_client.isSafetyResponseActive())
396398
{
397399
// This is the safety response
@@ -466,7 +468,7 @@ int main(int argc, char **argv)
466468
if (last_msg != nullptr && last_msg->header.stamp >= passthrough_start_time) {
467469
geometry_msgs::Twist twist;
468470
twist.linear.z = last_msg->throttle;
469-
471+
470472
MotionPointStamped motion_point;
471473
motion_point.motion_point.twist.linear.z = twist.linear.z;
472474

src/QuadVelocityController.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ QuadVelocityController::QuadVelocityController(
3434
double vz_pid_settings[6],
3535
double vx_pid_settings[6],
3636
double vy_pid_settings[6],
37-
double& height_p,
37+
double (&position_p)[3],
3838
const ThrustModel& thrust_model,
3939
const ThrustModel& thrust_model_side,
4040
const ros::Duration& battery_timeout,
@@ -59,7 +59,7 @@ QuadVelocityController::QuadVelocityController(
5959
xy_mixer_(ros_utils::ParamUtils::getParam<std::string>(
6060
private_nh,
6161
"xy_mixer")),
62-
height_p_(height_p),
62+
position_p_(position_p),
6363
startup_timeout_(ros_utils::ParamUtils::getParam<double>(
6464
private_nh,
6565
"startup_timeout")),
@@ -237,7 +237,7 @@ bool QuadVelocityController::update(const ros::Time& time,
237237
double local_y_setpoint_accel = -std::sin(current_yaw) * setpoint_accel.x
238238
+ std::cos(current_yaw) * setpoint_accel.y;
239239

240-
if (level_flight_active_ && col_height
240+
if (level_flight_active_ && col_height
241241
> level_flight_required_height_
242242
+ level_flight_required_hysteresis_) {
243243
level_flight_active_ = false;
@@ -428,19 +428,25 @@ bool QuadVelocityController::waitUntilReady()
428428

429429
void QuadVelocityController::updatePidSetpoints(double current_yaw, const Eigen::VectorXd& odometry)
430430
{
431-
double position_velocity_request = height_p_ *
432-
(setpoint_.motion_point.pose.position.z - odometry[5]);
431+
double position_velocity_request[3] = {
432+
position_p_[0] * (setpoint_.motion_point.pose.position.x - odometry[3]),
433+
position_p_[1] * (setpoint_.motion_point.pose.position.y - odometry[4]),
434+
position_p_[2] * (setpoint_.motion_point.pose.position.z - odometry[5])
435+
};
433436

434-
double velocity_request = position_velocity_request + setpoint_.motion_point.twist.linear.z;
437+
double map_z_velocity = position_velocity_request[2] + setpoint_.motion_point.twist.linear.z;
435438

436-
vz_pid_.setSetpoint(velocity_request);
439+
vz_pid_.setSetpoint(map_z_velocity);
437440

438441
// x and y velocities are transformed according to the last yaw
439442
// angle because the incoming target velocities are in the map frame
440-
double local_x_velocity = setpoint_.motion_point.twist.linear.x * std::cos(current_yaw)
441-
+ setpoint_.motion_point.twist.linear.y * std::sin(current_yaw);
442-
double local_y_velocity = setpoint_.motion_point.twist.linear.x * -std::sin(current_yaw)
443-
+ setpoint_.motion_point.twist.linear.y * std::cos(current_yaw);
443+
double map_x_velocity = setpoint_.motion_point.twist.linear.x + position_velocity_request[0];
444+
double map_y_velocity = setpoint_.motion_point.twist.linear.y + position_velocity_request[1];
445+
446+
double local_x_velocity = map_x_velocity * std::cos(current_yaw)
447+
+ map_y_velocity * std::sin(current_yaw);
448+
double local_y_velocity = map_x_velocity * -std::sin(current_yaw)
449+
+ map_y_velocity * std::cos(current_yaw);
444450

445451
vx_pid_.setSetpoint(local_x_velocity);
446452
vy_pid_.setSetpoint(local_y_velocity);

0 commit comments

Comments
 (0)