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

fix cmd_vel decided by LStick #41

Merged
merged 4 commits into from
Nov 24, 2023
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ void Example::onJoyCallback(sensor_msgs::msg::Joy::ConstSharedPtr joy_msg) {
| L2 | `float` | `pressedL2Analog();` | `-1.0` : Pressed, `1.0` : Not pressed |


## Convert from Left Joy Stick to cmd_vel
`teleop_twist_joy_node` has cmd_vel publisher.
Velocity is decided as below.
![Image](./media/joy2vel.png)


## Acknowledgements
We acknowledge attribute and gratitude to the following resources in creating this package.
Expand Down
Binary file added media/joy2vel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion p9n_node/include/p9n_node/teleop_twist_joy_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class TeleopTwistJoyNode : public rclcpp::Node
using Joy = sensor_msgs::msg::Joy;

private:
float speed_factor_ = 1.0;
double linear_max_speed_, angular_max_speed_;

p9n_interface::HW_TYPE hw_type_;
Expand Down
7 changes: 5 additions & 2 deletions p9n_node/src/teleop_twist_joy_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ void TeleopTwistJoyNode::onJoy(Joy::ConstSharedPtr joy_msg)
auto twist_msg = std::make_unique<Twist>();
twist_msg->linear.set__x(this->linear_max_speed_ * this->p9n_if_->tiltedStickLY());

if (twist_msg->linear.x > 0) {
if (this->p9n_if_->tiltedStickLY() > sin(M_PI * 0.125)) {
twist_msg->angular.set__z(this->angular_max_speed_ * this->p9n_if_->tiltedStickLX());
} else {
} else if (this->p9n_if_->tiltedStickLY() < sin(-M_PI * 0.125)) {
twist_msg->angular.set__z(-this->angular_max_speed_ * this->p9n_if_->tiltedStickLX());
} else {
twist_msg->linear.set__x(0.0);
twist_msg->angular.set__z(this->angular_max_speed_ * this->p9n_if_->tiltedStickLX());
}
this->twist_pub_->publish(std::move(twist_msg));

Expand Down
Loading