Skip to content

Commit 499ce01

Browse files
committed
Optional robot state initialization
1 parent 0f9cd01 commit 499ce01

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

include/ros_control_boilerplate/generic_hw_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class GenericHWInterface : public hardware_interface::RobotHW
180180

181181
// Configuration
182182
std::vector<std::string> joint_names_;
183+
std::vector<double> initial_state_;
183184
std::size_t num_joints_;
184185
urdf::Model* urdf_model_;
185186

src/generic_hw_interface.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ GenericHWInterface::GenericHWInterface(const ros::NodeHandle& nh, urdf::Model* u
5858
nh_, "hardware_interface"); // TODO(davetcoleman): change the namespace to "generic_hw_interface" aka name_
5959
std::size_t error = 0;
6060
error += !rosparam_shortcuts::get(name_, rpnh, "joints", joint_names_);
61+
62+
if (rpnh.hasParam("initial_state"))
63+
{
64+
error += !rosparam_shortcuts::get(name_, rpnh, "initial_state", initial_state_);
65+
66+
if (initial_state_.size() != joint_names_.size())
67+
ROS_WARN("skipping initial_state, does not match joints size");
68+
}
69+
6170
rosparam_shortcuts::shutdownIfError(name_, error);
6271
}
6372

@@ -81,6 +90,13 @@ void GenericHWInterface::init()
8190
joint_velocity_limits_.resize(num_joints_, 0.0);
8291
joint_effort_limits_.resize(num_joints_, 0.0);
8392

93+
// Initialize robot state
94+
if (initial_state_.size() != num_joints_)
95+
initial_state_.resize(joint_names_.size(), 0.0);
96+
97+
for (std::size_t i = 0; i < num_joints_; ++i)
98+
joint_position_[i] = initial_state_[i];
99+
84100
// Initialize interfaces for each joint
85101
for (std::size_t joint_id = 0; joint_id < num_joints_; ++joint_id)
86102
{

0 commit comments

Comments
 (0)