@@ -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
429429void 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