@@ -78,12 +78,13 @@ const
7878rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
7979SpeedScalingStateController::on_configure (const rclcpp_lifecycle::State & /* previous_state*/ )
8080{
81- try {
82- // TODO change subscriber to single value
83- joint_state_publisher_ = get_node ()->create_publisher <sensor_msgs::msg::JointState>(
84- " joint_states" , rclcpp::SystemDefaultsQoS ());
85-
86- } catch (const std::exception & e) {
81+ try
82+ {
83+ speed_scaling_state_publisher_ =
84+ get_node ()->create_publisher <std_msgs::msg::Float64>(" speed_scaling_factor" , rclcpp::SystemDefaultsQoS ());
85+ }
86+ catch (const std::exception& e)
87+ {
8788 // get_node() may throw, logging raw here
8889 fprintf (stderr, " Exception thrown during init stage with message: %s \n " , e.what ());
8990 return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR;
@@ -98,8 +99,6 @@ SpeedScalingStateController::on_activate(const rclcpp_lifecycle::State & /*previ
9899 return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR;
99100 }
100101
101- init_joint_state_msg ();
102-
103102 return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
104103}
105104
@@ -150,20 +149,9 @@ bool SpeedScalingStateController::init_joint_data()
150149 return true ;
151150}
152151
153- void SpeedScalingStateController::init_joint_state_msg ()
152+ double get_value (const std::unordered_map<std::string, std::unordered_map<std::string, double >>& map,
153+ const std::string& name, const std::string& interface_name)
154154{
155- const size_t num_joints = joint_names_.size ();
156-
157- // / @note joint_state_msg publishes position, velocity and effort for all joints,
158- // / with at least one of these interfaces, the rest are omitted from this message
159-
160- // default initialization for joint state message
161- joint_state_msg_.name = joint_names_;
162- joint_state_msg_.position .resize (num_joints, kUninitializedValue );
163- joint_state_msg_.velocity .resize (num_joints, kUninitializedValue );
164- joint_state_msg_.effort .resize (num_joints, kUninitializedValue );
165- }
166-
167155double get_value (
168156 const std::unordered_map<std::string, std::unordered_map<std::string, double >> & map,
169157 const std::string & name, const std::string & interface_name)
@@ -182,22 +170,18 @@ SpeedScalingStateController::update()
182170{
183171 for (const auto & state_interface : state_interfaces_) {
184172 name_if_value_mapping_[state_interface.get_name ()][state_interface.get_interface_name ()] =
185- state_interface.get_value ();
186- RCLCPP_DEBUG (
187- get_node ()->get_logger (), " %s/%s: %f\n " ,
188- state_interface.get_name ().c_str (),
189- state_interface.get_interface_name ().c_str (),
190- state_interface.get_value ());
173+ state_interface.get_value ();
174+ RCLCPP_DEBUG (get_node ()->get_logger (), " %s/%s: %f\n " , state_interface.get_name ().c_str (),
175+ state_interface.get_interface_name ().c_str (), state_interface.get_value ());
191176 }
192177
193- joint_state_msg_.header .stamp = node_->get_clock ()->now ();
194-
195- for (auto i = 0ul ; i < joint_names_.size (); ++i) {
196- std::cout << get_value (name_if_value_mapping_, joint_names_[i], " speed_scaling_factor" ) << std::endl;
178+ for (auto i = 0ul ; i < joint_names_.size (); ++i)
179+ {
180+ speed_scaling_state_msg_.data = get_value (name_if_value_mapping_, joint_names_[i], " speed_scaling_factor" );
197181 }
198182
199183 // publish
200- joint_state_publisher_ ->publish (joint_state_msg_ );
184+ speed_scaling_state_publisher_ ->publish (speed_scaling_state_msg_ );
201185
202186 return controller_interface::return_type::SUCCESS;
203187}
0 commit comments