Skip to content

Commit

Permalink
Merge branch 'master' into rename_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ahcorde authored Jun 10, 2024
2 parents 5455fe0 + 5d2d5eb commit 18eac5e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gz_ros2_control/src/gz_ros2_control_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ GazeboSimROS2ControlPlugin::GazeboSimROS2ControlPlugin()
GazeboSimROS2ControlPlugin::~GazeboSimROS2ControlPlugin()
{
// Stop controller manager thread
if (!this->dataPtr->controller_manager_) {
return;
}
this->dataPtr->executor_->remove_node(this->dataPtr->controller_manager_);
this->dataPtr->executor_->cancel();
this->dataPtr->thread_executor_spin_.join();
Expand Down Expand Up @@ -514,6 +517,9 @@ void GazeboSimROS2ControlPlugin::PreUpdate(
const sim::UpdateInfo & _info,
sim::EntityComponentManager & /*_ecm*/)
{
if (!this->dataPtr->controller_manager_) {
return;
}
static bool warned{false};
if (!warned) {
rclcpp::Duration gazebo_period(_info.dt);
Expand Down Expand Up @@ -548,6 +554,9 @@ void GazeboSimROS2ControlPlugin::PostUpdate(
const sim::UpdateInfo & _info,
const sim::EntityComponentManager & /*_ecm*/)
{
if (!this->dataPtr->controller_manager_) {
return;
}
// Get the simulation time and period
rclcpp::Time sim_time_ros(std::chrono::duration_cast<std::chrono::nanoseconds>(
_info.simTime).count(), RCL_ROS_TIME);
Expand Down
16 changes: 16 additions & 0 deletions gz_ros2_control/src/gz_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ bool GazeboSimSystem::initSim(
auto & joint_info = hardware_info.joints[j];
std::string joint_name = this->dataPtr->joints_[j].name = joint_info.name;

auto it_joint = enableJoints.find(joint_name);
if (it_joint == enableJoints.end()) {
RCLCPP_WARN_STREAM(
this->nh_->get_logger(), "Skipping joint in the URDF named '" << joint_name <<
"' which is not in the gazebo model.");
continue;
}

sim::Entity simjoint = enableJoints[joint_name];
this->dataPtr->joints_[j].sim_joint = simjoint;

Expand Down Expand Up @@ -501,6 +509,10 @@ hardware_interface::return_type GazeboSimSystem::read(
const rclcpp::Duration & /*period*/)
{
for (unsigned int i = 0; i < this->dataPtr->joints_.size(); ++i) {
if (this->dataPtr->joints_[i].sim_joint == sim::kNullEntity) {
continue;
}

// Get the joint velocity
const auto * jointVelocity =
this->dataPtr->ecm->Component<sim::components::JointVelocity>(
Expand Down Expand Up @@ -593,6 +605,10 @@ hardware_interface::return_type GazeboSimSystem::write(
const rclcpp::Duration & /*period*/)
{
for (unsigned int i = 0; i < this->dataPtr->joints_.size(); ++i) {
if (this->dataPtr->joints_[i].sim_joint == sim::kNullEntity) {
continue;
}

if (this->dataPtr->joints_[i].joint_control_method & VELOCITY) {
if (!this->dataPtr->ecm->Component<sim::components::JointVelocityCmd>(
this->dataPtr->joints_[i].sim_joint))
Expand Down

0 comments on commit 18eac5e

Please sign in to comment.