Skip to content

Commit 70ddd1a

Browse files
committed
feat(autoware_twist2accel): port autoware_twist2accel from Autoware Universe
Signed-off-by: Ryohsuke Mitsudome <ryohsuke.mitsudome@tier4.jp>
1 parent fbce570 commit 70ddd1a

File tree

9 files changed

+406
-0
lines changed

9 files changed

+406
-0
lines changed

Diff for: localization/autoware_twist2accel/CHANGELOG.rst

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2+
Changelog for package autoware_twist2accel
3+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
5+
0.43.0 (2025-03-21)
6+
-------------------
7+
* Merge remote-tracking branch 'origin/main' into chore/bump-version-0.43
8+
* chore: rename from `autoware.universe` to `autoware_universe` (`#10306 <https://github.com/autowarefoundation/autoware_universe/issues/10306>`_)
9+
* Contributors: Hayato Mizushima, Yutaka Kondo
10+
11+
0.42.0 (2025-03-03)
12+
-------------------
13+
14+
0.41.2 (2025-02-19)
15+
-------------------
16+
* chore: bump version to 0.41.1 (`#10088 <https://github.com/autowarefoundation/autoware_universe/issues/10088>`_)
17+
* Contributors: Ryohsuke Mitsudome
18+
19+
0.41.1 (2025-02-10)
20+
-------------------
21+
22+
0.41.0 (2025-01-29)
23+
-------------------
24+
* Merge remote-tracking branch 'origin/main' into tmp/bot/bump_version_base
25+
* chore(autoware_twist2accel): remove an unused dependency (`#9881 <https://github.com/autowarefoundation/autoware_universe/issues/9881>`_)
26+
Removed an unused dependency
27+
* feat: tier4_debug_msgs changed to autoware_internal_debug_msgs in files localization/autoware_twist2accel (`#9868 <https://github.com/autowarefoundation/autoware_universe/issues/9868>`_)
28+
Co-authored-by: SakodaShintaro <shintaro.sakoda@tier4.jp>
29+
* Contributors: Fumiya Watanabe, SakodaShintaro, Vishal Chauhan
30+
31+
0.40.0 (2024-12-12)
32+
-------------------
33+
* Revert "chore(package.xml): bump version to 0.39.0 (`#9587 <https://github.com/autowarefoundation/autoware_universe/issues/9587>`_)"
34+
This reverts commit c9f0f2688c57b0f657f5c1f28f036a970682e7f5.
35+
* fix: fix ticket links in CHANGELOG.rst (`#9588 <https://github.com/autowarefoundation/autoware_universe/issues/9588>`_)
36+
* chore(package.xml): bump version to 0.39.0 (`#9587 <https://github.com/autowarefoundation/autoware_universe/issues/9587>`_)
37+
* chore(package.xml): bump version to 0.39.0
38+
* fix: fix ticket links in CHANGELOG.rst
39+
* fix: remove unnecessary diff
40+
---------
41+
Co-authored-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
42+
* fix: fix ticket links in CHANGELOG.rst (`#9588 <https://github.com/autowarefoundation/autoware_universe/issues/9588>`_)
43+
* 0.39.0
44+
* update changelog
45+
* fix: fix ticket links to point to https://github.com/autowarefoundation/autoware_universe (`#9304 <https://github.com/autowarefoundation/autoware_universe/issues/9304>`_)
46+
* fix: fix ticket links to point to https://github.com/autowarefoundation/autoware_universe (`#9304 <https://github.com/autowarefoundation/autoware_universe/issues/9304>`_)
47+
* chore(package.xml): bump version to 0.38.0 (`#9266 <https://github.com/autowarefoundation/autoware_universe/issues/9266>`_) (`#9284 <https://github.com/autowarefoundation/autoware_universe/issues/9284>`_)
48+
* unify package.xml version to 0.37.0
49+
* remove system_monitor/CHANGELOG.rst
50+
* add changelog
51+
* 0.38.0
52+
---------
53+
* Contributors: Esteve Fernandez, Fumiya Watanabe, Ryohsuke Mitsudome, Yutaka Kondo
54+
55+
0.39.0 (2024-11-25)
56+
-------------------
57+
* fix: fix ticket links to point to https://github.com/autowarefoundation/autoware_universe (`#9304 <https://github.com/autowarefoundation/autoware_universe/issues/9304>`_)
58+
* fix: fix ticket links to point to https://github.com/autowarefoundation/autoware_universe (`#9304 <https://github.com/autowarefoundation/autoware_universe/issues/9304>`_)
59+
* chore(package.xml): bump version to 0.38.0 (`#9266 <https://github.com/autowarefoundation/autoware_universe/issues/9266>`_) (`#9284 <https://github.com/autowarefoundation/autoware_universe/issues/9284>`_)
60+
* unify package.xml version to 0.37.0
61+
* remove system_monitor/CHANGELOG.rst
62+
* add changelog
63+
* 0.38.0
64+
---------
65+
* Contributors: Esteve Fernandez, Yutaka Kondo
66+
67+
0.38.0 (2024-11-08)
68+
-------------------
69+
* unify package.xml version to 0.37.0
70+
* refactor(signal_processing): prefix package and namespace with autoware (`#8541 <https://github.com/autowarefoundation/autoware_universe/issues/8541>`_)
71+
* fix(autoware_twist2accel): fix funcArgNamesDifferent (`#8391 <https://github.com/autowarefoundation/autoware_universe/issues/8391>`_)
72+
fix:funcArgNamesDifferent
73+
* refactor(twist2accel)!: prefix package and namespace with autoware (`#8299 <https://github.com/autowarefoundation/autoware_universe/issues/8299>`_)
74+
* add autoware\_ prefix
75+
* add autoware\_ prefix
76+
* add autoware\_ prefix
77+
---------
78+
Co-authored-by: SakodaShintaro <shintaro.sakoda@tier4.jp>
79+
* Contributors: Esteve Fernandez, Masaki Baba, Yutaka Kondo, kobayu858
80+
81+
0.26.0 (2024-04-03)
82+
-------------------

Diff for: localization/autoware_twist2accel/CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(autoware_twist2accel)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
ament_auto_add_library(${PROJECT_NAME} SHARED
8+
src/twist2accel.cpp
9+
)
10+
11+
rclcpp_components_register_node(${PROJECT_NAME}
12+
PLUGIN "autoware::twist2accel::Twist2Accel"
13+
EXECUTABLE ${PROJECT_NAME}_node
14+
EXECUTOR SingleThreadedExecutor
15+
)
16+
17+
ament_auto_package(
18+
INSTALL_TO_SHARE
19+
launch
20+
config
21+
)

Diff for: localization/autoware_twist2accel/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# autoware_twist2accel
2+
3+
## Purpose
4+
5+
This package is responsible for estimating acceleration using the output of `ekf_localizer`. It uses lowpass filter to mitigate the noise.
6+
7+
## Inputs / Outputs
8+
9+
### Input
10+
11+
| Name | Type | Description |
12+
| ------------- | ------------------------------------------------ | --------------------- |
13+
| `input/odom` | `nav_msgs::msg::Odometry` | localization odometry |
14+
| `input/twist` | `geometry_msgs::msg::TwistWithCovarianceStamped` | twist |
15+
16+
### Output
17+
18+
| Name | Type | Description |
19+
| -------------- | ------------------------------------------------ | ---------------------- |
20+
| `output/accel` | `geometry_msgs::msg::AccelWithCovarianceStamped` | estimated acceleration |
21+
22+
## Parameters
23+
24+
{{ json_to_markdown("localization/autoware_twist2accel/schema/twist2accel.schema.json") }}
25+
26+
## Future work
27+
28+
Future work includes integrating acceleration into the EKF state.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**:
2+
ros__parameters:
3+
use_odom: true
4+
accel_lowpass_gain: 0.9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<launch>
2+
<arg name="param_file" default="$(find-pkg-share autoware_twist2accel)/config/twist2accel.param.yaml"/>
3+
4+
<arg name="in_odom" default="in_odom"/>
5+
<arg name="in_twist" default="in_twist"/>
6+
<arg name="out_accel" default="out_accel"/>
7+
<node pkg="autoware_twist2accel" exec="autoware_twist2accel_node" output="both">
8+
<remap from="input/odom" to="$(var in_odom)"/>
9+
<remap from="input/twist" to="$(var in_twist)"/>
10+
<remap from="output/accel" to="$(var out_accel)"/>
11+
<param from="$(var param_file)"/>
12+
</node>
13+
</launch>

Diff for: localization/autoware_twist2accel/package.xml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>autoware_twist2accel</name>
5+
<version>0.43.0</version>
6+
<description>The acceleration estimation package</description>
7+
<maintainer email="yamato.ando@tier4.jp">Yamato Ando</maintainer>
8+
<maintainer email="masahiro.sakamoto@tier4.jp">Masahiro Sakamoto</maintainer>
9+
<maintainer email="kento.yabuuchi.2@tier4.jp">Kento Yabuuchi</maintainer>
10+
<maintainer email="anh.nguyen.2@tier4.jp">NGUYEN Viet Anh</maintainer>
11+
<maintainer email="taiki.yamada@tier4.jp">Taiki Yamada</maintainer>
12+
<maintainer email="shintaro.sakoda@tier4.jp">Shintaro Sakoda</maintainer>
13+
<maintainer email="ryu.yamamoto@tier4.jp">Ryu Yamamoto</maintainer>
14+
<license>Apache License 2.0</license>
15+
<author email="koji.minoda@tier4.jp">Koji Minoda</author>
16+
17+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
18+
<buildtool_depend>autoware_cmake</buildtool_depend>
19+
20+
<depend>autoware_signal_processing</depend>
21+
<depend>geometry_msgs</depend>
22+
<depend>nav_msgs</depend>
23+
<depend>rclcpp</depend>
24+
<depend>rclcpp_components</depend>
25+
<depend>tf2</depend>
26+
27+
<test_depend>ament_cmake_ros</test_depend>
28+
<test_depend>ament_lint_auto</test_depend>
29+
<test_depend>autoware_lint_common</test_depend>
30+
31+
<export>
32+
<build_type>ament_cmake</build_type>
33+
</export>
34+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "Parameters for twist2accel Nodes",
4+
"type": "object",
5+
"definitions": {
6+
"twist2accel": {
7+
"type": "object",
8+
"properties": {
9+
"use_odom": {
10+
"type": "boolean",
11+
"default": true,
12+
"description": "use odometry if true, else use twist input."
13+
},
14+
"accel_lowpass_gain": {
15+
"type": "number",
16+
"default": 0.9,
17+
"minimum": 0.0,
18+
"description": "lowpass gain for lowpass filter in estimating acceleration."
19+
}
20+
},
21+
"required": ["use_odom", "accel_lowpass_gain"]
22+
}
23+
},
24+
"properties": {
25+
"/**": {
26+
"type": "object",
27+
"properties": {
28+
"ros__parameters": {
29+
"$ref": "#/definitions/twist2accel"
30+
}
31+
},
32+
"required": ["ros__parameters"]
33+
}
34+
},
35+
"required": ["/**"]
36+
}
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright 2022 TIER IV
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 "twist2accel.hpp"
16+
17+
#include <rclcpp/logging.hpp>
18+
19+
#include <algorithm>
20+
#include <functional>
21+
#include <memory>
22+
#include <string>
23+
#include <utility>
24+
25+
using autoware::signal_processing::LowpassFilter1d;
26+
27+
namespace autoware::twist2accel
28+
{
29+
using std::placeholders::_1;
30+
31+
Twist2Accel::Twist2Accel(const rclcpp::NodeOptions & node_options)
32+
: rclcpp::Node("twist2accel", node_options)
33+
{
34+
sub_odom_ = create_subscription<nav_msgs::msg::Odometry>(
35+
"input/odom", 1, std::bind(&Twist2Accel::callback_odometry, this, _1));
36+
sub_twist_ = create_subscription<geometry_msgs::msg::TwistWithCovarianceStamped>(
37+
"input/twist", 1, std::bind(&Twist2Accel::callback_twist_with_covariance, this, _1));
38+
39+
pub_accel_ = create_publisher<geometry_msgs::msg::AccelWithCovarianceStamped>("output/accel", 1);
40+
41+
prev_twist_ptr_ = nullptr;
42+
accel_lowpass_gain_ = declare_parameter<double>("accel_lowpass_gain");
43+
use_odom_ = declare_parameter<bool>("use_odom");
44+
45+
lpf_alx_ptr_ = std::make_shared<LowpassFilter1d>(accel_lowpass_gain_);
46+
lpf_aly_ptr_ = std::make_shared<LowpassFilter1d>(accel_lowpass_gain_);
47+
lpf_alz_ptr_ = std::make_shared<LowpassFilter1d>(accel_lowpass_gain_);
48+
lpf_aax_ptr_ = std::make_shared<LowpassFilter1d>(accel_lowpass_gain_);
49+
lpf_aay_ptr_ = std::make_shared<LowpassFilter1d>(accel_lowpass_gain_);
50+
lpf_aaz_ptr_ = std::make_shared<LowpassFilter1d>(accel_lowpass_gain_);
51+
}
52+
53+
void Twist2Accel::callback_odometry(const nav_msgs::msg::Odometry::SharedPtr msg)
54+
{
55+
if (!use_odom_) return;
56+
57+
geometry_msgs::msg::TwistStamped twist;
58+
twist.header = msg->header;
59+
twist.twist = msg->twist.twist;
60+
estimate_accel(std::make_shared<geometry_msgs::msg::TwistStamped>(twist));
61+
}
62+
63+
void Twist2Accel::callback_twist_with_covariance(
64+
const geometry_msgs::msg::TwistWithCovarianceStamped::SharedPtr msg)
65+
{
66+
if (use_odom_) return;
67+
68+
geometry_msgs::msg::TwistStamped twist;
69+
twist.header = msg->header;
70+
twist.twist = msg->twist.twist;
71+
estimate_accel(std::make_shared<geometry_msgs::msg::TwistStamped>(twist));
72+
}
73+
74+
void Twist2Accel::estimate_accel(const geometry_msgs::msg::TwistStamped::SharedPtr msg)
75+
{
76+
geometry_msgs::msg::AccelWithCovarianceStamped accel_msg;
77+
accel_msg.header = msg->header;
78+
79+
if (prev_twist_ptr_ != nullptr) {
80+
const double dt = std::max(
81+
(rclcpp::Time(msg->header.stamp) - rclcpp::Time(prev_twist_ptr_->header.stamp)).seconds(),
82+
1.0e-3);
83+
84+
double alx = (msg->twist.linear.x - prev_twist_ptr_->twist.linear.x) / dt;
85+
double aly = (msg->twist.linear.y - prev_twist_ptr_->twist.linear.y) / dt;
86+
double alz = (msg->twist.linear.z - prev_twist_ptr_->twist.linear.z) / dt;
87+
double aax = (msg->twist.angular.x - prev_twist_ptr_->twist.angular.x) / dt;
88+
double aay = (msg->twist.angular.y - prev_twist_ptr_->twist.angular.y) / dt;
89+
double aaz = (msg->twist.angular.z - prev_twist_ptr_->twist.angular.z) / dt;
90+
91+
accel_msg.accel.accel.linear.x = lpf_alx_ptr_->filter(alx);
92+
accel_msg.accel.accel.linear.y = lpf_aly_ptr_->filter(aly);
93+
accel_msg.accel.accel.linear.z = lpf_alz_ptr_->filter(alz);
94+
accel_msg.accel.accel.angular.x = lpf_aax_ptr_->filter(aax);
95+
accel_msg.accel.accel.angular.y = lpf_aay_ptr_->filter(aay);
96+
accel_msg.accel.accel.angular.z = lpf_aaz_ptr_->filter(aaz);
97+
98+
// Ideally speaking, these covariance should be properly estimated.
99+
accel_msg.accel.covariance[0 * 6 + 0] = 1.0;
100+
accel_msg.accel.covariance[1 * 6 + 1] = 1.0;
101+
accel_msg.accel.covariance[2 * 6 + 2] = 1.0;
102+
accel_msg.accel.covariance[3 * 6 + 3] = 0.05;
103+
accel_msg.accel.covariance[4 * 6 + 4] = 0.05;
104+
accel_msg.accel.covariance[5 * 6 + 5] = 0.05;
105+
}
106+
107+
pub_accel_->publish(accel_msg);
108+
prev_twist_ptr_ = msg;
109+
}
110+
} // namespace autoware::twist2accel
111+
112+
#include <rclcpp_components/register_node_macro.hpp>
113+
RCLCPP_COMPONENTS_REGISTER_NODE(autoware::twist2accel::Twist2Accel)

0 commit comments

Comments
 (0)