45 std::map<std::string, OdomSource> odom_options;
46 odom_options[
"encoder"] =
ENCODER;
47 odom_options[
"world"] =
WORLD;
51 this->mode_map_[
"tractor"] =
TRACTOR;
52 this->mode_map_[
"balance"] =
BALANCE;
55 if (!this->
sdf_->HasElement(
"wheelSeparation") || !this->
sdf_->HasElement(
"wheelRadius") )
57 ROS_ERROR(
"RsvBalancePlugin - Missing <wheelSeparation> or <wheelDiameter>, Aborting");
71 if (this->update_rate_ > 0.0)
77 ROS_WARN(
"RsvBalancePlugin - Update rate < 0. Update period set to: 0.1. ");
90 so = ros::SubscribeOptions::create<std_msgs::Float64>(
"tilt_equilibrium", 5,
98 ROS_INFO(
"%s: Advertise odom on %s !", this->
gazebo_ros_->info(), this->odom_topic_.c_str());
113 ao = ros::AdvertiseServiceOptions::create<rsv_balance_msgs::SetInput>(
"set_input",
119 ao = ros::AdvertiseServiceOptions::create<std_srvs::Empty>(
"reset_override",
125 ao = ros::AdvertiseServiceOptions::create<std_srvs::Empty>(
"reset_odom",
169 case rsv_balance_msgs::SetModeRequest::PARK:
173 case rsv_balance_msgs::SetModeRequest::TRACTOR:
177 case rsv_balance_msgs::SetModeRequest::BALANCE:
240 math::Pose pose = this->
parent_->GetWorldPose();
241 math::Vector3 veul = this->
parent_->GetRelativeAngularVel();
252 math::Pose pose = this->
parent_->GetWorldPose();
263 double ang_velocity_left = -this->
joints_[
LEFT]->GetVelocity(0);
264 double ang_velocity_right = this->
joints_[
RIGHT]->GetVelocity(0);
271 math::Pose pose = this->
parent_->GetWorldPose();
272 math::Vector3 velocity_linear = this->
parent_->GetRelativeLinearVel();
273 math::Vector3 velocity_angular = this->
parent_->GetRelativeAngularVel();
278 this->
odom_.pose.pose.position.x = pose.pos[0];
279 this->
odom_.pose.pose.position.y = pose.pos[1];
280 this->
odom_.pose.pose.position.z = pose.pos[2];
284 this->
odom_.pose.pose.orientation.x = pose.rot.x;
285 this->
odom_.pose.pose.orientation.y = pose.rot.y;
286 this->
odom_.pose.pose.orientation.z = pose.rot.z;
287 this->
odom_.pose.pose.orientation.w = pose.rot.w;
288 this->
odom_.twist.twist.linear.x = velocity_linear[0];
289 this->
odom_.twist.twist.linear.y = velocity_linear[1];
290 this->
odom_.twist.twist.angular.z = velocity_angular.z;
294 ROS_WARN(
"%s - Odometry from other sources not yet supported.", this->
gazebo_ros_->info());
309 this->
odom_.pose.covariance[0] = 0.00001;
310 this->
odom_.pose.covariance[7] = 0.00001;
311 this->
odom_.pose.covariance[14] = 1000000000000.0;
312 this->
odom_.pose.covariance[21] = 1000000000000.0;
313 this->
odom_.pose.covariance[28] = 1000000000000.0;
314 this->
odom_.pose.covariance[35] = 0.001;
316 this->
odom_.header.stamp = current_time;
317 this->
odom_.header.frame_id = odom_frame;
318 this->
odom_.child_frame_id = base_frame;
327 this->odom_.pose.pose.position.y,
328 this->odom_.pose.pose.position.z);
329 qt =
tf::Quaternion(this->
odom_.pose.pose.orientation.x, this->odom_.pose.pose.orientation.y,
330 this->odom_.pose.pose.orientation.z, this->odom_.pose.pose.orientation.w);
344 sensor_msgs::JointState joint_state;
345 joint_state.header.stamp = current_time;
346 joint_state.name.resize(
joints_.size());
347 joint_state.position.resize(
joints_.size());
349 for (
int i = 0; i < 2; i++)
351 physics::JointPtr joint = this->
joints_[i];
352 math::Angle angle = joint->GetAngle(0);
353 joint_state.name[i] = joint->GetName();
354 joint_state.position[i] = angle.Radian();
380 common::Time current_time = this->
parent_->GetWorld()->GetSimTime();
381 double seconds_since_last_update = (current_time - this->
last_update_time_).Double();
447 static const double timeout = 0.01;
std::string base_frame_id_
double publish_diagnostics_rate_
std::map< std::string, Mode > mode_map_
void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
bool setMode(rsv_balance_msgs::SetMode::Request &req)
Sets platform operating mode.
std::string odom_frame_id_
void publish(const boost::shared_ptr< M > &message) const
boost::thread callback_queue_thread_
ros::ServiceServer reset_odom_server_
void updateOdometry()
Updates odometry, from Gazebo world or from encoders.
void stepControl(double dt, const double(&x_desired)[4], const double(&y_fbk)[4])
void resetOdometry()
Resets odometry by adding offset to WORLD odometry, and resetting odometry values.
ros::ServiceServer set_input_server_
ros::Subscriber cmd_tilt_subscriber_
ros::Publisher state_publisher_
ros::ServiceServer reset_override_server_
ros::Subscriber cmd_vel_subscriber_
bool resetOverride(std_srvs::Empty::Request &req)
Just exposes service. Not used in simulation.
void Reset()
Called when Gazebo resets world.
void publishOdometry()
Publishes odometry and desired tfs.
ros::Publisher odometry_publisher_
math::Vector3 odom_offset_rot_
event::ConnectionPtr update_connection_
ros::ServiceServer set_mode_server_
bool setInput(rsv_balance_msgs::SetInput::Request &req)
Just exposes service. Not used in simulation.
ros::CallbackQueue queue_
void publishWheelJointState()
Publishes wheel joint_states.
void resetVariables()
Resets simulation variables.
void cmdTiltCallback(const std_msgs::Float64::ConstPtr &cmd_tilt)
Callback to cmd_tilt.
ros::Publisher joint_state_publisher_
physics::ModelPtr parent_
bool publish_wheel_joint_
math::Vector3 odom_offset_pos_
common::Time last_update_time_
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
std::string command_topic_
void updateIMU()
Gets pitch angle values directly from Gazebo world.
std::vector< physics::JointPtr > joints_
double publish_state_rate_
balance_control::BalanceControl state_control_
virtual void UpdateChild()
Gazebo step update.
void cmdVelCallback(const geometry_msgs::Twist::ConstPtr &cmd_msg)
Callback to cmd_vel.
boost::shared_ptr< void > VoidPtr
bool resetOdom(std_srvs::Empty::Request &req)
Service to reset odometry.
boost::shared_ptr< tf::TransformBroadcaster > transform_broadcaster_
boost::shared_ptr< GazeboRos > GazeboRosPtr
virtual void FiniChild()
Called by gazebo upon exiting.