-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(control_data_collecting_tool): add constant acceleration/actuati…
…on mode (#185) * Add actuation mode Signed-off-by: Yoshihiro Kogure <[email protected]> * Temporarily added data_collecting_pure_pursuit_trajectory_follower.py Signed-off-by: Yoshihiro Kogure <[email protected]> * Remove data_collecting_pure_pursuit_trajectory_follower.py Signed-off-by: Yoshihiro Kogure <[email protected]> * Add constant cmd scripts Signed-off-by: Yoshihiro Kogure <[email protected]> * Add pedal threshold for data counting Signed-off-by: Yoshihiro Kogure <[email protected]> * pre-commit run Signed-off-by: Yoshihiro Kogure <[email protected]> * Add some comments Signed-off-by: Yoshihiro Kogure <[email protected]> * Update install programs Signed-off-by: Yoshihiro Kogure <[email protected]> * Update params Signed-off-by: Yoshihiro Kogure <[email protected]> * pre-commit run Signed-off-by: Yoshihiro Kogure <[email protected]> * Update README Signed-off-by: Yoshihiro Kogure <[email protected]> * The bullet points were changed from numbers to letters. Signed-off-by: Yoshihiro Kogure <[email protected]> * Update print message Signed-off-by: Yoshihiro Kogure <[email protected]> * Fix bug and typo Signed-off-by: Yoshihiro Kogure <[email protected]> * Update README Signed-off-by: Yoshihiro Kogure <[email protected]> * pre-commit run Signed-off-by: Yoshihiro Kogure <[email protected]> * Update control_data_collecting_tool/README.md --------- Signed-off-by: Yoshihiro Kogure <[email protected]> Co-authored-by: Kosuke Takeuchi <[email protected]>
- Loading branch information
1 parent
6492e0f
commit e4d32ad
Showing
27 changed files
with
2,645 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
control_data_collecting_tool/config/constant_cmd_param/acceleration_cmd_param.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/data_collecting_acceleration_cmd: | ||
ros__parameters: | ||
# params for data_collecting_acceleration_cmd | ||
TARGET_VELOCITY: 11.80 | ||
TARGET_ACCELERATION_FOR_DRIVE: 1.5 | ||
TARGET_ACCELERATION_FOR_BRAKE: -1.5 | ||
TARGET_JERK_FOR_DRIVE: 1.5 | ||
TARGET_JERK_FOR_BRAKE: -1.5 | ||
MIN_ACCEL: -5.0 | ||
MAX_ACCEL: 2.0 | ||
topics: | ||
- /vehicle/status/velocity_status | ||
- /control/command/actuation_cmd | ||
- /sensing/imu/imu_data | ||
- /vehicle/status/control_mode | ||
validation_nodes: | ||
- /data_collecting_pure_pursuit_trajectory_follower_acceleration_cmd |
16 changes: 16 additions & 0 deletions
16
control_data_collecting_tool/config/constant_cmd_param/actuation_cmd_param.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/data_collecting_actuation_cmd: | ||
ros__parameters: | ||
# params for data_collecting_actuation_cmd | ||
TARGET_VELOCITY: 11.80 | ||
TARGET_ACTUATION_FOR_ACCEL: 0.3 | ||
TARGET_ACTUATION_FOR_BRAKE: 0.5 | ||
MAX_ACCEL_PEDAL: 0.5 | ||
MIN_BRAKE_PEDAL: 0.8 | ||
topics: | ||
- /vehicle/status/velocity_status | ||
- /control/command/control_cmd | ||
- /sensing/imu/imu_data | ||
- /vehicle/status/control_mode | ||
validation_nodes: | ||
- /raw_vehicle_cmd_converter | ||
- /data_collecting_pure_pursuit_trajectory_follower_actuation_cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 133 additions & 0 deletions
133
control_data_collecting_tool/scripts/accel_brake_map.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2024 Proxima Technology Inc, TIER IV | ||
# | ||
# 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. | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from scipy.interpolate import RegularGridInterpolator | ||
|
||
|
||
class MapConverter: | ||
def __init__(self, path_to_map): | ||
# Load map data from CSV and initialize grid values | ||
map_df = pd.read_csv(path_to_map, delimiter=",", header=0) | ||
self.map_grid = map_df.to_numpy()[:, 1:] | ||
|
||
# Extract velocity grid from column headers | ||
self.velocity_grid_map = np.array(map_df.columns[1:], dtype=float) | ||
self.max_vel_of_map = self.velocity_grid_map[-1] | ||
self.min_vel_of_map = self.velocity_grid_map[0] | ||
|
||
# Extract pedal grid from the first column | ||
self.pedal_grid_map = map_df.to_numpy()[:, 0] | ||
self.max_pedal_of_map = self.pedal_grid_map[-1] | ||
self.min_pedal_of_map = self.pedal_grid_map[0] | ||
|
||
# Create an interpolator for the map grid | ||
self.map_grid_interpolator = RegularGridInterpolator( | ||
(self.pedal_grid_map, self.velocity_grid_map), self.map_grid | ||
) | ||
|
||
def pedal_to_accel_input(self, pedal, velocity): | ||
# Convert pedal input and velocity to acceleration input using interpolation | ||
pedal = np.clip(pedal, self.min_pedal_of_map, self.max_pedal_of_map) | ||
velocity = np.clip(velocity, self.min_vel_of_map, self.max_vel_of_map) | ||
accel_input = self.map_grid_interpolator([pedal, velocity])[0] | ||
|
||
return accel_input | ||
|
||
def accel_input_to_pedal(self, accel_input, velocity): | ||
# Convert acceleration input and velocity to pedal input | ||
velocity = np.clip(velocity, self.min_vel_of_map, self.max_vel_of_map) | ||
|
||
# Find velocity interval for interpolation | ||
vel_idx = 0 | ||
alpha = 0.0 | ||
for i in range(len(self.velocity_grid_map) - 1): | ||
vel_left_grid = self.velocity_grid_map[i] | ||
vel_right_grid = self.velocity_grid_map[i + 1] | ||
|
||
if vel_left_grid <= velocity <= vel_right_grid: | ||
vel_idx = i | ||
alpha = (velocity - vel_left_grid) / (vel_right_grid - vel_left_grid) | ||
|
||
# Interpolate acceleration input map for given velocity | ||
accel_input_map = ( | ||
alpha * self.map_grid[:, vel_idx] + (1 - alpha) * self.map_grid[:, vel_idx + 1] | ||
) | ||
|
||
# Clip acceleration input within the bounds of the map | ||
min_accel_map = np.min([accel_input_map[0], accel_input_map[-1]]) | ||
max_accel_map = np.max([accel_input_map[0], accel_input_map[-1]]) | ||
accel_input = np.clip(accel_input, min_accel_map, max_accel_map) | ||
|
||
# Find corresponding pedal input using interpolation | ||
actuation_input = 0.0 | ||
for i in range(len(accel_input_map) - 1): | ||
if accel_input_map[i] <= accel_input_map[i + 1]: | ||
# Increasing interval | ||
if accel_input_map[i] <= accel_input <= accel_input_map[i + 1]: | ||
delta_accel_input = accel_input_map[i + 1] - accel_input_map[i] | ||
if abs(delta_accel_input) < 1e-3: | ||
actuation_input = self.pedal_grid_map[i] | ||
else: | ||
beta = (accel_input - accel_input_map[i]) / delta_accel_input | ||
actuation_input = ( | ||
beta * self.pedal_grid_map[i + 1] + (1 - beta) * self.pedal_grid_map[i] | ||
) | ||
elif accel_input_map[i + 1] < accel_input_map[i]: | ||
# Decreasing interval | ||
sign = -1 | ||
if accel_input_map[i + 1] <= accel_input <= accel_input_map[i]: | ||
delta_accel_input = accel_input_map[i] - accel_input_map[i + 1] | ||
if abs(delta_accel_input) < 1e-3: | ||
actuation_input = sign * self.pedal_grid_map[i] | ||
else: | ||
beta = (accel_input - accel_input_map[i + 1]) / delta_accel_input | ||
actuation_input = sign * ( | ||
beta * self.pedal_grid_map[i] + (1 - beta) * self.pedal_grid_map[i + 1] | ||
) | ||
|
||
return actuation_input | ||
|
||
|
||
class AccelBrakeMapConverter: | ||
def __init__(self, path_to_accel_map, path_to_brake_map): | ||
# Initialize converters for acceleration and brake maps | ||
self.accel_map_converter = MapConverter(path_to_accel_map) | ||
self.brake_map_converter = MapConverter(path_to_brake_map) | ||
|
||
def convert_accel_input_to_actuation_cmd(self, accel_input, velocity): | ||
# Convert acceleration input to actuation command | ||
accel_actuation_cmd = self.accel_map_converter.accel_input_to_pedal(accel_input, velocity) | ||
brake_actuation_cmd = self.brake_map_converter.accel_input_to_pedal(accel_input, velocity) | ||
|
||
return accel_actuation_cmd - brake_actuation_cmd | ||
|
||
def convert_actuation_cmd_to_accel_input(self, actuation_cmd, velocity): | ||
# Convert actuation command to acceleration input | ||
accel_input = 0.0 | ||
if actuation_cmd > 0.0: | ||
# Positive command corresponds to acceleration | ||
accel_input = self.accel_map_converter.pedal_to_accel_input( | ||
abs(actuation_cmd), velocity | ||
) | ||
if actuation_cmd <= 0.0: | ||
# Negative command corresponds to braking | ||
accel_input = self.brake_map_converter.pedal_to_accel_input( | ||
abs(actuation_cmd), velocity | ||
) | ||
|
||
return accel_input |
Oops, something went wrong.