m12watanabe1a 2022-10-19
add tilted judge function
@e259e08fe7fc69b01493481c14c47d27ec6bbd04
p9n_interface/include/p9n_interface/p9n_interface.hpp
--- p9n_interface/include/p9n_interface/p9n_interface.hpp
+++ p9n_interface/include/p9n_interface/p9n_interface.hpp
@@ -76,6 +76,7 @@
 
 private:
   bool isAvailable();
+  bool isTilted(const size_t, const double = 1e-1);
 
 public:
   explicit PlayStationInterface(const HW_TYPE);
@@ -107,8 +108,11 @@
 
   float tiltedStickLX();
   float tiltedStickLY();
+  bool isTiltedStickL();
+
   float tiltedStickRX();
   float tiltedStickRY();
+  bool isTiltedStickR();
 
   float pressedR2Analog();
   float pressedL2Analog();
p9n_interface/src/p9n_interface.cpp
--- p9n_interface/src/p9n_interface.cpp
+++ p9n_interface/src/p9n_interface.cpp
@@ -235,6 +235,11 @@
   return false;
 }
 
+bool PlayStationInterface::isTilted(const size_t idx, const double threshold)
+{
+  return std::abs(this->joy_->axes.at(idx)) > threshold;
+}
+
 void PlayStationInterface::setJoyMsg(sensor_msgs::msg::Joy::ConstSharedPtr msg)
 {
   this->joy_ = msg;
@@ -255,7 +260,7 @@
       pressed |= this->joy_->axes.at(i) < 0.0;
       continue;
     }
-    pressed |= std::abs(this->joy_->axes.at(i)) > 1e-1;
+    pressed |= this->isTilted(i);
   }
   return pressed;
 }
@@ -447,6 +452,16 @@
     this->axes_idx_->stick_ly);
 }
 
+bool PlayStationInterface::isTiltedStickL()
+{
+  if (!this->isAvailable()) {
+    return false;
+  }
+
+  return this->isTilted(this->axes_idx_->stick_lx) ||
+         this->isTilted(this->axes_idx_->stick_ly);
+}
+
 float PlayStationInterface::tiltedStickRX()
 {
   if (!this->isAvailable()) {
@@ -465,6 +480,16 @@
     this->axes_idx_->stick_ry);
 }
 
+bool PlayStationInterface::isTiltedStickR()
+{
+  if (!this->isAvailable()) {
+    return false;
+  }
+
+  return this->isTilted(this->axes_idx_->stick_rx) ||
+         this->isTilted(this->axes_idx_->stick_ry);
+}
+
 float PlayStationInterface::pressedR2Analog()
 {
   if (!this->isAvailable()) {
Add a comment
List