Skip to content

Commit

Permalink
Merge pull request #41 from HarvestX/fix/left_stick_velocity
Browse files Browse the repository at this point in the history
fix cmd_vel decided by LStick
  • Loading branch information
m12watanabe1a authored Nov 24, 2023
2 parents bcafaba + 74bfef3 commit 2d7b4b2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
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

0 comments on commit 2d7b4b2

Please sign in to comment.