@@ -37,25 +37,28 @@ class TrajectoryControllerBase
3737
3838 /* *
3939 * @brief initialize the controller plugin.
40- * declare parameters
4140 * @param node the node handle to use for parameter handling
4241 * @param map_cmd_to_joints a mapping from the joint names in the trajectory messages to the
4342 * command joints
4443 */
45- virtual bool initialize (
46- rclcpp_lifecycle::LifecycleNode::SharedPtr node, std::vector<size_t > map_cmd_to_joints) = 0;
44+ bool initialize (
45+ rclcpp_lifecycle::LifecycleNode::SharedPtr node, std::vector<size_t > map_cmd_to_joints)
46+ {
47+ node_ = node;
48+ map_cmd_to_joints_ = map_cmd_to_joints;
49+ logger_ = this ->set_logger ();
50+ return on_initialize ();
51+ };
4752
4853 /* *
4954 * @brief configure the controller plugin.
50- * parse read-only parameters, pre-allocate memory for the controller
5155 */
52- virtual bool configure () = 0;
56+ bool configure () { return on_configure (); }
5357
5458 /* *
5559 * @brief activate the controller plugin.
56- * parse parameters
5760 */
58- virtual bool activate () = 0;
61+ bool activate () { return on_activate (); }
5962
6063 /* *
6164 * @brief compute the control law for the given trajectory
@@ -64,15 +67,15 @@ class TrajectoryControllerBase
6467 * of the trajectory until it finishes
6568 *
6669 * this method is not virtual, any overrides won't be called by JTC. Instead, override
67- * compute_control_law_non_rt_impl for your implementation
70+ * on_compute_control_law_non_rt for your implementation
6871 *
6972 * @return true if the gains were computed, false otherwise
7073 */
7174 bool compute_control_law_non_rt (
7275 const std::shared_ptr<trajectory_msgs::msg::JointTrajectory> & trajectory)
7376 {
7477 rt_control_law_ready_.writeFromNonRT (false );
75- auto ret = compute_control_law_non_rt_impl (trajectory);
78+ auto ret = on_compute_control_law_non_rt (trajectory);
7679 rt_control_law_ready_.writeFromNonRT (true );
7780 return ret;
7881 }
@@ -83,7 +86,7 @@ class TrajectoryControllerBase
8386 * this method must finish quickly (within one controller-update rate)
8487 *
8588 * this method is not virtual, any overrides won't be called by JTC. Instead, override
86- * compute_control_law_rt_impl for your implementation
89+ * on_compute_control_law_rt for your implementation
8790 *
8891 * @return true if the gains were computed, false otherwise
8992 */
@@ -92,7 +95,7 @@ class TrajectoryControllerBase
9295 {
9396 // TODO(christophfroehlich): Need a lock-free write here
9497 rt_control_law_ready_.writeFromNonRT (false );
95- auto ret = compute_control_law_rt_impl (trajectory);
98+ auto ret = on_compute_control_law_rt (trajectory);
9699 rt_control_law_ready_.writeFromNonRT (true );
97100 return ret;
98101 }
@@ -145,22 +148,58 @@ class TrajectoryControllerBase
145148protected:
146149 // the node handle for parameter handling
147150 rclcpp_lifecycle::LifecycleNode::SharedPtr node_;
151+ // map from joints in the message to command joints
152+ std::vector<size_t > map_cmd_to_joints_;
148153 // Are we computing the control law or is it valid?
149154 realtime_tools::RealtimeBuffer<bool > rt_control_law_ready_;
150155
156+ /* *
157+ * @brief Get the logger for this plugin
158+ */
159+ rclcpp::Logger get_logger () const { return logger_; }
160+ /* *
161+ * @brief Get the logger for this plugin
162+ */
163+ virtual rclcpp::Logger set_logger () const = 0;
164+
151165 /* *
152166 * @brief compute the control law from the given trajectory (in the non-RT loop)
153167 * @return true if the gains were computed, false otherwise
154168 */
155- virtual bool compute_control_law_non_rt_impl (
169+ virtual bool on_compute_control_law_non_rt (
156170 const std::shared_ptr<trajectory_msgs::msg::JointTrajectory> & trajectory) = 0;
157171
158172 /* *
159173 * @brief compute the control law for a single point (in the RT loop)
160174 * @return true if the gains were computed, false otherwise
161175 */
162- virtual bool compute_control_law_rt_impl (
176+ virtual bool on_compute_control_law_rt (
163177 const std::shared_ptr<trajectory_msgs::msg::JointTrajectory> & trajectory) = 0;
178+
179+ /* *
180+ * @brief initialize the controller plugin.
181+ *
182+ * declare parameters
183+ */
184+ virtual bool on_initialize (void ) = 0;
185+
186+ /* *
187+ * @brief configure the controller plugin.
188+ *
189+ * parse read-only parameters, pre-allocate memory for the controller
190+ */
191+ virtual bool on_configure () = 0;
192+
193+ /* *
194+ * @brief activate the controller plugin.
195+ *
196+ * parse parameters
197+ */
198+ virtual bool on_activate () = 0;
199+
200+ private:
201+ // child logger for this plugin
202+ rclcpp::Logger logger_ = rclcpp::get_logger(" joint_trajectory_controller_plugins" );
164203};
165204
166205} // namespace joint_trajectory_controller_plugins
0 commit comments