Skip to content

Commit

Permalink
refactor(smart_mpc_trajectory_folower): modify pacakge structure and …
Browse files Browse the repository at this point in the history
…install without setup.py (#8268)

* refactor(smart_mpc_trajectory_follower): modify pacakge structure and install without setup.py

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

* import proxima calc

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

* use ament_get_python_install_dir

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

* add <depend>python3-torch</depend>

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

* remove pip from readme

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

* remove str conversion from open

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

* sort in cmake

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

---------

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
  • Loading branch information
kosuke55 authored Aug 1, 2024
1 parent 41fca7e commit 13ee518
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 95 deletions.
21 changes: 20 additions & 1 deletion control/autoware_smart_mpc_trajectory_follower/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,31 @@ cmake_minimum_required(VERSION 3.14)
project(autoware_smart_mpc_trajectory_follower)

find_package(autoware_cmake REQUIRED)
find_package(python_cmake_module REQUIRED)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
find_package(pybind11_vendor REQUIRED)
find_package(pybind11 REQUIRED)
find_package(Eigen3 REQUIRED)
autoware_package()

execute_process(COMMAND bash -c "pip3 install numba==0.58.1 --force-reinstall")
execute_process(COMMAND bash -c "pip3 install GPy")

pybind11_add_module(proxima_calc SHARED
${PROJECT_NAME}/src/proxima_calc.cpp
)
ament_target_dependencies(proxima_calc Eigen3)
ament_get_python_install_dir(PYTHON_INSTALL_DIR)
install(TARGETS proxima_calc
LIBRARY DESTINATION ${PYTHON_INSTALL_DIR}/${PROJECT_NAME}
)

ament_python_install_package(${PROJECT_NAME})
install(PROGRAMS
autoware_smart_mpc_trajectory_follower/scripts/pympc_trajectory_follower.py
scripts/pympc_trajectory_follower.py
DESTINATION lib/${PROJECT_NAME}
)
ament_auto_package(
INSTALL_TO_SHARE
autoware_smart_mpc_trajectory_follower/param
)
14 changes: 0 additions & 14 deletions control/autoware_smart_mpc_trajectory_follower/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ This technology makes it relatively easy to operate model predictive control, wh
</a>
</p>

## Setup

After building autoware, move to `control/autoware_smart_mpc_trajectory_follower` and run the following command:

```bash
pip3 install .
```

If you have already installed and want to update the package, run the following command instead:

```bash
pip3 install -U .
```

## Provided features

This package provides smart MPC logic for path-following control as well as mechanisms for learning and evaluation. These features are described below.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.


from autoware_smart_mpc_trajectory_follower import proxima_calc
from autoware_smart_mpc_trajectory_follower.scripts import drive_functions
from autoware_smart_mpc_trajectory_follower.scripts import proxima_calc
import numpy as np
import torch
from torch import nn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,21 @@

"""Define primary parameters and functions to be used elsewhere."""
from functools import partial
import json
import os
from pathlib import Path
import sys
from typing import Callable

from ament_index_python.packages import get_package_share_directory
from numba import njit
import numpy as np
import yaml

package_path_json = str(Path(__file__).parent.parent) + "/package_path.json"
with open(package_path_json, "r") as file:
package_path = json.load(file)
PACKAGE_NAME = "autoware_smart_mpc_trajectory_follower"

mpc_param_path = (
package_path["path"] + "/autoware_smart_mpc_trajectory_follower/param/mpc_param.yaml"
)
param_path = Path(get_package_share_directory(PACKAGE_NAME)) / "param"

mpc_param_path = param_path / "mpc_param.yaml"
with open(mpc_param_path, "r") as yml:
mpc_param = yaml.safe_load(yml)

Expand Down Expand Up @@ -102,9 +100,7 @@

cap_pred_error = np.array(mpc_param["mpc_parameter"]["preprocessing"]["cap_pred_error"])

nominal_param_path = (
package_path["path"] + "/autoware_smart_mpc_trajectory_follower/param/nominal_param.yaml"
)
nominal_param_path = param_path / "nominal_param.yaml"
with open(nominal_param_path, "r") as yml:
nominal_param = yaml.safe_load(yml)
# Vehicle body information given by default.
Expand Down Expand Up @@ -173,10 +169,7 @@
)
max_error_steer = float(mpc_param["mpc_parameter"]["compensation"]["max_error_steer"])


trained_model_param_path = (
package_path["path"] + "/autoware_smart_mpc_trajectory_follower/param/trained_model_param.yaml"
)
trained_model_param_path = param_path / "trained_model_param.yaml"
with open(trained_model_param_path, "r") as yml:
trained_model_param = yaml.safe_load(yml)
use_trained_model_diff = bool(
Expand Down Expand Up @@ -370,31 +363,12 @@
)
# upper limit of input


package_path_split = str(package_path["path"]).split("/")
control_dir_path = ""
for i in range(len(package_path_split)):
control_dir_path += package_path_split[i]
if package_path_split[i] == "control":
break
control_dir_path += "/"

read_limit_file = bool(mpc_param["mpc_parameter"]["limit"]["read_limit_file"])
if read_limit_file:
limit_yaml_path = None
for curDir, dirs, files in os.walk(control_dir_path):
for name in files:
if name == "vehicle_cmd_gate.param.yaml":
if curDir.split("/")[-2] == "autoware_vehicle_cmd_gate":
limit_yaml_path = curDir + "/" + name
break

limit_params = None
if limit_yaml_path is not None:
with open(limit_yaml_path, "r") as yml:
limit_params = yaml.safe_load(yml)
else:
print("Error: limit_yaml_path is None")
limitter_package_path = Path(get_package_share_directory("autoware_vehicle_cmd_gate"))
limit_yaml_path = limitter_package_path / "config" / "vehicle_cmd_gate.param.yaml"
with open(limit_yaml_path, "r") as yml:
limit_params = yaml.safe_load(yml)

if limit_params is not None:
reference_speed_points = np.array(
Expand Down
2 changes: 2 additions & 0 deletions control/autoware_smart_mpc_trajectory_follower/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
<depend>autoware_planning_msgs</depend>
<depend>autoware_system_msgs</depend>
<depend>autoware_universe_utils</depend>
<depend>autoware_vehicle_cmd_gate</depend>
<depend>autoware_vehicle_msgs</depend>
<depend>pybind11_vendor</depend>
<depend>python3-scipy</depend>
<depend>python3-torch</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>

Expand Down
42 changes: 0 additions & 42 deletions control/autoware_smart_mpc_trajectory_follower/setup.py

This file was deleted.

0 comments on commit 13ee518

Please sign in to comment.