Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "roll_pitch_yawrate_thrust_controller_node.h"
00022
00023 #include "rotors_control/parameters_ros.h"
00024
00025 namespace rotors_control {
00026
00027 RollPitchYawrateThrustControllerNode::RollPitchYawrateThrustControllerNode() {
00028 InitializeParams();
00029
00030 ros::NodeHandle nh;
00031
00032 cmd_roll_pitch_yawrate_thrust_sub_ = nh.subscribe(kDefaultCommandRollPitchYawrateThrustTopic, 1,
00033 &RollPitchYawrateThrustControllerNode::RollPitchYawrateThrustCallback, this);
00034 odometry_sub_ = nh.subscribe(kDefaultOdometryTopic, 1,
00035 &RollPitchYawrateThrustControllerNode::OdometryCallback, this);
00036
00037 motor_velocity_reference_pub_ = nh.advertise<mav_msgs::Actuators>(
00038 kDefaultCommandMotorSpeedTopic, 1);
00039 }
00040
00041 RollPitchYawrateThrustControllerNode::~RollPitchYawrateThrustControllerNode() { }
00042
00043 void RollPitchYawrateThrustControllerNode::InitializeParams() {
00044 ros::NodeHandle pnh("~");
00045
00046
00047 GetRosParameter(pnh, "attitude_gain/x",
00048 roll_pitch_yawrate_thrust_controller_.controller_parameters_.attitude_gain_.x(),
00049 &roll_pitch_yawrate_thrust_controller_.controller_parameters_.attitude_gain_.x());
00050 GetRosParameter(pnh, "attitude_gain/y",
00051 roll_pitch_yawrate_thrust_controller_.controller_parameters_.attitude_gain_.y(),
00052 &roll_pitch_yawrate_thrust_controller_.controller_parameters_.attitude_gain_.y());
00053 GetRosParameter(pnh, "attitude_gain/z",
00054 roll_pitch_yawrate_thrust_controller_.controller_parameters_.attitude_gain_.z(),
00055 &roll_pitch_yawrate_thrust_controller_.controller_parameters_.attitude_gain_.z());
00056 GetRosParameter(pnh, "angular_rate_gain/x",
00057 roll_pitch_yawrate_thrust_controller_.controller_parameters_.angular_rate_gain_.x(),
00058 &roll_pitch_yawrate_thrust_controller_.controller_parameters_.angular_rate_gain_.x());
00059 GetRosParameter(pnh, "angular_rate_gain/y",
00060 roll_pitch_yawrate_thrust_controller_.controller_parameters_.angular_rate_gain_.y(),
00061 &roll_pitch_yawrate_thrust_controller_.controller_parameters_.angular_rate_gain_.y());
00062 GetRosParameter(pnh, "angular_rate_gain/z",
00063 roll_pitch_yawrate_thrust_controller_.controller_parameters_.angular_rate_gain_.z(),
00064 &roll_pitch_yawrate_thrust_controller_.controller_parameters_.angular_rate_gain_.z());
00065 GetVehicleParameters(pnh, &roll_pitch_yawrate_thrust_controller_.vehicle_parameters_);
00066 roll_pitch_yawrate_thrust_controller_.InitializeParameters();
00067 }
00068 void RollPitchYawrateThrustControllerNode::Publish() {
00069 }
00070
00071 void RollPitchYawrateThrustControllerNode::RollPitchYawrateThrustCallback(
00072 const mav_msgs::RollPitchYawrateThrustConstPtr& roll_pitch_yawrate_thrust_reference_msg) {
00073 mav_msgs::EigenRollPitchYawrateThrust roll_pitch_yawrate_thrust;
00074 mav_msgs::eigenRollPitchYawrateThrustFromMsg(*roll_pitch_yawrate_thrust_reference_msg, &roll_pitch_yawrate_thrust);
00075 roll_pitch_yawrate_thrust_controller_.SetRollPitchYawrateThrust(roll_pitch_yawrate_thrust);
00076 }
00077
00078
00079 void RollPitchYawrateThrustControllerNode::OdometryCallback(const nav_msgs::OdometryConstPtr& odometry_msg) {
00080
00081 ROS_INFO_ONCE("RollPitchYawrateThrustController got first odometry message.");
00082
00083 EigenOdometry odometry;
00084 eigenOdometryFromMsg(odometry_msg, &odometry);
00085 roll_pitch_yawrate_thrust_controller_.SetOdometry(odometry);
00086
00087 Eigen::VectorXd ref_rotor_velocities;
00088 roll_pitch_yawrate_thrust_controller_.CalculateRotorVelocities(&ref_rotor_velocities);
00089
00090
00091 mav_msgs::ActuatorsPtr actuator_msg(new mav_msgs::Actuators);
00092
00093 actuator_msg->angular_velocities.clear();
00094 for (int i = 0; i < ref_rotor_velocities.size(); i++)
00095 actuator_msg->angular_velocities.push_back(ref_rotor_velocities[i]);
00096 actuator_msg->header.stamp = odometry_msg->header.stamp;
00097
00098 motor_velocity_reference_pub_.publish(actuator_msg);
00099 }
00100
00101 }
00102
00103 int main(int argc, char** argv) {
00104 ros::init(argc, argv, "roll_pitch_yawrate_thrust_controller_node");
00105
00106 rotors_control::RollPitchYawrateThrustControllerNode roll_pitch_yawrate_thrust_controller_node;
00107
00108 ros::spin();
00109
00110 return 0;
00111 }
rotors_control
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Thu Apr 18 2019 02:43:38