Skip to content

Commit 2ab1ade

Browse files
taikitanaka3mitsudome-rfred-apex-ainnmmesteve
authored
feat: add shift decider (#29)
* release v0.4.0 * remove ROS1 packages temporarily Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * add sample ros2 packages Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * remove ROS1 packages Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * Revert "remove ROS1 packages temporarily" This reverts commit bcc60bdc82842e2ea4d1e844b4442fa613d80fdf. Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * add COLCON_IGNORE to ros1 packages Signed-off-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> * Port shift decider to ros2 (#7) * Update package.xml and CMakeLists.txt to ros2 Code doesn't compile yet * Code compiles * Update launch file * Add better timer clang-format shift_decider * Rename h files to hpp (#142) * Change includes * Rename files * Adjustments to make things compile * Other packages * Adjust copyright notice on 532 out of 699 source files (#143) * Use quotes for includes where appropriate (#144) * Use quotes for includes where appropriate * Fix lint tests * Make tests pass hopefully * Run uncrustify on the entire Pilot.Auto codebase (#151) * Run uncrustify on the entire Pilot.Auto codebase * Exclude open PRs * Added linters to shift_decider (#167) * Added linters to shift_decider * Fix dependencies * Use ament_cmake_cppcheck and ament_cmake_cpplint * Fix linting errors * add use_sim-time option (#454) * Unify Apache-2.0 license name (#1242) * Make control modules components (#1262) Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Remove use_sim_time for set_parameter (#1260) Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * add sort-package-xml hook in pre-commit (#1881) * add sort xml hook in pre-commit * change retval to exit_status * rename * add prettier plugin-xml * use early return * add license note * add tier4 license * restore prettier * change license order * move local hooks to public repo * move prettier-xml to pre-commit-hooks-ros * update version for bug-fix * apply pre-commit * Change formatter to clang-format and black (#2332) * Revert "Temporarily comment out pre-commit hooks" This reverts commit 748e9cdb145ce12f8b520bcbd97f5ff899fc28a3. * Replace ament_lint_common with autoware_lint_common Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Remove ament_cmake_uncrustify and ament_clang_format Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Apply Black Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Apply clang-format Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix build errors Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix for cpplint * Fix include double quotes to angle brackets Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Apply clang-format Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix build errors Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Add COLCON_IGNORE (#500) Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * port shift decider (#485) * port shift decider * apply clang format * delete colcon ignore * change to ackermann control command * remove VehicleStateReport/VehicleStateCommand/VehicleControlCommand (#549) * fix autoware_error_monitor * fix state monitor * fix emergency handler(vehicle_state_report) * fix emergency Handler(vehicle_state_command) * fix shift_decider * fix emergency_handler(vehicle_control_command) * fix topic name * fix readme * Update system/autoware_state_monitor/Readme.md Co-authored-by: taikitanaka3 <65527974+taikitanaka3@users.noreply.github.com> * fix format * Update system/autoware_state_monitor/launch/autoware_state_monitor.launch.xml Co-authored-by: taikitanaka3 <65527974+taikitanaka3@users.noreply.github.com> * fix typo Co-authored-by: taikitanaka3 <65527974+taikitanaka3@users.noreply.github.com> * [shift decider] add README.md (#577) * add readme to shift decider * better expression Co-authored-by: tkimura4 <tomoya.kimura@tier4.jp> Co-authored-by: taikitanaka3 <taiki.tanaka@tier4.jp> Co-authored-by: tkimura4 <tomoya.kimura@tier4.jp> * Fix topic name (#673) Co-authored-by: mitsudome-r <ryohsuke.mitsudome@tier4.jp> Co-authored-by: Frederik Beaujean <72439809+fred-apex-ai@users.noreply.github.com> Co-authored-by: Nikolai Morin <nnmmgit@gmail.com> Co-authored-by: Esteve Fernandez <esteve@apache.org> Co-authored-by: tkimura4 <tomoya.kimura@tier4.jp> Co-authored-by: Kazuki Miyahara <kmiya@outlook.com> Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> Co-authored-by: Keisuke Shima <19993104+KeisukeShima@users.noreply.github.com> Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> Co-authored-by: Sugatyon <32741405+Sugatyon@users.noreply.github.com> Co-authored-by: taikitanaka3 <taiki.tanaka@tier4.jp> Co-authored-by: Fumiya Watanabe <rej55.g@gmail.com>
1 parent 00308c4 commit 2ab1ade

File tree

6 files changed

+244
-0
lines changed

6 files changed

+244
-0
lines changed

control/shift_decider/CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(shift_decider)
3+
4+
find_package(ament_cmake_auto REQUIRED)
5+
ament_auto_find_build_dependencies()
6+
7+
if(NOT CMAKE_CXX_STANDARD)
8+
set(CMAKE_CXX_STANDARD 14)
9+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
set(CMAKE_CXX_EXTENSIONS OFF)
11+
endif()
12+
13+
ament_auto_add_library(shift_decider_node SHARED
14+
src/shift_decider.cpp
15+
)
16+
17+
rclcpp_components_register_node(shift_decider_node
18+
PLUGIN "ShiftDecider"
19+
EXECUTABLE shift_decider
20+
)
21+
22+
if(BUILD_TESTING)
23+
find_package(ament_lint_auto REQUIRED)
24+
ament_lint_auto_find_test_dependencies()
25+
endif()
26+
27+
ament_auto_package(
28+
INSTALL_TO_SHARE
29+
launch
30+
)

control/shift_decider/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Shift Decider
2+
3+
## Purpose
4+
5+
`shift_decider` is a module to decide shift from ackermann control command.
6+
7+
## Inner-workings / Algorithms
8+
9+
### Flow chart
10+
11+
```plantuml
12+
@startuml
13+
skinparam monochrome true
14+
15+
title update current shift
16+
start
17+
if (absolute target velocity is less than threshold) then (yes)
18+
:set previous shift;
19+
else(no)
20+
if (target velocity is positive) then (yes)
21+
:set shift DRIVE;
22+
else
23+
:set shift REVERSE;
24+
endif
25+
endif
26+
:publish current shift;
27+
note right
28+
publish shift for constant interval
29+
end note
30+
stop
31+
@enduml
32+
```
33+
34+
### Algorithms
35+
36+
## Inputs / Outputs
37+
38+
### Input
39+
40+
| Name | Type | Description |
41+
| --------------------- | ---------------------------------------------------------- | ---------------------------- |
42+
| `~/input/control_cmd` | `autoware_auto_control_msgs::msg::AckermannControlCommand` | Control command for vehicle. |
43+
44+
### Output
45+
46+
| Name | Type | Description |
47+
| ------------------- | ---------------------------------------------- | ---------------------------------- |
48+
| `~output/shift_cmd` | `autoware_auto_vehicle_msgs::msg::GearCommand` | Gear for drive forward / backward. |
49+
50+
## Parameters
51+
52+
none.
53+
54+
## Assumptions / Known limits
55+
56+
TBD.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2020 Tier IV, Inc.
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 SHIFT_DECIDER__SHIFT_DECIDER_HPP_
16+
#define SHIFT_DECIDER__SHIFT_DECIDER_HPP_
17+
18+
#include <rclcpp/rclcpp.hpp>
19+
20+
#include <autoware_auto_control_msgs/msg/ackermann_control_command.hpp>
21+
#include <autoware_auto_vehicle_msgs/msg/gear_command.hpp>
22+
23+
#include <memory>
24+
25+
class ShiftDecider : public rclcpp::Node
26+
{
27+
public:
28+
explicit ShiftDecider(const rclcpp::NodeOptions & node_options);
29+
30+
private:
31+
void onTimer();
32+
void onControlCmd(autoware_auto_control_msgs::msg::AckermannControlCommand::SharedPtr msg);
33+
void updateCurrentShiftCmd();
34+
void initTimer(double period_s);
35+
36+
rclcpp::Publisher<autoware_auto_vehicle_msgs::msg::GearCommand>::SharedPtr pub_shift_cmd_;
37+
rclcpp::Subscription<autoware_auto_control_msgs::msg::AckermannControlCommand>::SharedPtr
38+
sub_control_cmd_;
39+
rclcpp::TimerBase::SharedPtr timer_;
40+
41+
autoware_auto_control_msgs::msg::AckermannControlCommand::SharedPtr control_cmd_;
42+
autoware_auto_vehicle_msgs::msg::GearCommand shift_cmd_;
43+
};
44+
45+
#endif // SHIFT_DECIDER__SHIFT_DECIDER_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<launch>
2+
<node pkg="shift_decider" exec="shift_decider" name="shift_decider" output="screen">
3+
<remap from="input/control_cmd" to="/control/trajectory_follower/control_cmd" />
4+
<remap from="output/gear_cmd" to="/control/shift_decider/gear_cmd" />
5+
</node>
6+
</launch>

control/shift_decider/package.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<package format="2">
3+
<name>shift_decider</name>
4+
<version>0.1.0</version>
5+
<description>The shift_decider package</description>
6+
<maintainer email="horibe.takamasa@gmail.com">Takamasa Horibe</maintainer>
7+
<author email="horibe.takamasa@gmail.com">Takamasa Horibe</author>
8+
<license>Apache License 2.0</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<depend>autoware_auto_control_msgs</depend>
13+
<depend>autoware_auto_vehicle_msgs</depend>
14+
<depend>rclcpp</depend>
15+
<depend>rclcpp_components</depend>
16+
17+
<test_depend>ament_cmake_cppcheck</test_depend>
18+
<test_depend>ament_cmake_cpplint</test_depend>
19+
<test_depend>ament_lint_auto</test_depend>
20+
21+
<export>
22+
<build_type>ament_cmake</build_type>
23+
</export>
24+
25+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2020 Tier IV, Inc.
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+
#include "shift_decider/shift_decider.hpp"
16+
17+
#include <rclcpp/timer.hpp>
18+
19+
#include <cstddef>
20+
#include <functional>
21+
#include <memory>
22+
#include <utility>
23+
24+
ShiftDecider::ShiftDecider(const rclcpp::NodeOptions & node_options)
25+
: Node("shift_decider", node_options)
26+
{
27+
using std::placeholders::_1;
28+
29+
static constexpr std::size_t queue_size = 1;
30+
rclcpp::QoS durable_qos(queue_size);
31+
durable_qos.transient_local();
32+
33+
pub_shift_cmd_ =
34+
create_publisher<autoware_auto_vehicle_msgs::msg::GearCommand>("output/gear_cmd", durable_qos);
35+
sub_control_cmd_ = create_subscription<autoware_auto_control_msgs::msg::AckermannControlCommand>(
36+
"input/control_cmd", queue_size, std::bind(&ShiftDecider::onControlCmd, this, _1));
37+
38+
initTimer(0.1);
39+
}
40+
41+
void ShiftDecider::onControlCmd(
42+
autoware_auto_control_msgs::msg::AckermannControlCommand::SharedPtr msg)
43+
{
44+
control_cmd_ = msg;
45+
}
46+
47+
void ShiftDecider::onTimer()
48+
{
49+
if (!control_cmd_) {
50+
return;
51+
}
52+
53+
updateCurrentShiftCmd();
54+
pub_shift_cmd_->publish(shift_cmd_);
55+
}
56+
57+
void ShiftDecider::updateCurrentShiftCmd()
58+
{
59+
using autoware_auto_vehicle_msgs::msg::GearCommand;
60+
61+
shift_cmd_.stamp = now();
62+
static constexpr double vel_threshold = 0.01; // to prevent chattering
63+
if (control_cmd_->longitudinal.speed > vel_threshold) {
64+
shift_cmd_.command = GearCommand::DRIVE;
65+
} else if (control_cmd_->longitudinal.speed < -vel_threshold) {
66+
shift_cmd_.command = GearCommand::REVERSE;
67+
}
68+
}
69+
70+
void ShiftDecider::initTimer(double period_s)
71+
{
72+
auto timer_callback = std::bind(&ShiftDecider::onTimer, this);
73+
const auto period_ns =
74+
std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>(period_s));
75+
timer_ = std::make_shared<rclcpp::GenericTimer<decltype(timer_callback)>>(
76+
this->get_clock(), period_ns, std::move(timer_callback),
77+
this->get_node_base_interface()->get_context());
78+
this->get_node_timers_interface()->add_timer(timer_, nullptr);
79+
}
80+
81+
#include <rclcpp_components/register_node_macro.hpp>
82+
RCLCPP_COMPONENTS_REGISTER_NODE(ShiftDecider)

0 commit comments

Comments
 (0)