41 nh_(NULL), spinner_thread_(NULL), tf_broadcaster_(NULL), first_update_(true), fast_(true)
47 mode_ = mobility_base_core_msgs::Mode::MODE_DISABLED;
93 std::string model_name = sdf->GetParent()->Get<std::string>(
"name");
94 gzdbg <<
"MobilityBasePlugin loaded for model '" << model_name <<
"'\n";
97 if (sdf->HasElement(
"fast")) {
98 std::string comp =
"true";
99 fast_ = comp.compare(sdf->GetElement(
"fast")->Get<std::string>()) ?
false :
true;
101 if (sdf->HasElement(
"parent_frame_id")) {
103 if (sdf->HasElement(
"child_frame_id")) {
104 child_frame_id_ = sdf->GetElement(
"child_frame_id")->Get<std::string>();
120 for (
unsigned int i = 0; i <
NUM_WHEELS; i++) {
130 gzerr <<
"Failed to find joint '" << wheel <<
"' in the model\n";
136 std::stringstream ss;
137 ss << wheel <<
"_roller_" << j;
138 std::string roller = ss.str();
147 gzerr <<
"Failed to find joint '" << roller <<
"' in the model\n";
191 pmq_imu_is_calibrated_->push(msg, pub_imu_is_calibrated_);
201 const common::Time gstamp =
world_->GetSimTime();
202 const ros::Time rstamp(gstamp.sec, gstamp.nsec);
206 std_msgs::Header header;
207 header.stamp = rstamp;
211 math::Vector3 linear_vel;
212 math::Vector3 angular_vel;
213 math::Vector3 linear_accel;
214 math::Vector3 angular_pos;
215 math::Quaternion orientation;
216 math::Vector3 position;
218 linear_vel =
model_->GetRelativeLinearVel();
219 angular_vel =
model_->GetRelativeAngularVel();
220 linear_accel =
model_->GetRelativeLinearAccel();
221 angular_pos =
model_->GetWorldPose().rot.GetAsEuler();
222 orientation =
model_->GetWorldPose().rot;
223 position =
model_->GetWorldPose().pos;
225 const math::Vector3 fb_vel(linear_vel.x, linear_vel.y, angular_vel.z);
238 math::Vector3
cmd = math::Vector3::Zero;
239 mobility_base_core_msgs::Mode::_mode_type mode = mobility_base_core_msgs::Mode::MODE_TIMEOUT;
246 mode = mobility_base_core_msgs::Mode::MODE_VELOCITY;
251 mode = mobility_base_core_msgs::Mode::MODE_VELOCITY_RAW;
257 math::Vector3 accel_limit;
259 case mobility_base_core_msgs::Mode::MODE_VELOCITY:
264 case mobility_base_core_msgs::Mode::MODE_VELOCITY_RAW:
265 case mobility_base_core_msgs::Mode::MODE_TIMEOUT:
300 math::Vector3 linear_vel = orientation.RotateVector(math::Vector3(temp.x, temp.y, 0.0));
308 for (
unsigned int i = 0; i <
NUM_WHEELS; i++) {
310 #if GAZEBO_MAJOR_VERSION >= 7 322 geometry_msgs::TwistStamped msg_twist;
323 msg_twist.header = header;
324 msg_twist.twist.linear.x = linear_vel.x;
325 msg_twist.twist.linear.y = linear_vel.y;
326 msg_twist.twist.linear.z = linear_vel.z;
327 msg_twist.twist.angular.x = angular_vel.x;
328 msg_twist.twist.angular.y = angular_vel.y;
329 msg_twist.twist.angular.z = angular_vel.z;
333 geometry_msgs::WrenchStamped msg_wrench;
334 msg_wrench.header = header;
335 msg_wrench.wrench.force.x = 0.0;
336 msg_wrench.wrench.force.y = 0.0;
337 msg_wrench.wrench.torque.z = 0.0;
344 for (
unsigned int i = 0; i <
NUM_WHEELS; i++) {
361 geometry_msgs::TransformStamped transform;
362 transform.header.stamp = rstamp;
365 transform.transform.translation.x = position.x;
366 transform.transform.translation.y = position.y;
367 transform.transform.translation.z = position.z;
368 transform.transform.rotation.w = orientation.w;
369 transform.transform.rotation.x = orientation.x;
370 transform.transform.rotation.y = orientation.y;
371 transform.transform.rotation.z = orientation.z;
381 sensor_msgs::Imu msg_imu;
382 msg_imu.header = header;
383 msg_imu.linear_acceleration.x = linear_accel.x;
384 msg_imu.linear_acceleration.y = linear_accel.y;
385 msg_imu.linear_acceleration.z = linear_accel.z;
386 msg_imu.orientation_covariance[0] = -1;
387 msg_imu.angular_velocity.x = angular_vel.x;
388 msg_imu.angular_velocity.y = angular_vel.y;
389 msg_imu.angular_velocity.z = angular_vel.z;
390 msg_imu.angular_velocity_covariance[0] = -1;
393 sensor_msgs::MagneticField msg_mag;
394 msg_mag.header = header;
395 msg_mag.magnetic_field.x = 0.0;
396 msg_mag.magnetic_field.y = 0.0;
397 msg_mag.magnetic_field.z = 0.0;
398 msg_mag.magnetic_field_covariance[0] = -1;
405 geometry_msgs::TwistStamped
msg;
413 mobility_base_core_msgs::BumperState
msg;
457 mobility_base_core_msgs::Mode
msg;
459 msg.header.stamp = stamp;
static _CONST double PUB_FREQ_BUMPERS
void push(T &msg, ros::Publisher &pub)
void recvCmdVel(const geometry_msgs::Twist::ConstPtr &msg)
ros::Publisher pub_bumper_states_
physics::JointPtr joint_wheels_[NUM_WHEELS]
ros::Publisher pub_imu_is_calibrated_
common::Time cmd_vel_stamp_
static _CONST double GAIN_X
ros::Publisher pub_imu_data_
std::string child_frame_id_
physics::JointPtr joint_rollers_[NUM_WHEELS][NUM_ROLLERS]
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
PubQueue< geometry_msgs::TwistStamped >::Ptr pmq_joystick_
math::Vector3 cmd_vel_history_
boost::mutex cmd_vel_raw_mutex_
ros::Publisher pub_twist_
static _CONST unsigned int NUM_ROLLERS
void recvCmdVelRaw(const geometry_msgs::Twist::ConstPtr &msg)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Subscriber sub_cmd_vel_
static _CONST double ACCEL_INSTANT_VXY
void Load(physics::ModelPtr _parent, sdf::ElementPtr sdf)
static _CONST double GAIN_Y
static _CONST double ACCEL_LIMIT_FAST_WZ
static _CONST double ACCEL_INSTANT_WZ
common::Time previous_stamp_
event::ConnectionPtr update_connection_
common::Time stamp_joystick_
static _CONST double PUB_FREQ_JOYSTICK
PubQueue< std_msgs::Bool >::Ptr pmq_imu_is_calibrated_
physics::LinkPtr link_base_footprint_
common::Time stamp_bumpers_
static _CONST double ACCEL_LIMIT_SLOW_WZ
math::Vector3 cmd_vel_raw_
static _CONST double ACCEL_LIMIT_SLOW_VXY
ros::Publisher pub_joystick_
static _CONST double ACCEL_LIMIT_FAST_VXY
static bool omniSaturate(double limit, double speeds[4])
static _CONST double CMD_TIMEOUT
ros::Publisher pub_joint_states_
void omniFromCartesian(double vx, double vy, double wz, double w[4]) const
common::Time cmd_vel_raw_stamp_
PubQueue< sensor_msgs::MagneticField >::Ptr pmq_imu_mag_
static _CONST double WHEEL_RADIUS
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
boost::thread * spinner_thread_
boost::shared_ptr< PubQueue< T > > addPub()
sensor_msgs::JointState joint_state_rollers_
static _CONST double PUB_FREQ_IMU
PubQueue< mobility_base_core_msgs::BumperState >::Ptr pmq_bumper_states_
PubQueue< sensor_msgs::Imu >::Ptr pmq_imu_data_
PubQueue< sensor_msgs::JointState >::Ptr pmq_joint_states_
boost::mutex cmd_vel_mutex_
void omniToCartesian(const double w[4], double *vx, double *vy, double *wz) const
static _CONST double TORQUE_MAX_GLOBAL
static _CONST double WHEEL_BASE_LENGTH
static _CONST double PUB_FREQ_MODE
static _CONST double GAIN_Z
PubQueue< geometry_msgs::TwistStamped >::Ptr pmq_twist_
static _CONST unsigned int NUM_WHEELS
ros::Subscriber sub_cmd_vel_raw_
void startServiceThread()
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
static _CONST double WHEEL_BASE_WIDTH
mobility_base_core_msgs::Mode::_mode_type mode_
ros::Publisher pub_wrench_
ROSCPP_DECL void spinOnce()
common::Time stamp_vehicle_
virtual void UpdateChild(const common::UpdateInfo &_info)
std::string parent_frame_id_
void publishMode(const ros::Time &stamp)
tf::TransformBroadcaster * tf_broadcaster_
ros::Publisher pub_imu_mag_
sensor_msgs::JointState joint_state_wheels_
PubQueue< geometry_msgs::WrenchStamped >::Ptr pmq_wrench_
static _CONST double RADIANS_PER_SECOND_MAX
PubQueue< mobility_base_core_msgs::Mode >::Ptr pmq_mode_
static _CONST double PUB_FREQ_VEHICLE
static double limitDelta(double input, double previous, double limit)