31 #include <geometry_msgs/WrenchStamped.h> 55 const std::string &robot_namespace,
57 gazebo::physics::ModelPtr parent_model,
59 std::vector<transmission_interface::TransmissionInfo> transmissions)
64 #if (GAZEBO_MAJOR_VERSION >= 8) 74 std::string state_topic;
75 model_nh.
getParam(
"state_topic", state_topic);
76 if (!state_topic.empty())
81 gzlog <<
"[hector_quadrotor_controller_gazebo] Using topic '" << state_topic <<
"' as state input for control" <<
86 gzlog <<
"[hector_quadrotor_controller_gazebo] Using ground truth from Gazebo as state input for control" <<
91 std::string imu_topic;
92 model_nh.
getParam(
"imu_topic", imu_topic);
93 if (!imu_topic.empty())
95 imu_sub_helper_ = boost::make_shared<ImuSubscriberHelper>(model_nh, imu_topic, boost::ref(
imu_));
96 gzlog <<
"[hector_quadrotor_controller_gazebo] Using topic '" << imu_topic <<
"' as imu input for control" <<
101 gzlog <<
"[hector_quadrotor_controller_gazebo] Using ground truth from Gazebo as imu input for control" <<
121 const double acceleration_time_constant = 0.1;
122 #if (GAZEBO_MAJOR_VERSION >= 8) 124 (period.
toSec() + acceleration_time_constant);
127 (period.
toSec() + acceleration_time_constant);
133 gz_acceleration_ = ((
link_->GetWorldLinearVel() -
gz_velocity_) + acceleration_time_constant * gz_acceleration_) /
134 (period.
toSec() + acceleration_time_constant);
135 gz_angular_acceleration_ =
137 (period.
toSec() + acceleration_time_constant);
152 #if (GAZEBO_MAJOR_VERSION >= 8) 197 #if (GAZEBO_MAJOR_VERSION >= 8) 204 imu_.angular_velocity.x = gz_angular_velocity_body.X();
205 imu_.angular_velocity.y = gz_angular_velocity_body.Y();
206 imu_.angular_velocity.z = gz_angular_velocity_body.Z();
208 ignition::math::Vector3d gz_linear_acceleration_body =
gz_pose_.Rot().RotateVectorReverse(
209 gz_acceleration_ -
model_->GetWorld()->Gravity());
210 imu_.linear_acceleration.x = gz_linear_acceleration_body.X();
211 imu_.linear_acceleration.y = gz_linear_acceleration_body.Y();
212 imu_.linear_acceleration.z = gz_linear_acceleration_body.Z();
220 imu_.angular_velocity.x = gz_angular_velocity_body.x;
221 imu_.angular_velocity.y = gz_angular_velocity_body.y;
222 imu_.angular_velocity.z = gz_angular_velocity_body.z;
224 gazebo::math::Vector3 gz_linear_acceleration_body =
gz_pose_.rot.RotateVectorReverse(
225 gz_acceleration_ -
physics_->GetGravity());
226 imu_.linear_acceleration.x = gz_linear_acceleration_body.x;
227 imu_.linear_acceleration.y = gz_linear_acceleration_body.y;
228 imu_.linear_acceleration.z = gz_linear_acceleration_body.z;
235 bool result_written =
false;
239 result_written =
true;
243 geometry_msgs::WrenchStamped wrench;
244 wrench.header.stamp = time;
250 if (!result_written) {
251 #if (GAZEBO_MAJOR_VERSION >= 8) 252 ignition::math::Vector3d force(wrench.wrench.force.x, wrench.wrench.force.y, wrench.wrench.force.z);
253 ignition::math::Vector3d torque(wrench.wrench.torque.x, wrench.wrench.torque.y, wrench.wrench.torque.z);
255 gazebo::math::Vector3 force(wrench.wrench.force.x, wrench.wrench.force.y, wrench.wrench.force.z);
256 gazebo::math::Vector3 torque(wrench.wrench.torque.x, wrench.wrench.torque.y, wrench.wrench.torque.z);
258 link_->AddRelativeForce(force);
259 #if (GAZEBO_MAJOR_VERSION >= 8) 260 link_->AddRelativeTorque(torque -
link_->GetInertial()->CoG().Cross(force));
262 link_->AddRelativeTorque(torque -
link_->GetInertial()->GetCoG().Cross(force));
267 wrench.wrench = geometry_msgs::Wrench();
void registerInterface(T *iface)
virtual ~QuadrotorHardwareSim()
geometry_msgs::Accel acceleration_
void registerPose(geometry_msgs::Pose *pose)
void publish(const boost::shared_ptr< M > &message) const
gazebo::math::Vector3 gz_velocity_
MotorCommandHandlePtr motor_output_
virtual void writeSim(ros::Time time, ros::Duration period)
ros::Publisher wrench_command_publisher_
void init(const ros::NodeHandle &nh, const std::string &field=std::string())
void registerMotorStatus(hector_uav_msgs::MotorStatus *motor_status)
boost::shared_ptr< HandleType > addInput(const std::string &name)
geometry_msgs::Pose pose_
ros::ServiceServer enable_motors_server_
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
hector_quadrotor_interface::WrenchLimiter wrench_limiter_
boost::shared_ptr< hector_quadrotor_interface::ImuSubscriberHelper > imu_sub_helper_
ros::Publisher motor_command_publisher_
gazebo::physics::PhysicsEnginePtr physics_
gazebo::math::Pose gz_pose_
hector_uav_msgs::MotorStatus motor_status_
boost::shared_ptr< hector_quadrotor_interface::OdomSubscriberHelper > odom_sub_helper_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
gazebo::physics::ModelPtr model_
virtual void readSim(ros::Time time, ros::Duration period)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
gazebo::physics::LinkPtr link_
void registerTwist(geometry_msgs::Twist *twist)
virtual bool initSim(const std::string &robot_namespace, ros::NodeHandle model_nh, gazebo::physics::ModelPtr parent_model, const urdf::Model *const urdf_model, std::vector< transmission_interface::TransmissionInfo > transmissions)
geometry_msgs::Twist twist_
bool getParam(const std::string &key, std::string &s) const
bool enableMotors(bool enable)
std::string base_link_frame_
bool enableMotorsCallback(hector_uav_msgs::EnableMotors::Request &req, hector_uav_msgs::EnableMotors::Response &res)
WrenchCommandHandlePtr wrench_output_
void registerAccel(geometry_msgs::Accel *accel)
PLUGINLIB_EXPORT_CLASS(transmission_interface::BiDirectionalEffortJointInterfaceProvider, transmission_interface::RequisiteProvider)
void registerSensorImu(sensor_msgs::Imu *imu)
gazebo::math::Vector3 gz_acceleration_
QuadrotorInterface interface_
gazebo::math::Vector3 gz_angular_acceleration_
gazebo::math::Vector3 gz_angular_velocity_