Skip to content

Commit c1c5ba4

Browse files
committed
modify kinematics plugin to use SetWorldPose, SetWorldTwist instaed of get/set_model_state
1 parent 5636017 commit c1c5ba4

2 files changed

Lines changed: 29 additions & 15 deletions

File tree

kinematics_ros_plugins/include/kinematics_ros_plugins/KinematicsROSPlugin.hh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ namespace kinematics_ros
131131
/// \brief ROS helper function that processes messages
132132
private: void commandSubThread();
133133

134-
/// \brief ROS Publishers to gazebo_msgs topic
135-
private: std::map<std::string, ros::ServiceClient> commandPublisher;
134+
// /// \brief ROS Publishers to gazebo_msgs topic
135+
// private: std::map<std::string, ros::ServiceClient> commandPublisher;
136136

137-
/// \brief ROS Subscriber from gazebo topic
138-
private: std::map<std::string, ros::ServiceClient> stateSubscriber;
137+
// /// \brief ROS Subscriber from gazebo topic
138+
// private: std::map<std::string, ros::ServiceClient> stateSubscriber;
139139

140140
/// \brief update ocean current
141141
protected: virtual void applyOceanCurrent();

kinematics_ros_plugins/src/KinematicsROSPlugin.cc

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ void KinematicsROSPlugin::Load(gazebo::physics::ModelPtr _model,
220220
this->prev_pitch = 0.0;
221221
this->prev_yaw = 0.0;
222222
this->prev_motorPower = 0.0;
223+
this->modelVel = ignition::math::Vector3d(0.0, 0.0, 0.0);
223224

224225
// Free surface detection
225226
this->buoyancyFlag = true; // Initialize buoyancy engine
@@ -311,18 +312,15 @@ void KinematicsROSPlugin::updateModelState()
311312
model_state_msg.request.model_name = this->model->GetName();
312313
model_state_msg.request.relative_entity_name = "world";
313314
// this->stateSubscriber["Model"].call(model_state_msg);
314-
315-
316-
// ros::NodeHandle n;
317-
// ros::ServiceClient client = n.serviceClient<gazebo_msgs::GetModelState>("/gazebo/get_model_state", true);
318-
// client.waitForExistence();
319-
// client.call(model_state_msg);
320-
// client.shutdown();
321-
// n.shutdown();
322-
323315
this->modelState.model_name = this->model->GetName();
324-
this->modelState.pose = model_state_msg.response.pose;
325-
this->modelState.twist = model_state_msg.response.twist;
316+
// this->modelState.pose = model_state_msg.response.pose;
317+
this->modelState.pose.position.x = this->model->WorldPose().Pos().X();
318+
this->modelState.pose.position.y = this->model->WorldPose().Pos().Y();
319+
this->modelState.pose.position.z = this->model->WorldPose().Pos().Z();
320+
this->modelState.pose.orientation.x = this->model->WorldPose().Rot().X();
321+
this->modelState.pose.orientation.y = this->model->WorldPose().Rot().Y();
322+
this->modelState.pose.orientation.z = this->model->WorldPose().Rot().Z();
323+
this->modelState.pose.orientation.w = this->model->WorldPose().Rot().W();
326324
}
327325

328326
/////////////////////////////////////////////////
@@ -547,6 +545,21 @@ void KinematicsROSPlugin::ConveyKinematicsCommands(
547545
cmd_msg.request.model_state.twist.linear.z = -v_thrust*tan(target_pitch);
548546
}
549547
// this->commandPublisher["Model"].call(cmd_msg);
548+
ignition::math::Pose3d targetPose;
549+
targetPose.Pos() = this->model->WorldPose().Pos();
550+
targetPose.Rot().X() = cmd_msg.request.model_state.pose.orientation.x;
551+
targetPose.Rot().Y() = cmd_msg.request.model_state.pose.orientation.y;
552+
targetPose.Rot().Z() = cmd_msg.request.model_state.pose.orientation.z;
553+
targetPose.Rot().W() = cmd_msg.request.model_state.pose.orientation.w;
554+
this->model->SetWorldPose(targetPose);
555+
556+
ignition::math::v4::Vector3d targetLinearTwist;
557+
targetLinearTwist.X() = cmd_msg.request.model_state.twist.linear.x;
558+
targetLinearTwist.Y() = cmd_msg.request.model_state.twist.linear.y;
559+
targetLinearTwist.Z() = cmd_msg.request.model_state.twist.linear.z;
560+
ignition::math::v4::Vector3d targetAngularTwist(0.0, 0.0, 0.0);
561+
this->model->SetWorldTwist(targetLinearTwist, targetAngularTwist);
562+
550563
this->modelState = cmd_msg.request.model_state;
551564

552565
// Save model velocity right after commend published
@@ -781,6 +794,7 @@ void KinematicsROSPlugin::CheckSubmergence()
781794
this->link->SetLinearVel(ignition::math::Vector3d(0.0, 0.0, 0.0));
782795
this->link->ResetPhysicsStates();
783796
}
797+
gzmsg << this->model->GetName() << " : " << "surface detected" << std::endl;
784798
}
785799
}
786800

0 commit comments

Comments
 (0)