30 #include <gazebo/common/Events.hh> 31 #include <gazebo/physics/physics.hh> 32 #include <gazebo/gazebo_config.h> 34 #include <sensor_msgs/JointState.h> 36 #if (GAZEBO_MAJOR_VERSION > 1) || (GAZEBO_MINOR_VERSION >= 2) 39 #define RADIAN GetAsRadian 44 GZ_REGISTER_MODEL_PLUGIN(ServoPlugin)
66 #if (GAZEBO_MAJOR_VERSION >= 8) 80 world = _model->GetWorld();
93 if (_sdf->HasElement(
"robotNamespace"))
robotNamespace = _sdf->Get<std::string>(
"robotNamespace");
94 if (_sdf->HasElement(
"topicName"))
topicName = _sdf->Get<std::string>(
"topicName");
95 if (_sdf->HasElement(
"jointStateName"))
jointStateName = _sdf->Get<std::string>(
"jointStateName");
96 if (_sdf->HasElement(
"firstServoName"))
servo[
FIRST].name = _sdf->Get<std::string>(
"firstServoName");
97 #if (GAZEBO_MAJOR_VERSION >= 8) 98 if (_sdf->HasElement(
"firstServoAxis"))
servo[
FIRST].axis = _sdf->Get<ignition::math::Vector3d>(
"firstServoAxis");
100 if (_sdf->HasElement(
"firstServoAxis"))
servo[
FIRST].axis = _sdf->Get<math::Vector3>(
"firstServoAxis");
102 if (_sdf->HasElement(
"secondServoName"))
servo[
SECOND].name = _sdf->Get<std::string>(
"secondServoName");
103 #if (GAZEBO_MAJOR_VERSION >= 8) 104 if (_sdf->HasElement(
"secondServoAxis"))
servo[
SECOND].axis = _sdf->Get<ignition::math::Vector3d>(
"secondServoAxis");
106 if (_sdf->HasElement(
"secondServoAxis"))
servo[
SECOND].axis = _sdf->Get<math::Vector3>(
"secondServoAxis");
108 if (_sdf->HasElement(
"thirdServoName"))
servo[
THIRD].name = _sdf->Get<std::string>(
"thirdServoName");
109 #if (GAZEBO_MAJOR_VERSION >= 8) 110 if (_sdf->HasElement(
"thirdServoAxis"))
servo[
THIRD].axis = _sdf->Get<ignition::math::Vector3d>(
"thirdServoAxis");
112 if (_sdf->HasElement(
"thirdServoAxis"))
servo[
THIRD].axis = _sdf->Get<math::Vector3>(
"thirdServoAxis");
114 if (_sdf->HasElement(
"proportionalControllerGain"))
proportionalControllerGain = _sdf->Get<
double>(
"proportionalControllerGain");
115 if (_sdf->HasElement(
"derivativeControllerGain"))
derivativeControllerGain = _sdf->Get<
double>(
"derivativeControllerGain");
116 if (_sdf->HasElement(
"maxVelocity"))
maximumVelocity = _sdf->Get<
double>(
"maxVelocity");
117 if (_sdf->HasElement(
"torque"))
maximumTorque = _sdf->Get<
double>(
"torque");
119 double controlRate = 0.0;
120 if (_sdf->HasElement(
"controlRate")) controlRate = _sdf->Get<
double>(
"controlRate");
128 gzthrow(
"The controller couldn't get first joint");
139 gzthrow(
"The controller couldn't get second joint, but third joint was loaded");
192 #if (GAZEBO_MAJOR_VERSION >= 8) 205 common::Time stepTime;
206 #if (GAZEBO_MAJOR_VERSION >= 8) 215 #if (GAZEBO_MAJOR_VERSION >= 8) 232 #if (GAZEBO_MAJOR_VERSION > 4) 250 #if (GAZEBO_MAJOR_VERSION > 4) 273 boost::mutex::scoped_lock lock(
mutex);
276 geometry_msgs::QuaternionStamped *default_cmd =
new geometry_msgs::QuaternionStamped;
277 default_cmd->header.frame_id =
"base_stabilized";
278 default_cmd->quaternion.w = 1;
296 #if (GAZEBO_MAJOR_VERSION >= 8) 306 double actualAngle[3] = {0.0, 0.0, 0.0};
307 double actualVel[3] = {0.0, 0.0, 0.0};
317 #if (GAZEBO_MAJOR_VERSION >= 8) 327 #if (GAZEBO_MAJOR_VERSION >= 8) 340 #if (GAZEBO_MAJOR_VERSION >= 8) 350 #if (GAZEBO_MAJOR_VERSION >= 8) 363 #if (GAZEBO_MAJOR_VERSION >= 8) 374 gzthrow(
"Something went wrong. The count of servos is greater than 3");
380 #if (GAZEBO_MAJOR_VERSION >= 8) 381 temp[0] = 2*(rotation_.X()*rotation_.Y() + rotation_.W()*rotation_.Z());
382 temp[1] = rotation_.W()*rotation_.W() + rotation_.X()*rotation_.X() - rotation_.Y()*rotation_.Y() - rotation_.Z()*rotation_.Z();
383 temp[2] = -2*(rotation_.X()*rotation_.Z() - rotation_.W()*rotation_.Y());
384 temp[3] = 2*(rotation_.Y()*rotation_.Z() + rotation_.W()*rotation_.X());
385 temp[4] = rotation_.W()*rotation_.W() - rotation_.X()*rotation_.X() - rotation_.Y()*rotation_.Y() + rotation_.Z()*rotation_.Z();
387 temp[0] = 2*(rotation_.x*rotation_.y + rotation_.w*rotation_.z);
388 temp[1] = rotation_.w*rotation_.w + rotation_.x*rotation_.x - rotation_.y*rotation_.y - rotation_.z*rotation_.z;
389 temp[2] = -2*(rotation_.x*rotation_.z - rotation_.w*rotation_.y);
390 temp[3] = 2*(rotation_.y*rotation_.z + rotation_.w*rotation_.x);
391 temp[4] = rotation_.w*rotation_.w - rotation_.x*rotation_.x - rotation_.y*rotation_.y + rotation_.z*rotation_.z;
396 #if (GAZEBO_MAJOR_VERSION >= 8) 397 temp[0] = -2*(rotation_.Y()*rotation_.Z() - rotation_.W()*rotation_.X());
398 temp[1] = rotation_.W()*rotation_.W() - rotation_.X()*rotation_.X() - rotation_.Y()*rotation_.Y() + rotation_.Z()*rotation_.Z();
399 temp[2] = 2*(rotation_.X()*rotation_.Z() + rotation_.W()*rotation_.Y());
400 temp[3] = -2*(rotation_.X()*rotation_.Y() - rotation_.W()*rotation_.Z());
401 temp[4] = rotation_.W()*rotation_.W() + rotation_.X()*rotation_.X() - rotation_.Y()*rotation_.Y() - rotation_.Z()*rotation_.Z();
403 temp[0] = -2*(rotation_.y*rotation_.z - rotation_.w*rotation_.x);
404 temp[1] = rotation_.w*rotation_.w - rotation_.x*rotation_.x - rotation_.y*rotation_.y + rotation_.z*rotation_.z;
405 temp[2] = 2*(rotation_.x*rotation_.z + rotation_.w*rotation_.y);
406 temp[3] = -2*(rotation_.x*rotation_.y - rotation_.w*rotation_.z);
407 temp[4] = rotation_.w*rotation_.w + rotation_.x*rotation_.x - rotation_.y*rotation_.y - rotation_.z*rotation_.z;
412 gzthrow(
"joint order " <<
rotationConv <<
" not supported");
416 desAngle[0] = atan2(temp[0], temp[1]);
417 desAngle[1] = asin(temp[2]);
418 desAngle[2] = atan2(temp[3], temp[4]);
420 #if (GAZEBO_MAJOR_VERSION >= 8) 431 #if (GAZEBO_MAJOR_VERSION >= 8) 442 #if (GAZEBO_MAJOR_VERSION >= 8) 461 boost::mutex::scoped_lock lock(
mutex);
469 #if (GAZEBO_MAJOR_VERSION >= 8) 484 #if (GAZEBO_MAJOR_VERSION >= 8)
void publish(const boost::shared_ptr< M > &message) const
void CalculateVelocities()
common::Time prevUpdateTime
unsigned int countOfServos
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL bool isInitialized()
event::ConnectionPtr updateConnection
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Publisher jointStatePub_
TFSIMD_FORCE_INLINE const tfScalar & getW() const
tf::TransformListener * transform_listener_
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
#define ROS_DEBUG_NAMED(name,...)
math::Quaternion rotation_
void publish_joint_states()
float proportionalControllerGain
unsigned int orderOfAxes[3]
ros::CallbackQueue queue_
void cmdCallback(const geometry_msgs::QuaternionStamped::ConstPtr &cmd_msg)
physics::WorldPtr world
The parent World.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
unsigned int rotationConv
common::Time controlPeriod
std::string jointStateName
geometry_msgs::QuaternionStamped::ConstPtr current_cmd
std::string robotNamespace
float derivativeControllerGain
ros::NodeHandle * rosnode_
boost::shared_ptr< void > VoidPtr
struct gazebo::ServoPlugin::Servo servo[3]
sensor_msgs::JointState joint_state