Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add autoware joy controller #72

Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
55874d2
release v0.4.0
mitsudome-r Sep 18, 2020
1e8dd6e
Support G29 controller in autoware_joy_controller (#699)
rej55 Jul 19, 2020
491c0ce
Change key map for G29 controller and set deadzone parameter (#740)
rej55 Aug 6, 2020
af3a231
Add missing dependencies of autoware_joy_controller (#755)
kenji-miyake Aug 12, 2020
41601eb
remove ROS1 packages temporarily
mitsudome-r Sep 29, 2020
b657d55
add sample ros2 packages
mitsudome-r Sep 29, 2020
f98dee7
remove ROS1 packages
mitsudome-r Oct 6, 2020
0d65b02
Revert "remove ROS1 packages temporarily"
mitsudome-r Oct 8, 2020
6c94e2c
add COLCON_IGNORE to ros1 packages
mitsudome-r Oct 8, 2020
fa8b029
Rename launch files to launch.xml (#28)
nnmm Oct 15, 2020
1929d9f
Rename h files to hpp (#142)
nnmm Dec 3, 2020
443a147
Adjust copyright notice on 532 out of 699 source files (#143)
nnmm Dec 3, 2020
44e70c4
Use quotes for includes where appropriate (#144)
nnmm Dec 7, 2020
75ede3b
Port autoware joy controller (#124)
sgermanserrano Dec 8, 2020
bf98f2f
Run uncrustify on the entire Pilot.Auto codebase (#151)
nnmm Dec 8, 2020
21266f1
[update to v0.8.0] autoware joy controller (#251)
TakaHoribe Feb 8, 2021
449f4ba
Rename ROS-related .yaml to .param.yaml (#352)
kenji-miyake Feb 24, 2021
9c16639
remove using in global namespace (#379)
mitsudome-r Feb 28, 2021
e4ab6a1
fix namespace (#414)
tkimura4 Mar 10, 2021
226c5a2
add use_sim-time option (#454)
tkimura4 Mar 26, 2021
59a39b1
Fix for rolling (#1226)
kenji-miyake Apr 8, 2021
df5bf04
Make control modules components (#1262)
wep21 Apr 21, 2021
9e5b51f
Remove use_sim_time for set_parameter (#1260)
wep21 Apr 26, 2021
1919d0c
Remove autoware_debug_msgs from autoware_joy_controller (#1303)
kenji-miyake May 7, 2021
cb21087
Porting remote cmd selector (#1286)
KeisukeShima May 7, 2021
01531d6
Ros2/create/external commands (#1299)
taikitanaka3 May 31, 2021
39a0365
Fix -Wunused-parameter (#1836)
kenji-miyake Aug 14, 2021
9d8381a
Add autoware api (#1979)
isamu-takagi Aug 31, 2021
4368ea0
Use EmergencyState instead of deprecated EmergencyMode (#2030)
kenji-miyake Sep 8, 2021
509df2e
add sort-package-xml hook in pre-commit (#1881)
KeisukeShima Sep 9, 2021
f752152
Add selected external command API (#2053)
isamu-takagi Sep 10, 2021
e6857cb
submit engage with api service from joy controller (#2320)
h-ohta Oct 29, 2021
2ffed42
Change formatter to clang-format and black (#2332)
kenji-miyake Nov 2, 2021
e52a75c
Add COLCON_IGNORE (#500)
kenji-miyake Nov 4, 2021
39d2387
port autoware joy controller (#588)
takayuki5168 Nov 11, 2021
824c008
update README.md in autoware_joy_controller (#593)
takayuki5168 Nov 11, 2021
c566909
fix format
taikitanaka3 Nov 30, 2021
4aa8d1e
Merge branch 'autowarefoundation:tier4/proposal' into 1-add-autoware-…
taikitanaka3 Dec 1, 2021
f1e2eb8
ci(pre-commit): autofix
pre-commit-ci[bot] Dec 1, 2021
29f6e00
Merge branch 'tier4/proposal' into 1-add-autoware-joy-controller
1222-takeshi Dec 7, 2021
ec3ce96
Merge branch 'tier4/proposal' into 1-add-autoware-joy-controller
1222-takeshi Dec 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions control/autoware_joy_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.5)
project(autoware_joy_controller)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
endif()

find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

ament_auto_add_library(autoware_joy_controller_node SHARED
src/autoware_joy_controller/autoware_joy_controller_node.cpp
)

rclcpp_components_register_node(autoware_joy_controller_node
PLUGIN "autoware_joy_controller::AutowareJoyControllerNode"
EXECUTABLE autoware_joy_controller
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

ament_auto_package(
INSTALL_TO_SHARE
launch
config
)
43 changes: 43 additions & 0 deletions control/autoware_joy_controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# autoware_joy_controller

## Role

`autoware_joy_controller` is the package to convert a joy msg to autoware commands (e.g. steering wheel, shift, turn signal, engage) for a vehicle.

## Input / Output

### Input topics

| Name | Type | Description |
| ------------------ | ----------------------- | --------------------------------- |
| `~/input/joy` | sensor_msgs::msg::Joy | joy controller command |
| `~/input/odometry` | nav_msgs::msg::Odometry | ego vehicle odometry to get twist |

### Output topics

| Name | Type | Description |
| ----------------------------------- | -------------------------------------------------------- | ---------------------------------------- |
| `~/output/control_command` | autoware_auto_control_msgs::msg::AckermannControlCommand | lateral and longitudinal control command |
| `~/output/external_control_command` | autoware_external_api_msgs::msg::ControlCommandStamped | lateral and longitudinal control command |
| `~/output/shift` | autoware_external_api_msgs::msg::GearShiftStamped | gear command |
| `~/output/turn_signal` | autoware_external_api_msgs::msg::TurnSignalStamped | turn signal command |
| `~/output/gate_mode` | autoware_control_msgs::msg::GateMode | gate mode (Auto or External) |
| `~/output/heartbeat` | autoware_external_api_msgs::msg::Heartbeat | heartbeat |
| `~/output/vehicle_engage` | autoware_auto_vehicle_msgs::msg::Engage | vehicle engage |

## Parameters

| Parameter | Type | Description |
| ------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------ |
| `joy_type` | string | joy controller type (default: DS4) |
| `update_rate` | double | update rate to publish control commands |
| `accel_ratio` | double | ratio to calculate acceleration (commanded acceleration is ratio \* operation) |
| `brake_ratio` | double | ratio to calculate deceleration (commanded acceleration is -ratio \* operation) |
| `steer_ratio` | double | ratio to calculate deceleration (commanded steer is ratio \* operation) |
| `steering_angle_velocity` | double | steering angle velocity for operation |
| `accel_sensitivity` | double | sensitivity to calculate acceleration for external API (commanded acceleration is pow(operation, 1 / sensitivity)) |
| `brake_sensitivity` | double | sensitivity to calculate deceleration for external API (commanded acceleration is pow(operation, 1 / sensitivity)) |
| `velocity_gain` | double | ratio to calculate velocity by acceleration |
| `max_forward_velocity` | double | absolute max velocity to go forward |
| `max_backward_velocity` | double | absolute max velocity to go backward |
| `backward_accel_ratio` | double | ratio to calculate deceleration (commanded acceleration is -ratio \* operation) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**:
ros__parameters:
update_rate: 10.0
accel_ratio: 3.0
brake_ratio: 5.0
steer_ratio: 0.5
steering_angle_velocity: 0.1
accel_sensitivity: 1.0
brake_sensitivity: 1.0
control_command:
velocity_gain: 3.0
max_forward_velocity: 20.0
max_backward_velocity: 3.0
backward_accel_ratio: 1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright 2020 Tier IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef AUTOWARE_JOY_CONTROLLER__AUTOWARE_JOY_CONTROLLER_HPP_
#define AUTOWARE_JOY_CONTROLLER__AUTOWARE_JOY_CONTROLLER_HPP_

#include "autoware_joy_controller/joy_converter/joy_converter_base.hpp"

#include <rclcpp/rclcpp.hpp>

#include <autoware_auto_control_msgs/msg/ackermann_control_command.hpp>
#include <autoware_auto_vehicle_msgs/msg/engage.hpp>
#include <autoware_control_msgs/msg/gate_mode.hpp>
#include <autoware_external_api_msgs/msg/control_command_stamped.hpp>
#include <autoware_external_api_msgs/msg/gear_shift_stamped.hpp>
#include <autoware_external_api_msgs/msg/heartbeat.hpp>
#include <autoware_external_api_msgs/msg/turn_signal_stamped.hpp>
#include <autoware_external_api_msgs/srv/engage.hpp>
#include <autoware_external_api_msgs/srv/set_emergency.hpp>
#include <geometry_msgs/msg/twist_stamped.hpp>
#include <nav_msgs/msg/odometry.hpp>
#include <sensor_msgs/msg/joy.hpp>

#include <algorithm>
#include <memory>
#include <string>

namespace autoware_joy_controller
{
using GearShiftType = autoware_external_api_msgs::msg::GearShift::_data_type;
using TurnSignalType = autoware_external_api_msgs::msg::TurnSignal::_data_type;
using GateModeType = autoware_control_msgs::msg::GateMode::_data_type;

class AutowareJoyControllerNode : public rclcpp::Node
{
public:
explicit AutowareJoyControllerNode(const rclcpp::NodeOptions & node_options);

private:
// Parameter
std::string joy_type_;
double update_rate_;
double accel_ratio_;
double brake_ratio_;
double steer_ratio_;
double steering_angle_velocity_;
double accel_sensitivity_;
double brake_sensitivity_;

// ControlCommand Parameter
double velocity_gain_;
double max_forward_velocity_;
double max_backward_velocity_;
double backward_accel_ratio_;

// CallbackGroups
rclcpp::CallbackGroup::SharedPtr callback_group_subscribers_;
rclcpp::CallbackGroup::SharedPtr callback_group_services_;

// Subscriber
rclcpp::Subscription<sensor_msgs::msg::Joy>::SharedPtr sub_joy_;
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr sub_odom_;

rclcpp::Time last_joy_received_time_;
std::shared_ptr<const JoyConverterBase> joy_;
geometry_msgs::msg::TwistStamped::ConstSharedPtr twist_;

void onJoy(const sensor_msgs::msg::Joy::ConstSharedPtr msg);
void onOdometry(const nav_msgs::msg::Odometry::ConstSharedPtr msg);

// Publisher
rclcpp::Publisher<autoware_auto_control_msgs::msg::AckermannControlCommand>::SharedPtr
pub_control_command_;
rclcpp::Publisher<autoware_external_api_msgs::msg::ControlCommandStamped>::SharedPtr
pub_external_control_command_;
rclcpp::Publisher<autoware_external_api_msgs::msg::GearShiftStamped>::SharedPtr pub_shift_;
rclcpp::Publisher<autoware_external_api_msgs::msg::TurnSignalStamped>::SharedPtr pub_turn_signal_;
rclcpp::Publisher<autoware_external_api_msgs::msg::Heartbeat>::SharedPtr pub_heartbeat_;
rclcpp::Publisher<autoware_control_msgs::msg::GateMode>::SharedPtr pub_gate_mode_;
rclcpp::Publisher<autoware_auto_vehicle_msgs::msg::Engage>::SharedPtr pub_vehicle_engage_;

void publishControlCommand();
void publishExternalControlCommand();
void publishShift();
void publishTurnSignal();
void publishGateMode();
void publishHeartbeat();
void publishAutowareEngage();
void publishVehicleEngage();
void sendEmergencyRequest(bool emergency);

// Service Client
rclcpp::Client<autoware_external_api_msgs::srv::SetEmergency>::SharedPtr client_emergency_stop_;
rclcpp::Client<autoware_external_api_msgs::srv::Engage>::SharedPtr client_autoware_engage_;

// Previous State
autoware_auto_control_msgs::msg::AckermannControlCommand prev_control_command_;
autoware_external_api_msgs::msg::ControlCommand prev_external_control_command_;
GearShiftType prev_shift_ = autoware_external_api_msgs::msg::GearShift::NONE;
TurnSignalType prev_turn_signal_ = autoware_external_api_msgs::msg::TurnSignal::NONE;
GateModeType prev_gate_mode_ = autoware_control_msgs::msg::GateMode::AUTO;

// Timer
rclcpp::TimerBase::SharedPtr timer_;
void initTimer(double period_s);

bool isDataReady();
void onTimer();
};
} // namespace autoware_joy_controller

#endif // AUTOWARE_JOY_CONTROLLER__AUTOWARE_JOY_CONTROLLER_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2020 Tier IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef AUTOWARE_JOY_CONTROLLER__JOY_CONVERTER__DS4_JOY_CONVERTER_HPP_
#define AUTOWARE_JOY_CONTROLLER__JOY_CONVERTER__DS4_JOY_CONVERTER_HPP_

#include "autoware_joy_controller/joy_converter/joy_converter_base.hpp"

#include <algorithm>

namespace autoware_joy_controller
{
class DS4JoyConverter : public JoyConverterBase
{
public:
explicit DS4JoyConverter(const sensor_msgs::msg::Joy & j) : j_(j) {}

float accel() const
{
const auto button = static_cast<float>(Cross());
const auto stick = std::max(0.0f, RStickUpDown());
const auto trigger = std::max(0.0f, -RTrigger());
return std::max({button, stick, trigger});
}

float brake() const
{
const auto button = static_cast<float>(Square());
const auto stick = std::max(0.0f, -RStickUpDown());
const auto trigger = std::max(0.0f, -LTrigger());
return std::max({button, stick, trigger});
}

float steer() const { return LStickLeftRight(); }

bool shift_up() const { return CursorUpDown() == 1.0f; }
bool shift_down() const { return CursorUpDown() == -1.0f; }
bool shift_drive() const { return CursorLeftRight() == 1.0f; }
bool shift_reverse() const { return CursorLeftRight() == -1.0f; }

bool turn_signal_left() const { return L1(); }
bool turn_signal_right() const { return R1(); }
bool clear_turn_signal() const { return Share(); }

bool gate_mode() const { return Options(); }

bool emergency_stop() const { return !reverse() && PS(); }
bool clear_emergency_stop() const { return reverse() && PS(); }

bool autoware_engage() const { return !reverse() && Circle(); }
bool autoware_disengage() const { return reverse() && Circle(); }

bool vehicle_engage() const { return !reverse() && Triangle(); }
bool vehicle_disengage() const { return reverse() && Triangle(); }

private:
float LStickLeftRight() const { return j_.axes.at(0); }
float LStickUpDown() const { return j_.axes.at(1); }
float LTrigger() const { return j_.axes.at(2); }
float RStickLeftRight() const { return j_.axes.at(3); }
float RStickUpDown() const { return j_.axes.at(4); }
float RTrigger() const { return j_.axes.at(5); }
float CursorLeftRight() const { return j_.axes.at(6); }
float CursorUpDown() const { return j_.axes.at(7); }

bool Cross() const { return j_.buttons.at(0); }
bool Circle() const { return j_.buttons.at(1); }
bool Triangle() const { return j_.buttons.at(2); }
bool Square() const { return j_.buttons.at(3); }
bool L1() const { return j_.buttons.at(4); }
bool R1() const { return j_.buttons.at(5); }
bool L2() const { return j_.buttons.at(6); }
bool R2() const { return j_.buttons.at(7); }
bool Share() const { return j_.buttons.at(8); }
bool Options() const { return j_.buttons.at(9); }
bool PS() const { return j_.buttons.at(10); }

const sensor_msgs::msg::Joy j_;

bool reverse() const { return Share(); }
};
} // namespace autoware_joy_controller

#endif // AUTOWARE_JOY_CONTROLLER__JOY_CONVERTER__DS4_JOY_CONVERTER_HPP_
Loading