

add tilted judge function
@e259e08fe7fc69b01493481c14c47d27ec6bbd04
--- p9n_interface/include/p9n_interface/p9n_interface.hpp
+++ p9n_interface/include/p9n_interface/p9n_interface.hpp
... | ... | @@ -76,6 +76,7 @@ |
76 | 76 |
|
77 | 77 |
private: |
78 | 78 |
bool isAvailable(); |
79 |
+ bool isTilted(const size_t, const double = 1e-1); |
|
79 | 80 |
|
80 | 81 |
public: |
81 | 82 |
explicit PlayStationInterface(const HW_TYPE); |
... | ... | @@ -107,8 +108,11 @@ |
107 | 108 |
|
108 | 109 |
float tiltedStickLX(); |
109 | 110 |
float tiltedStickLY(); |
111 |
+ bool isTiltedStickL(); |
|
112 |
+ |
|
110 | 113 |
float tiltedStickRX(); |
111 | 114 |
float tiltedStickRY(); |
115 |
+ bool isTiltedStickR(); |
|
112 | 116 |
|
113 | 117 |
float pressedR2Analog(); |
114 | 118 |
float pressedL2Analog(); |
--- p9n_interface/src/p9n_interface.cpp
+++ p9n_interface/src/p9n_interface.cpp
... | ... | @@ -235,6 +235,11 @@ |
235 | 235 |
return false; |
236 | 236 |
} |
237 | 237 |
|
238 |
+bool PlayStationInterface::isTilted(const size_t idx, const double threshold) |
|
239 |
+{ |
|
240 |
+ return std::abs(this->joy_->axes.at(idx)) > threshold; |
|
241 |
+} |
|
242 |
+ |
|
238 | 243 |
void PlayStationInterface::setJoyMsg(sensor_msgs::msg::Joy::ConstSharedPtr msg) |
239 | 244 |
{ |
240 | 245 |
this->joy_ = msg; |
... | ... | @@ -255,7 +260,7 @@ |
255 | 260 |
pressed |= this->joy_->axes.at(i) < 0.0; |
256 | 261 |
continue; |
257 | 262 |
} |
258 |
- pressed |= std::abs(this->joy_->axes.at(i)) > 1e-1; |
|
263 |
+ pressed |= this->isTilted(i); |
|
259 | 264 |
} |
260 | 265 |
return pressed; |
261 | 266 |
} |
... | ... | @@ -447,6 +452,16 @@ |
447 | 452 |
this->axes_idx_->stick_ly); |
448 | 453 |
} |
449 | 454 |
|
455 |
+bool PlayStationInterface::isTiltedStickL() |
|
456 |
+{ |
|
457 |
+ if (!this->isAvailable()) { |
|
458 |
+ return false; |
|
459 |
+ } |
|
460 |
+ |
|
461 |
+ return this->isTilted(this->axes_idx_->stick_lx) || |
|
462 |
+ this->isTilted(this->axes_idx_->stick_ly); |
|
463 |
+} |
|
464 |
+ |
|
450 | 465 |
float PlayStationInterface::tiltedStickRX() |
451 | 466 |
{ |
452 | 467 |
if (!this->isAvailable()) { |
... | ... | @@ -465,6 +480,16 @@ |
465 | 480 |
this->axes_idx_->stick_ry); |
466 | 481 |
} |
467 | 482 |
|
483 |
+bool PlayStationInterface::isTiltedStickR() |
|
484 |
+{ |
|
485 |
+ if (!this->isAvailable()) { |
|
486 |
+ return false; |
|
487 |
+ } |
|
488 |
+ |
|
489 |
+ return this->isTilted(this->axes_idx_->stick_rx) || |
|
490 |
+ this->isTilted(this->axes_idx_->stick_ry); |
|
491 |
+} |
|
492 |
+ |
|
468 | 493 |
float PlayStationInterface::pressedR2Analog() |
469 | 494 |
{ |
470 | 495 |
if (!this->isAvailable()) { |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?