generated from iscumd/isc-ros2-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
69 additions
and
76 deletions.
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 was deleted.
Oops, something went wrong.
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,21 @@ | ||
#pragma once | ||
|
||
#include "ackermann_msgs/msg/ackermann_drive.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "sensor_msgs/msg/joy.hpp" | ||
|
||
class TeleopAckJoyNode : public rclcpp::Node { | ||
private: | ||
// Sub | ||
rclcpp::Subscription<sensor_msgs::msg::Joy>::SharedPtr joy_sub; | ||
|
||
// Pub | ||
rclcpp::Publisher<ackermann_msgs::msg::AckermannDrive>::SharedPtr ackermann_pub; | ||
|
||
public: | ||
TeleopAckJoyNode(const rclcpp::NodeOptions& options); | ||
|
||
float map_input(float in, float inMin, float inMax, float outMin, float outMax); | ||
|
||
void joy_cb(sensor_msgs::msg::Joy::SharedPtr outputs); | ||
}; |
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 was deleted.
Oops, something went wrong.
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,30 @@ | ||
#include "teleop_ack_joy/TeleopAckJoyNode_node.hpp" | ||
|
||
// For _1 | ||
using namespace std::placeholders; | ||
|
||
TeleopAckJoyNode::TeleopAckJoyNode(const rclcpp::NodeOptions& options) : Node("TeleopAckjoyNode", options) { | ||
joy_sub = | ||
this->create_subscription<sensor_msgs::msg::Joy>("/joy", 5, std::bind(&TeleopAckJoyNode::joy_cb, this, _1)); | ||
|
||
ackermann_pub = this->create_publisher<ackermann_msgs::msg::AckermannDrive>("/nav_ack_vel", 1); | ||
} | ||
|
||
void TeleopAckJoyNode::joy_cb(sensor_msgs::msg::Joy::SharedPtr outputs) { | ||
ackermann_msgs::msg::AckermannDrive command; | ||
|
||
float left_stick_lr_val = outputs->axes.at(0); | ||
float right_trigger_val = -outputs->axes.at(5); | ||
|
||
command.steering_angle = map_input(left_stick_lr_val, -1, 1, -0.40, 0.40); | ||
command.speed = map_input(right_trigger_val, -1, 1, 0, 5); | ||
|
||
ackermann_pub->publish(command); | ||
} | ||
|
||
float TeleopAckJoyNode::map_input(float in, float inMin, float inMax, float outMin, float outMax) { | ||
float slope = (outMax - outMin) / (inMax - inMin); | ||
float b = outMax - slope * inMax; | ||
|
||
return slope * in + b; | ||
} |
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