-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f462d4
commit 020c820
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef JOYSTICK_DRIVER_H | ||
#define JOYSTICK_DRIVER_H | ||
|
||
#include <geometry_msgs/msg/twist_stamped.hpp> | ||
#include <rclcpp/publisher.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
#include <rclcpp_components/register_node_macro.hpp> | ||
|
||
namespace zero_cmd_vel_node { | ||
class ZeroCmdVelNode : public rclcpp::Node { | ||
public: | ||
explicit ZeroCmdVelNode(const rclcpp::NodeOptions &options); | ||
|
||
private: | ||
void publish_zero_cmd_vel(); | ||
std::shared_ptr<rclcpp::Publisher<geometry_msgs::msg::TwistStamped>> | ||
drivetrain_cmd_publisher; | ||
rclcpp::TimerBase::SharedPtr timer_; | ||
}; | ||
} // namespace zero_cmd_vel_node | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "zero_cmd_vel_node.hpp" | ||
|
||
namespace zero_cmd_vel_node { | ||
|
||
ZeroCmdVelNode::ZeroCmdVelNode(const rclcpp::NodeOptions &options) | ||
: rclcpp::Node("zero_cmd_vel_node", options) { | ||
declare_parameter("zero_cmd_vel_topic", "/zero_cmd_vel"); | ||
drivetrain_cmd_publisher = create_publisher<geometry_msgs::msg::TwistStamped>( | ||
get_parameter("zero_cmd_vel_topic").as_string(), | ||
rclcpp::SystemDefaultsQoS()); | ||
|
||
timer_ = this->create_wall_timer( | ||
std::chrono::milliseconds(100), | ||
std::bind(&ZeroCmdVelNode::publish_zero_cmd_vel, this)); | ||
} | ||
|
||
void ZeroCmdVelNode::publish_zero_cmd_vel() { | ||
geometry_msgs::msg::TwistStamped zero_cmd_vel; | ||
zero_cmd_vel.twist.linear.x = 0.0; | ||
zero_cmd_vel.twist.angular.z = 0.0; | ||
drivetrain_cmd_publisher->publish(zero_cmd_vel); | ||
|
||
} // namespace zero_cmd_vel_node | ||
} // namespace zero_cmd_vel_node | ||
|
||
RCLCPP_COMPONENTS_REGISTER_NODE(zero_cmd_vel_node::ZeroCmdVelNode); |