Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/axis params enum like #83

Merged
merged 6 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/control/joy2twist/config/joy2twist.param.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**:
joy2twist:
ros__parameters:
linear_x_axis: 1
angular_z_axis: 0
linear_x_axis: "LEFT_STICK_Y"
angular_z_axis: "LEFT_STICK_X"
8 changes: 8 additions & 0 deletions src/control/joy2twist/include/joy2twist/joy2twist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <geometry_msgs/msg/twist_stamped.hpp>
#include <sensor_msgs/msg/joy.hpp>

#include <string>
#include <unordered_map>

namespace joy2twist
{
using Joy = sensor_msgs::msg::Joy;
Expand All @@ -28,6 +31,11 @@ class Joy2Twist : public rclcpp::Node
TwistStampedPublisher::SharedPtr twist_pub_;
};

const std::unordered_map<std::string, int> axis_map = {
{"LEFT_STICK_X", 0}, // 左スティックのX軸
{"LEFT_STICK_Y", 1} // 左スティックのY軸
};

} // namespace joy2twist

#endif // JOY2TWIST__JOY2TWIST_HPP_
9 changes: 6 additions & 3 deletions src/control/joy2twist/src/joy2twist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace joy2twist
{

Joy2Twist::Joy2Twist(const rclcpp::NodeOptions & options) : Node("joy2twist", options)
{
// パラメータの取得
linear_x_axis_ = declare_parameter<int>("linear_x_axis", 1);
angular_z_axis_ = declare_parameter<int>("angular_z_axis", 0);
std::string linear_x_axis_str = declare_parameter<std::string>("linear_x_axis", "LEFT_STICK_Y");
std::string angular_z_axis_str = declare_parameter<std::string>("angular_z_axis", "LEFT_STICK_X");

// 軸名を対応する数値に変換
linear_x_axis_ = axis_map.at(linear_x_axis_str);
angular_z_axis_ = axis_map.at(angular_z_axis_str);

// 受信機を作る。型はjoyで受け取る。10個まで値が保持される。
joy_sub_ = this->create_subscription<Joy>(
Expand Down
Loading