32 #include <geometry_msgs/WrenchStamped.h> 33 #include <std_srvs/Empty.h> 52 node_handle_->shutdown();
69 controller_nh.
getParam(
"force_per_voltage", parameters_.force_per_voltage = 0.559966216);
70 controller_nh.
getParam(
"torque_per_voltage", parameters_.torque_per_voltage = 7.98598e-3);
71 controller_nh.
getParam(
"lever", parameters_.lever = 0.275);
72 root_nh.
param<std::string>(
"base_link_frame", base_link_frame_,
"base_link");
88 wrench_.wrench.force.x = 0.0;
89 wrench_.wrench.force.y = 0.0;
90 wrench_.wrench.force.z = 0.0;
91 wrench_.wrench.torque.x = 0.0;
92 wrench_.wrench.torque.y = 0.0;
93 wrench_.wrench.torque.z = 0.0;
95 motor_.force.assign(4, 0.0);
96 motor_.torque.assign(4, 0.0);
97 motor_.frequency.clear();
98 motor_.voltage.assign(4, 0.0);
104 if (wrench_.header.stamp.isZero()) wrench_.header.stamp =
ros::Time::now();
107 if (!isRunning()) this->startRequest(wrench_.header.stamp);
113 motor_output_->start();
118 motor_output_->stop();
124 if (wrench_input_->connected() && wrench_input_->enabled()) {
125 wrench_.wrench = wrench_input_->getCommand();
129 if (wrench_.wrench.force.z > 0.0) {
131 double nominal_thrust_per_motor = wrench_.wrench.force.z / 4.0;
132 motor_.force[0] = nominal_thrust_per_motor - wrench_.wrench.torque.y / 2.0 / parameters_.lever;
133 motor_.force[1] = nominal_thrust_per_motor - wrench_.wrench.torque.x / 2.0 / parameters_.lever;
134 motor_.force[2] = nominal_thrust_per_motor + wrench_.wrench.torque.y / 2.0 / parameters_.lever;
135 motor_.force[3] = nominal_thrust_per_motor + wrench_.wrench.torque.x / 2.0 / parameters_.lever;
137 double nominal_torque_per_motor = wrench_.wrench.torque.z / 4.0;
138 motor_.voltage[0] = motor_.force[0] / parameters_.force_per_voltage + nominal_torque_per_motor / parameters_.torque_per_voltage;
139 motor_.voltage[1] = motor_.force[1] / parameters_.force_per_voltage - nominal_torque_per_motor / parameters_.torque_per_voltage;
140 motor_.voltage[2] = motor_.force[2] / parameters_.force_per_voltage + nominal_torque_per_motor / parameters_.torque_per_voltage;
141 motor_.voltage[3] = motor_.force[3] / parameters_.force_per_voltage - nominal_torque_per_motor / parameters_.torque_per_voltage;
143 motor_.torque[0] = motor_.voltage[0] * parameters_.torque_per_voltage;
144 motor_.torque[1] = motor_.voltage[1] * parameters_.torque_per_voltage;
145 motor_.torque[2] = motor_.voltage[2] * parameters_.torque_per_voltage;
146 motor_.torque[3] = motor_.voltage[3] * parameters_.torque_per_voltage;
148 if (motor_.voltage[0] < 0.0) motor_.voltage[0] = 0.0;
149 if (motor_.voltage[1] < 0.0) motor_.voltage[1] = 0.0;
150 if (motor_.voltage[2] < 0.0) motor_.voltage[2] = 0.0;
151 if (motor_.voltage[3] < 0.0) motor_.voltage[3] = 0.0;
158 motor_.header.stamp = time;
159 motor_.header.frame_id =
"base_link";
160 motor_output_->setCommand(motor_);
WrenchCommandHandlePtr wrench_input_
boost::shared_ptr< HandleType > addOutput(const std::string &name)
ros::Subscriber wrench_subscriber_
void stopping(const ros::Time &time)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
boost::shared_ptr< HandleType > addInput(const std::string &name)
void wrenchCommandCallback(const geometry_msgs::WrenchStampedConstPtr &command)
ros::NodeHandle * node_handle_
double torque_per_voltage
MotorCommandHandlePtr motor_output_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
hector_uav_msgs::MotorCommand motor_
ros::ServiceServer engage_service_server_
bool getParam(const std::string &key, std::string &s) const
void update(const ros::Time &time, const ros::Duration &period)
ros::ServiceServer shutdown_service_server_
geometry_msgs::WrenchStamped wrench_
void starting(const ros::Time &time)
std::string base_link_frame_
bool init(QuadrotorInterface *interface, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)