83 double force = this->
joint->GetForce(0);
93 this->
model->GetJointController()->Reset();
98 this->
model->GetJointController()->SetForce(
99 this->
joint->GetScopedName(),
110 this->
model->GetJointController()->Reset();
115 this->
model->GetJointController()->SetVelocityTarget(
116 this->
joint->GetScopedName(),
127 this->
model->GetJointController()->Reset();
132 this->
model->GetJointController()->SetPositionTarget(
133 this->
joint->GetScopedName(),
141 if ((!_msg->position.empty()) && (_msg->position.size() ==
NUMJOINTS))
146 if ((!_msg->velocity.empty()) && (_msg->velocity.size() ==
NUMJOINTS))
151 if ((!_msg->effort.empty()) && (_msg->effort.size() ==
NUMJOINTS))
160 static const double timeout = 0.000001;
170 ros::Rate loop_rate(10);
173 std_msgs::Float64 joint_force_msg;
185 if (!ros::isInitialized())
193 ros::init_options::NoSigintHandler
197 this->
rosNode.reset(
new ros::NodeHandle(
"gazebo_client"));
199 ros::SubscribeOptions joint_state_so =
200 ros::SubscribeOptions::create<sensor_msgs::JointState>(
201 "/" + this->
model->GetName() +
"/joint_state_cmd",
205 &this->rosProcessQueue
208 ros::AdvertiseOptions joint_force_ao =
209 ros::AdvertiseOptions::create<std_msgs::Float64>(
210 "/" + this->
model->GetName() +
"/joint_force",
212 ros::SubscriberStatusCallback(),
213 ros::SubscriberStatusCallback(),
215 &this->rosPublishQueue
238 this->
model->GetJointController()->SetVelocityPID(
239 this->
joint->GetScopedName(),
240 common::PID(this->vel_p_gain, this->vel_i_gain, this->vel_d_gain)
243 this->
model->GetJointController()->SetPositionPID(
244 this->
joint->GetScopedName(),
245 common::PID(this->pos_p_gain, this->pos_i_gain, this->pos_d_gain)
253 this->
model->GetJointController()->SetJointPosition(
254 this->
joint->GetScopedName(),
259 this->
model->GetJointController()->SetPositionTarget(
260 this->
joint->GetScopedName(),
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
The Load function is called by Gazebo when the plugin is inserted into simulation.
void SetJointPosition(const double &_pos)
Set the position of the joint.
std::thread rosPublishQueueThread
Thread running the rosPublishQueue.
void OnJointStateMsg(const sensor_msgs::JointStateConstPtr &_msg)
The OnJointStateMsg function handles an incoming joint state message from ROS.
std::string model_name
Model name.
ros::Publisher jointForcePub
ROS Joint Force (Torque) Publisher.
double pos_d_gain
Position D-gain.
void SetJointVelocity(const double &_vel)
Set the velocity of the joint.
PendulumPlugin()
Constructor.
double vel_i_gain
Velocity I-gain.
double vel_d_gain
Velocity D-gain.
double pos_i_gain
Position I-gain.
void InitJointController()
The InitJointControllers function is called to setup joint PID controllers.
physics::ModelPtr model
Pointer to the model.
void SetJointForce(const double &_force)
Apply force at a specific joint.
physics::JointPtr joint
Pointers to the joint.
double pos_p_gain
Position P-gain.
ros::Subscriber jointStateSub
ROS Joint State Subscriber.
double GetJointForce()
Get currently applied force at the joint.
std::unique_ptr< ros::NodeHandle > rosNode
Node used for ROS transport.
std::thread rosProcessQueueThread
Thread running the rosProcessQueue.
void InitRos()
The initRos function is called to initialize ROS.
ControlMode controlMode
Control mode indicator { position = 1, velocity = 2, torque = 3 }.
ros::CallbackQueue rosProcessQueue
ROS callbackque that helps process messages.
void InitRosQueueThreads()
The InitRosQueueThreads function is called to initialize the ROS Publish and Process Queue Threads.
void ProcessQueueThread()
The ProcessQueueThread function is a ROS helper function that processes messages.
void InitJointConfiguration()
The InitJointConfiguration function is called to initialize the desired joint configuration.
double vel_p_gain
Velocity P-gain.
void PublishQueueThread()
The PublishQueueThread function is a ROS helper function that publish state messages.
virtual ~PendulumPlugin()
Destructor.
static constexpr unsigned int NUMJOINTS
Fixed variable for num joints.
double degToRad(const double &_deg)
The degToRad function converts degrees to radians.