kobayashina 2023-09-28
fix cmd_vel decided by LStick
@c59346a9ca88ac4277dcfccfd07455d2441e8d90
README.md
--- README.md
+++ README.md
@@ -71,6 +71,11 @@
 | 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.
 
media/joy2vel.png (Binary) (added)
+++ media/joy2vel.png
Binary file is not shown
p9n_node/src/teleop_twist_joy_node.cpp
--- p9n_node/src/teleop_twist_joy_node.cpp
+++ p9n_node/src/teleop_twist_joy_node.cpp
@@ -23,7 +23,7 @@
   const std::string hw_name = this->declare_parameter<std::string>(
     "hw_type", p9n_interface::HW_NAME::DUALSENSE);
   this->linear_max_speed_ =
-    this->declare_parameter<double>("linear_speed", 0.2);
+    this->declare_parameter<double>("linear_speed", 0.9);
   this->angular_max_speed_ =
     this->declare_parameter<double>("angular_speed", 0.6);
 
@@ -64,15 +64,19 @@
   this->timer_watchdog_->reset();
   this->p9n_if_->setJoyMsg(joy_msg);
 
+  const double PI = 3.14159;
   static bool stopped = true;
   if (this->p9n_if_->isTiltedStickL()) {
     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(PI / 8)) {
       twist_msg->angular.set__z(this->angular_max_speed_ * this->p9n_if_->tiltedStickLX());
-    } else {
+    } else if (this->p9n_if_->tiltedStickLY() < sin(-PI / 8)) {
       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));
 
Add a comment
List