|
| 1 | +// Copyright 2023 The Autoware Contributors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef JOY_CONTROLLER__JOY_CONVERTER__XBOX_JOY_CONVERTER_HPP_ |
| 16 | +#define JOY_CONTROLLER__JOY_CONVERTER__XBOX_JOY_CONVERTER_HPP_ |
| 17 | + |
| 18 | +#include "joy_controller/joy_converter/joy_converter_base.hpp" |
| 19 | + |
| 20 | +#include <algorithm> |
| 21 | + |
| 22 | +namespace joy_controller |
| 23 | +{ |
| 24 | +class XBOXJoyConverter : public JoyConverterBase |
| 25 | +{ |
| 26 | +public: |
| 27 | + explicit XBOXJoyConverter(const sensor_msgs::msg::Joy & j) : j_(j) {} |
| 28 | + |
| 29 | + float accel() const { return std::max(0.0f, -((RT() - 1.0f) / 2.0f)); } |
| 30 | + |
| 31 | + float brake() const { return std::max(0.0f, -((LT() - 1.0f) / 2.0f)); } |
| 32 | + |
| 33 | + float steer() const { return LStickLeftRight(); } |
| 34 | + |
| 35 | + bool shift_up() const { return CursorUpDown() == 1.0f; } |
| 36 | + bool shift_down() const { return CursorUpDown() == -1.0f; } |
| 37 | + bool shift_drive() const { return CursorLeftRight() == 1.0f; } |
| 38 | + bool shift_reverse() const { return CursorLeftRight() == -1.0f; } |
| 39 | + |
| 40 | + bool turn_signal_left() const { return LB(); } |
| 41 | + bool turn_signal_right() const { return RB(); } |
| 42 | + bool clear_turn_signal() const { return A(); } |
| 43 | + |
| 44 | + bool gate_mode() const { return B(); } |
| 45 | + |
| 46 | + bool emergency_stop() const { return ChangeView(); } |
| 47 | + bool clear_emergency_stop() const { return Menu(); } |
| 48 | + |
| 49 | + bool autoware_engage() const { return X(); } |
| 50 | + bool autoware_disengage() const { return Y(); } |
| 51 | + |
| 52 | + bool vehicle_engage() const { return LStickButton(); } |
| 53 | + bool vehicle_disengage() const { return RStickButton(); } |
| 54 | + |
| 55 | +private: |
| 56 | + float LStickLeftRight() const { return j_.axes.at(0); } |
| 57 | + float LStickUpDown() const { return j_.axes.at(1); } |
| 58 | + float RStickLeftRight() const { return j_.axes.at(2); } |
| 59 | + float RStickUpDown() const { return j_.axes.at(3); } |
| 60 | + float RT() const { return j_.axes.at(4); } |
| 61 | + float LT() const { return j_.axes.at(5); } |
| 62 | + float CursorLeftRight() const { return j_.axes.at(6); } |
| 63 | + float CursorUpDown() const { return j_.axes.at(7); } |
| 64 | + |
| 65 | + bool A() const { return j_.buttons.at(0); } |
| 66 | + bool B() const { return j_.buttons.at(1); } |
| 67 | + bool X() const { return j_.buttons.at(3); } |
| 68 | + bool Y() const { return j_.buttons.at(4); } |
| 69 | + bool LB() const { return j_.buttons.at(6); } |
| 70 | + bool RB() const { return j_.buttons.at(7); } |
| 71 | + bool Menu() const { return j_.buttons.at(11); } |
| 72 | + bool LStickButton() const { return j_.buttons.at(13); } |
| 73 | + bool RStickButton() const { return j_.buttons.at(14); } |
| 74 | + bool ChangeView() const { return j_.buttons.at(15); } |
| 75 | + bool Xbox() const { return j_.buttons.at(16); } |
| 76 | + |
| 77 | + const sensor_msgs::msg::Joy j_; |
| 78 | +}; |
| 79 | +} // namespace joy_controller |
| 80 | + |
| 81 | +#endif // JOY_CONTROLLER__JOY_CONVERTER__XBOX_JOY_CONVERTER_HPP_ |
0 commit comments