diff --git a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/.pages b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/.pages index b8ce748b7cf..b685d1ce9f8 100644 --- a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/.pages +++ b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/.pages @@ -1,3 +1,5 @@ nav: - - Creating a vehicle interface for an Ackermann kinematic model: creating-a-vehicle-interface-for-an-ackermann-kinematic-model.md + - Vehicle interface overview: vehicle-interface.md + - creating-vehicle-interface.md + - ackermann-kinematic-model.md - customizing-for-differential-drive-model.md diff --git a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/ackermann-kinematic-model.md b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/ackermann-kinematic-model.md new file mode 100644 index 00000000000..f90b15eb0ce --- /dev/null +++ b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/ackermann-kinematic-model.md @@ -0,0 +1,67 @@ +# Ackermann kinematic model + +Autoware now supports control inputs for vehicles based on an Ackermann kinematic model. +This section introduces you a brief concept of the Ackermann kinematic model +and explains how Autoware controls it. +Please remember, +Autoware control output (/control/command/control_cmd) +publishes lateral and longitudinal commands according to the Ackermann kinematic model. + +- If your vehicle does not suit the Ackermann kinematic model, you have to modify the control commands. [Another document gives you an example how to convert your Ackermann kinematic model control inputs into a differential drive model.](https://autowarefoundation.github.io/autoware-documentation/main/how-to-guides/integrating-autoware/creating-vehicle-interface-package/customizing-for-differential-drive-model/) + +## Geometry + +The basic style of the Ackermann kinematic model has four wheels with an Ackermann link on the front, +and it is powered by the rear wheels. +The key point of Ackermann kinematic model is +that the axes of all wheels intersect at the same point, +which means +all wheels will trace a circular trajectory with a different radii but a common center point +(See the figure below). +Therefore, +this model has a great advantage that it minimizes the slippage of the wheels +and prevents tires from getting worn soon. + +In general, +the Ackermann kinematic model accepts the longitudinal speed $v$ and the steering angle $\phi$ as inputs. +In autoware, $\phi$ is positive if it is steered counterclockwise, +so the steering angle in the figure below is actually negative. + +
+ ![ackermann_link](images/Ackermann_WB.png){ align=center } +
+ The basic style of an Ackermann kinematic model. The left figure shows a vehicle facing straight forward, while the right figure shows a vehicle steering to the right. +
+
+ +### Control + +Autoware publishes a ROS 2 topic named `control_cmd` from several types of publishers. +A `control_cmd` topic is a [`AckermannControlCommand`](https://gitlab.com/autowarefoundation/autoware.auto/autoware_auto_msgs/-/blob/master/autoware_auto_control_msgs/msg/AckermannControlCommand.idl) type message that contains + +```bash title="AckermannControlCommand" + builtin_interfaces/Time stamp + autoware_auto_control_msgs/AckermannLateralCommand lateral + autoware_auto_control_msgs/LongitudinalCommand longitudinal +``` + +where, + +```bash title="AckermannLateralCommand" + builtin_interfaces/Time stamp + float32 steering_tire_angle + float32 steering_tire_rotation_rate +``` + +```bash title="LongitudinalCommand" + builtin_interfaces/Time stamp + float32 speed + float32 accelaration + float32 jerk +``` + +See the [AckermannLateralCommand.idl](https://gitlab.com/autowarefoundation/autoware.auto/autoware_auto_msgs/-/blob/master/autoware_auto_control_msgs/msg/AckermannLateralCommand.idl) and [LongitudinalCommand.idl](https://gitlab.com/autowarefoundation/autoware.auto/autoware_auto_msgs/-/blob/master/autoware_auto_control_msgs/msg/LongitudinalCommand.idl) for details. + +The vehicle interface should realize these control commands through your vehicle's control device. + +Moreover, Autoware also provides brake commands, light commands, and more (see [vehicle interface design](https://autowarefoundation.github.io/autoware-documentation/main/design/autoware-interfaces/components/vehicle-interface/)), so the vehicle interface module should be applicable to these commands as long as there are devices available to handle them. diff --git a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/creating-a-vehicle-interface-for-an-ackermann-kinematic-model.md b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/creating-a-vehicle-interface-for-an-ackermann-kinematic-model.md deleted file mode 100644 index 58eb276071f..00000000000 --- a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/creating-a-vehicle-interface-for-an-ackermann-kinematic-model.md +++ /dev/null @@ -1,244 +0,0 @@ -# Creating a vehicle interface for an Ackermann kinematic model - -This page introduces a module vehicle interface and explains how to implement it. - -## What is a vehicle interface - -Vehicle interface is an interface that connects the control commands and your vehicle's control device. -Autoware publishes control commands such as: - -- Velocity control -- Steering control -- Car light commands - -Then, the vehicle interface converts these commands into actuation such like: - -- Motor and brake activation -- Steering wheel operation -- Lighting control - -So think of the vehicle interface as a module that runs the vehicle's control device to realize the input commands provided by Autoware. - -
- ![vehicle_interface_IO](images/Vehicle-Interface-Bus-ODD-Architecture.drawio.svg){ align=center } -
- An example of inputs and outputs for vehicle interface -
-
- -This page shows you a brief explanation how to implement your vehicle interface, but [you can see further information of vehicle interface in the "design" page](https://autowarefoundation.github.io/autoware-documentation/main/design/autoware-interfaces/components/vehicle-interface/). - -**Note that there is no package named "vehicle interface" prepared in Autoware.** -**It is a necessary package to actuate your vehicle, but you have to create one by yourself since it is very specific to your vehicle's control device.** - -For example, if you are using a by-wire kit [PACMod](https://autonomoustuff.com/platform/pacmod), a vehicle interface named [`pacmod_interface` published by TIER IV, Inc.](https://github.com/tier4/pacmod_interface/tree/main) is available. -However, if you have constructed something original and haven't found an open source vehicle interface applicable, you have to implement your own vehicle interface from scratch. - ---- - -## How to implement a vehicle interface - -The following instructions describe how to create a vehicle interface. - -### 1. Create a directory for vehicle interface - -It is recommended to create your vehicle interface at `/src/vehicle/external` - -```bash -cd /src/vehicle/external -``` - -### 2. Install or implement your own vehicle interface - -If there is an already complete vehicle interface package (like [`pacmod_interface`](https://github.com/tier4/pacmod_interface/tree/main)), you can install it to your environment. -If not, you have to implement your own vehicle interface by yourself. -Let's create a new package by `ros2 pkg create`. -The following example will show you how to create a vehicle interface package named `my_vehicle_interface`. - -```bash -ros2 pkg create --build-type ament_cmake my_vehicle_interface -``` - -Then, you should write your implementation of vehicle interface in `my_vehicle_interface/src`. -Again, since this implementation is so specific to the control device of your vehicle, it is beyond the scope of this document to describe how to implement your vehicle interface in detail. -Here are some factors that might be considered. - -- Subscription of control command topics from Autoware -- Communication between the vehicle interface and your vehicle's control device -- Modification of control values if needed - -### 3. Prepare a launch file - -After you implement your vehicle interface or you want to debug it by launching it, create a launch file of your vehicle interface, and include it to `vehicle_interface.launch.xml`. - -Do not get confused. First, you need to create a launch file for your own vehicle interface module (like `my_vehicle_interface.launch.xml`) **and then include that to `vehicle_interface.launch.xml` which exists in another directory.** Here are the details. - -1. Add a `launch` directory in the `my_vehicle_interface` directory, and create a launch file of your own vehicle interface in it. Take a look at [Creating a launch file](https://docs.ros.org/en/humble/Tutorials/Intermediate/Launch/Launch-Main.html) in the ROS 2 documentation. - -2. Next, go to `/src/vehicle`, copy the directory `/sample_vehicle_launch/`, and paste it to the same place (which means it should be lined up with `external` and `sample_vehicle_launch`). - -3. You have to rename each "sample_vehicle" to something else. For example, if you want to rename "sample_vehicle" to "my_vehicle_name", you need to change the following. Note that it is restricted to keep the "\_launch" and "\_description" part. - - - **Rename the directories** - - `sample_vehicle_launch` → `my_vehicle_name_launch` - - `my_vehicle_name_launch/sample_vehicle_launch` → `my_vehicle_name_launch/my_vehicle_name_launch` - - `my_vehicle_name_launch/sample_vehicle_description` → `my_vehicle_name_launch/my_vehicle_name_description` - - **After you rename your directories, rename each "sample_vehicle" to "my_vehicle_name" in the source code.** - - `my_vehicle_name_description/CMakeLists.txt` - - `my_vehicle_name_description/package.xml` - - `my_vehicle_name_description/urdf/vehicle.xacro` (there are two parts) - - `my_vehicle_name_launch/CMakeLists.txt` - - `my_vehicle_name_launch/package.xml` - - `README.md` - -4. Include your launch file to `my_vehicle_name_launch/my_vehicle_name_launch/launch/vehicle_interface.launch.xml` by opening it and add the include terms like below. - -```xml title="vehicle_interface.launch.xml" - - - - - - - -``` - -Finally, your directory structure may look like below. - Most of the files are omitted for clarity, but the files shown here needs modification as said in the previous and current process. - -```diff -/ -└─ src/ - └─ vehicle/ - ├─ external/ -+ │ └─ my_vehicle_interface/ -+ │ ├─ src/ -+ │ └─ launch/ -+ │ └─ my_vehicle_interface.launch.xml - ├─ sample_vehicle_launch/ -+ └─ my_vehicle_name_launch/ (COPIED FROM sample_vehicle_launch) -+ ├─ my_vehicle_name_launch/ -+ │ ├─ launch/ -+ │ │ └─ vehicle_interface.launch.xml -+ │ ├─ CMakeLists.txt -+ │ └─ package.xml -+ ├─ my_vehicle_name_description/ -+ │ ├─ config/ -+ │ ├─ mesh/ -+ │ ├─ urdf/ -+ │ │ └─ vehicle.xacro -+ │ ├─ CMakeLists.txt -+ │ └─ package.xml -+ └─ README.md -``` - -### 4. Build the vehicle interface package and the launch package - -Build three packages `my_vehicle_interface`, `my_vehicle_name_launch` and `my_vehicle_name_description` by `colcon build`, or you can just build the entire Autoware if you have done other things. - -```bash -colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release --packages-select my_vehicle_interface my_vehicle_name_launch my_vehicle_name_description -``` - -### 5. When you launch Autoware - -Finally, you are done implementing your vehicle interface module! Be careful that you need to launch Autoware with the proper `vehicle_model` option like the example below. This example is launching planning simulator. - -```bash -ros2 launch autoware_launch planning.launch.xml map_path:=$HOME/autoware_map/sample-map-planning vehicle_model:=my_vehicle_name sensor_model:=sample_sensor_kit -``` - -### Tips - -There are some tips that may help you. - -- You can subdivide your vehicle interface into smaller packages if you want. Then your directory structure may look like below (not the only way though). Do not forget to launch all packages in `my_vehicle_interface.launch.xml`. - - ```diff - / - └─ src/ - └─ vehicle/ - ├─ external/ - │ └─ my_vehicle_interface/ - │ ├─ src/ - │ │ ├─ package1/ - │ │ ├─ package2/ - │ │ └─ package3/ - │ └─ launch/ - │ └─ my_vehicle_interface.launch.xml - ├─ sample_vehicle_launch/ - └─ my_vehicle_name_launch/ - ``` - -- If you are using a vehicle interface and launch package from a open git repository, or created your own as a git repository, it is highly recommended to add those repositories to your `autoware.repos` file which is located to directly under your autoware folder like the example below. You can specify the branch or commit hash by the version tag. - - ```yaml title="autoware.repos" - # vehicle (this section should be somewhere in autoware.repos and add the below) - vehicle/my_vehicle_name_launch: - type: git - url: https://github.com//my_vehicle_name_launch.git - version: main - vehicle/external/my_vehicle_interface: - type: git - url: https://github.com//my_vehicle_interface.git - version: main - ``` - - Then you can import your entire environment easily to another local device by using the `vcs import` command. (See [the source installation guide](https://autowarefoundation.github.io/autoware-documentation/main/installation/autoware/source-installation/#how-to-set-up-a-workspace)) - ---- - -## Ackermann kinematic model - -Autoware now supports control inputs for vehicles based on an Ackermann kinematic model. -This section introduces you a brief concept of Ackermann kinematic model and explains how Autoware controls it. - -- If your vehicle does not suit the Ackermann kinematic model, you have to modified the control commands. [Another document gives you an example how to convert your Ackermann kinematic model control inputs into a differential drive model.](https://autowarefoundation.github.io/autoware-documentation/main/how-to-guides/integrating-autoware/creating-vehicle-interface-package/customizing-for-differential-drive-model/) - -### Geometry - -The basic style of Ackermann kinematic model has four wheels with an Ackermann link on the front, and it is powered by the rear wheels. -The key point of Ackermann kinematic model is that the axes of all wheels intersect at a same point, which means all wheels will trace a circular trajectory with a different radii but a common center point (See the figure below). -Therefore, this model has a great advantage that it minimizes the slippage of the wheels, and prevent tires to get worn soon. - -In general, Ackermann kinematic model accepts the longitudinal speed $v$ and the steering angle $\phi$ as inputs. -In autoware, $\phi$ is positive if it is steered counter clockwise, so the steering angle in the figure below is actually negative. - -
- ![ackermann_link](images/Ackermann_WB.png){ align=center } -
- The basic style of an Ackermann kinematic model. The left figure shows a vehicle facing straight forward, while the right figure shows a vehicle steering to the right. -
-
- -### Control - -Autoware publishes a ROS 2 topic named `control_cmd` from several types of publishers. -A `control_cmd` topic is a [`AckermannControlCommand`](https://gitlab.com/autowarefoundation/autoware.auto/autoware_auto_msgs/-/blob/master/autoware_auto_control_msgs/msg/AckermannControlCommand.idl) type message that contains - -```bash title="AckermannControlCommand" - builtin_interfaces/Time stamp - autoware_auto_control_msgs/AckermannLateralCommand lateral - autoware_auto_control_msgs/LongitudinalCommand longitudinal -``` - -where, - -```bash title="AckermannLateralCommand" - builtin_interfaces/Time stamp - float32 steering_tire_angle - float32 steering_tire_rotation_rate -``` - -```bash title="LongitudinalCommand" - builtin_interfaces/Time stamp - float32 speed - float32 accelaration - float32 jerk -``` - -See the [AckermannLateralCommand.idl](https://gitlab.com/autowarefoundation/autoware.auto/autoware_auto_msgs/-/blob/master/autoware_auto_control_msgs/msg/AckermannLateralCommand.idl) and [LongitudinalCommand.idl](https://gitlab.com/autowarefoundation/autoware.auto/autoware_auto_msgs/-/blob/master/autoware_auto_control_msgs/msg/LongitudinalCommand.idl) for details. - -The vehicle interface should realize these control commands through your vehicle's control device. - -Moreover, Autoware also provides brake commands, light commands, and more (see [vehicle interface design](https://autowarefoundation.github.io/autoware-documentation/main/design/autoware-interfaces/components/vehicle-interface/)), so the vehicle interface module should be applicable to these commands as long as there are devices available to handle them. diff --git a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/creating-vehicle-interface.md b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/creating-vehicle-interface.md new file mode 100644 index 00000000000..cbdbaf085b7 --- /dev/null +++ b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/creating-vehicle-interface.md @@ -0,0 +1,260 @@ +# Creating vehicle interface + +## How to implement a vehicle interface + +The following instructions describe how to create a vehicle interface. + +### 1. Create a directory for vehicle interface + +It is recommended to create your vehicle interface at `/src/vehicle/external` + +```bash +cd /src/vehicle/external +``` + +### 2. Install or implement your own vehicle interface + +If there is an already complete vehicle interface package (like [`pacmod_interface`](https://github.com/tier4/pacmod_interface/tree/main)), you can install it to your environment. +If not, you have to implement your own vehicle interface by yourself. +Let's create a new package by `ros2 pkg create`. +The following example will show you how to create a vehicle interface package named `my_vehicle_interface`. + +```bash +ros2 pkg create --build-type ament_cmake my_vehicle_interface +``` + +Then, you should write your implementation of vehicle interface in `my_vehicle_interface/src`. +Again, since this implementation is so specific to the control device of your vehicle, it is beyond the scope of this document to describe how to implement your vehicle interface in detail. +Here are some factors that might be considered: + +- Some necessary topic subscription of control commands topics from Autoware to control your vehicle: + +| Topic Name | Topic Type | Description | +| ------------------------------------ | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| /control/command/control_cmd | autoware_auto_control_msgs/msg/AckermannControlCommand | This topic includes main topics for controlling our vehicle like a steering tire angle, speed, acceleration, etc. | +| /control/command/gear_cmd | autoware_auto_vehicle_msgs/msg/GearCommand | This topic includes gear command for autonomous driving, please check message values to make sense of gears values. Please check [the message definition](https://github.com/tier4/autoware_auto_msgs/blob/tier4/main/autoware_auto_vehicle_msgs/msg/GearCommand.idl) of this type. | +| /control/current_gate_mode | tier4_control_msgs/msg/GateMode | This topic describes control on the autoware or not. Please check [GateMode](https://github.com/tier4/tier4_autoware_msgs/blob/tier4/universe/tier4_control_msgs/msg/GateMode.msg) message type for detailed information. | +| /control/command/emergency_cmd | tier4_vehicle_msgs/msg/VehicleEmergencyStamped | This topic sends emergency when autoware is on emergency state. Please check [VehicleEmergencyStamped](https://github.com/tier4/tier4_autoware_msgs/blob/tier4/universe/tier4_vehicle_msgs/msg/VehicleEmergencyStamped.msg) message type for detailed information. | +| /control/command/turn_indicators_cmd | autoware_auto_vehicle_msgs/msg/TurnIndicatorsCommand | This topic indicates a turn signal for your own vehicle. Please check [TurnIndicatorsCommand](https://github.com/tier4/autoware_auto_msgs/blob/tier4/main/autoware_auto_vehicle_msgs/msg/TurnIndicatorsCommand.idl) message type for detailed information. | +| /control/command/hazard_lights_cmd | autoware_auto_vehicle_msgs/msg/HazardLightsCommand | This topic sends command for hazard lights. Please check [HazardLightsCommand](https://github.com/tier4/autoware_auto_msgs/blob/tier4/main/autoware_auto_vehicle_msgs/msg/HazardLightsCommand.idl) | +| /control/command/actuation_cmd | tier4_vehicle_msgs/msg/ActuationCommandStamped | This topic is enabled when you use `raw_vehicle_command_converter` for control your vehicle with TYPE B which we mentioned at [Vehicle interface](./vehicle-interface.md) section. In summary, if you are using Type B on your vehicle, this topic appeared and included with gas, brake, steering-wheel actuation commands. Please check [ActuationCommandStamped](https://github.com/tier4/tier4_autoware_msgs/blob/tier4/universe/tier4_vehicle_msgs/msg/ActuationCommandStamped.msg) message type for detailed information. | +| etc. | etc. | etc. | + +- Some necessary topic publication of vehicle status topics from vehicle interface to Autoware: + +| Topic Name | Topic Type | Description | +| -------------------------------------- | --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| /vehicle/status/battery_charge | tier4_vehicle_msgs/msg/BatteryStatus | This topic includes battery information. Please check [BatteryStatus](https://github.com/tier4/tier4_autoware_msgs/blob/tier4/universe/tier4_vehicle_msgs/msg/BatteryStatus.msg) message type for detailed information. You can use this value as describing fuel level, etc. | +| /vehicle/status/control_mode | autoware_auto_vehicle_msgs/msg/ControlModeReport | This topic describes the current control mode of vehicle. Please check [ControlModeReport](https://github.com/tier4/autoware_auto_msgs/blob/tier4/main/autoware_auto_vehicle_msgs/msg/ControlModeReport.idl) message type for detailed information. | +| /vehicle/status/gear_status | autoware_auto_vehicle_msgs/msg/GearReport | This topic includes the current gear status of the vehicle. Please check [GearReport](https://github.com/tier4/autoware_auto_msgs/blob/tier4/main/autoware_auto_vehicle_msgs/msg/GearReport.idl) message type for detailed information. | +| /vehicle/status/hazard_lights_status | autoware_auto_vehicle_msgs/msg/HazardLightsReport | This topic describes hazard light status of the vehicle. Please check [HazardLightsReport](https://github.com/tier4/autoware_auto_msgs/blob/tier4/main/autoware_auto_vehicle_msgs/msg/HazardLightsReport.idl) message type for detailed information. | +| /vehicle/status/turn_indicators_status | autoware_auto_vehicle_msgs/msg/TurnIndicatorsReport | This topic reports the steering status of the vehicle. Please check [SteeringReport](https://github.com/tier4/autoware_auto_msgs/blob/tier4/main/autoware_auto_vehicle_msgs/msg/SteeringReport.idl) message type for detailed information. | +| /vehicle/status/steering_status | autoware_auto_vehicle_msgs/msg/SteeringReport | This topic reports the steering status of the vehicle. Please check [SteeringReport](https://github.com/tier4/autoware_auto_msgs/blob/tier4/main/autoware_auto_vehicle_msgs/msg/SteeringReport.idl) message type for detailed information. | +| /vehicle/status/velocity_Status | autoware_auto_vehicle_msgs/msg/VelocityReport | This topic gives us the velocity status of the vehicle. Please check [VelocityReport](https://github.com/tier4/autoware_auto_msgs/blob/tier4/main/autoware_auto_vehicle_msgs/msg/VelocityReport.idl) message type for detailed information. | +| etc. | etc. | etc. | + +This diagram as an example for communication of vehicle interface and autoware +with describing sample topics and message types. + +
+ ![vehicle_communication](images/autoware-vehicle-communication.svg){ align=center } +
+ Sample demonstration of vehicle and autoware communication. + There are some topics and types included in this diagram and + it can be changed your desired control command or autoware updates. +
+
+ +You must create a subscriber and publisher with these topics on your vehicle interface. +Let's +explain with the simple demonstration of subscribing `/control/command/control_cmd` and publishing `/vehicle/status/gear_status` topics. + +So, your `YOUR-OWN-VEHICLE-INTERFACE.hpp` header file should be like this: + +```c++ +... +#include +#include +... + +class : public rclcpp::Node +{ +public: + ... +private: + ... + // from autoware + rclcpp::Subscription::SharedPtr + control_cmd_sub_; + ... + // from vehicle + rclcpp::Publisher::SharedPtr gear_status_pub_; + ... + // autoware command messages + ... + autoware_auto_control_msgs::msg::AckermannControlCommand::ConstSharedPtr control_cmd_ptr_; + ... + // callbacks + ... + void callback_control_cmd( + const autoware_auto_control_msgs::msg::AckermannControlCommand::ConstSharedPtr msg); + ... + void to_vehicle(); + void from_vehicle(); +} +``` + +And your `YOUR-OWN-VEHICLE-INTERFACE.cpp` .cpp file should be like this: + +```c++ +#include /.hpp> +... + +::() +: Node("") +{ + ... + /* subscribers */ + using std::placeholders::_1; + // from autoware + control_cmd_sub_ = create_subscription( + "/control/command/control_cmd", 1, std::bind(&::callback_control_cmd, this, _1)); + ... + // to autoware + gear_status_pub_ = create_publisher( + "/vehicle/status/gear_status", rclcpp::QoS{1}); + ... +} + +void ::callback_control_cmd( + const autoware_auto_control_msgs::msg::AckermannControlCommand::ConstSharedPtr msg) +{ + control_cmd_ptr_ = msg; +} + +void ::to_vehicle() +{ + ... + // you should implement this structure according to your own vehicle design + control_command_to_vehicle(control_cmd_ptr_); + ... +} + +void ::to_autoware() +{ + ... + // you should implement this structure according to your own vehicle design + autoware_auto_vehicle_msgs::msg::GearReport gear_report_msg; + convert_gear_status_to_autoware_msg(gear_report_msg); + gear_status_pub_->publish(gear_report_msg); + ... +} + +``` + +- Modification of control values if needed + - In some cases, you may need to modify the control commands. For example, Autoware expects vehicle velocity information in m/s units, but if your vehicle publishes it in a different format (i.e., km/h), you must convert it before sending it to Autoware. + +### 3. Prepare a launch file + +After you implement your vehicle interface, or you want to debug it by launching it, +create a launch file of your vehicle interface, +and include it to `vehicle_interface.launch.xml` which included in `_vehicle_launch` package +that we forked and created +at [creating vehicle and sensor description page](../creating-vehicle-and-sensor-description/creating-vehicle-and-sensor-description.md). + +Do not get confused. First, you need to create a launch file for your own vehicle interface module (like `my_vehicle_interface.launch.xml`) **and then include that to `vehicle_interface.launch.xml` which exists in another directory.** Here are the details. + +1. Add a `launch` directory in the `my_vehicle_interface` directory, and create a launch file of your own vehicle interface in it. Take a look at [Creating a launch file](https://docs.ros.org/en/humble/Tutorials/Intermediate/Launch/Launch-Main.html) in the ROS 2 documentation. + +2. Include your launch file which is created for vehicle_interface to `_launch/_launch/launch/vehicle_interface.launch.xml` by opening it and add the included terms like below. + +```xml title="vehicle_interface.launch.xml" + + + + + + + +``` + +Finally, your directory structure may look like below. +Most of the files are omitted for clarity, but the files shown here needs modification as said in the previous and current process. + +```diff +/ +└─ src/ + └─ vehicle/ + ├─ external/ ++ │ └─ _interface/ ++ │ ├─ src/ ++ │ └─ launch/ ++ │ └─ my_vehicle_interface.launch.xml ++ └─ _launch/ (COPIED FROM sample_vehicle_launch) ++ ├─ _launch/ ++ │ ├─ launch/ ++ │ │ └─ vehicle_interface.launch.xml ++ │ ├─ CMakeLists.txt ++ │ └─ package.xml ++ ├─ _description/ ++ │ ├─ config/ ++ │ ├─ mesh/ ++ │ ├─ urdf/ ++ │ │ └─ vehicle.xacro ++ │ ├─ CMakeLists.txt ++ │ └─ package.xml ++ └─ README.md +``` + +### 4. Build the vehicle interface package and the launch package + +Build three packages `my_vehicle_interface`, `_launch` +and `_description` by `colcon build`, +or you can just build the entire Autoware if you have done other things. + +```bash +colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release --packages-select my_vehicle_interface _launch _description +``` + +### 5. When you launch Autoware + +Finally, you are done implementing your vehicle interface module! Be careful that you need to launch Autoware with the proper `vehicle_model` option like the example below. This example is launching planning simulator. + +```bash +ros2 launch autoware_launch planning.launch.xml map_path:=$HOME/autoware_map/sample-map-planning vehicle_model:= sensor_model:=_sensor_kit +``` + +### Tips + +There are some tips that may help you. + +- You can subdivide your vehicle interface into smaller packages if you want. Then your directory structure may look like below (not the only way though). Do not forget to launch all packages in `my_vehicle_interface.launch.xml`. + + ```diff + / + └─ src/ + └─ vehicle/ + ├─ external/ + │ └─ my_vehicle_interface/ + │ ├─ src/ + │ │ ├─ package1/ + │ │ ├─ package2/ + │ │ └─ package3/ + │ └─ launch/ + │ └─ my_vehicle_interface.launch.xml + ├─ sample_vehicle_launch/ + └─ my_vehicle_name_launch/ + ``` + +- If you are using a vehicle interface and launch package from a open git repository, or created your own as a git repository, it is highly recommended to add those repositories to your `autoware.repos` file which is located to directly under your autoware folder like the example below. You can specify the branch or commit hash by the version tag. + + ```yaml title="autoware.repos" + # vehicle (this section should be somewhere in autoware.repos and add the below) + vehicle/external/my_vehicle_interface: + type: git + url: https://github.com//my_vehicle_interface.git + version: main + ``` + + Then you can import your entire environment easily to another local device by using the `vcs import` command. (See [the source installation guide](https://autowarefoundation.github.io/autoware-documentation/main/installation/autoware/source-installation/#how-to-set-up-a-workspace)) diff --git a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/customizing-for-differential-drive-model.md b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/customizing-for-differential-drive-model.md index fd833f3cf50..3627c30f06e 100644 --- a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/customizing-for-differential-drive-model.md +++ b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/customizing-for-differential-drive-model.md @@ -3,9 +3,23 @@ ## 1. Introduction Currently, Autoware assumes that vehicles use an Ackermann kinematic model with Ackermann steering. -Thus, Autoware adopts the Ackermann command format for the Control module's output (see [the AckermannDrive ROS message definition](http://docs.ros.org/en/api/ackermann_msgs/html/msg/AckermannDrive.html) for an overview of Ackermann commands, and [the AckermannControlCommands struct](https://gitlab.com/autowarefoundation/autoware.auto/autoware_auto_msgs/-/blob/master/autoware_auto_control_msgs/msg/AckermannControlCommand.idl) used in Autoware for more details). - -However, it is possible to integrate Autoware with a vehicle that follows a differential drive kinematic model, as commonly used by small mobile robots. +Thus, Autoware adopts the Ackermann command format for the Control module's output +(see [the AckermannDrive ROS message definition](http://docs.ros.org/en/api/ackermann_msgs/html/msg/AckermannDrive.html) for an overview of Ackermann commands, +and [the AckermannControlCommands struct](https://gitlab.com/autowarefoundation/autoware.auto/autoware_auto_msgs/-/blob/master/autoware_auto_control_msgs/msg/AckermannControlCommand.idl) +used in Autoware for more details). + +However, +it is possible to integrate Autoware with a vehicle +that follows a differential drive kinematic model, +as commonly used by small mobile robots. +The differential vehicles can be either four-wheel or two-wheel, as described in the figure below. + +
+ ![differential_vehicle](images/differential_vehicle.svg){ align=center } +
+ Sample differential vehicles with four-wheel and two-wheel models. +
+
## 2. Procedure @@ -36,7 +50,26 @@ $$ where $l$ denotes wheel tread. -For information about other factors that need to be considered when creating a `vehicle_interface` package, refer to the [`vehicle_interface` component page](../../../design/autoware-interfaces/components/vehicle-interface.md). +Here is the example `.cpp` snippet +for converting ackermann model kinematics to a differential model: + +```c++ +... +void convert_ackermann_to_differential( + autoware_auto_control_msgs::msg::AckermannControlCommand & ackermann_msg + my_vehicle_msgs::msg::DifferentialCommand & differential_command) +{ + differential_command.left_wheel.velocity = + ackermann_msg.longitudinal.speed - (ackermann_msg.lateral.steering_tire_angle * my_wheel_tread) / 2; + differential_command.right_wheel.velocity = + ackermann_msg.longitudinal.speed + (ackermann_msg.lateral.steering_tire_angle * my_wheel_tread) / 2; +} +... +``` + +For information about other factors +that need to be considered when creating a `vehicle_interface` package, +refer to the [creating `vehicle_interface` page](./creating-vehicle-interface.md). ### 2.2 Set an appropriate `wheel_base` diff --git a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/images/autoware-vehicle-communication.svg b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/images/autoware-vehicle-communication.svg new file mode 100644 index 00000000000..e057e99b8b4 --- /dev/null +++ b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/images/autoware-vehicle-communication.svg @@ -0,0 +1,4 @@ + + + +
autoware.universe
autoware.universe
topic: /control/command/control_cmd
topic: /control/command/control_cmd

type: 
autoware_auto_control_msgs/
msg/AckermannControlCommand
type:...
topic: /control/command/gear_cmd
topic: /control/command/gear_cmd

type: 
autoware_auto_vehicle_msgs/
msg/GearCommand
type:...
topic: /control/command/turn_indicators_cmd
topic: /control/command/turn_indicators_cmd
type: 
autoware_auto_vehicle_msgs/
msg/TurnIndicatorsCommand
type:...
topic: /control/command/hazard_lights_cmd
topic: /control/command/hazard_lights_cmd
type: 
autoware_auto_vehicle_msgs/
msg/HazardLightsCommand
type:...
topic: /control/command/emergency_cmd
topic: /control/command/emergency_cmd
type: 
tier4_vehicle_msgs/msg/VehicleEmergencyStamped
type:...
topic: /control/command/emergency_cmd
topic: /control/command/emergency_cmd
type: 
tier4_vehicle_msgs/
msg/VehicleEmergencyStamped
type:...
topic: /control/current_gate_mode
topic: /control/current_gate_mode
type: 
tier4_control_msgs/msg/GateMode
type:...
Vehicle Gate
Vehicle Gate
node: 
/control/vehicle_cmd_gate
node:...
Planning
Planning
node:
ns/behavior_path_planner
node:...
Control
Control
node: 
/control/external_cmd_selector
node:
/control/trajectory_follower/controller_node_exe
...
node:...
hazard_light msgs turn_indicators msgs
hazard_light msgs turn_...
control_cmd msgs
external_command msgs
system msgs
...
control_cmd msgs...
vehicle
vehicle
topic: /vehicle/status/battery_charge
topic: /vehicle/status/battery_charge
type: 
tier4_vehicle_msgs/msg/BatteryStatus
type:...
topic: /vehicle/status/control_mode
topic: /vehicle/status/control_mode
type: 
autoware_auto_vehicle_msgs/msg/ControlModeReport
type:...
topic: /vehicle/status/gear_status
topic: /vehicle/status/gear_status
type: 
autoware_auto_vehicle_msgs/msg/GearReport
type:...
topic: /vehicle/status/hazard_lights_status
topic: /vehicle/status/hazard_lights_status
type: 
autoware_auto_vehicle_msgs/msg/HazardLightsReport
type:...
topic: /vehicle/status/steering_status
topic: /vehicle/status/steering_status
type: 
autoware_auto_vehicle_msgs/msg/SteeringReport
type:...
topic: /vehicle/status/turn_indicators_status
topic: /vehicle/status/turn_indicators_status
type: 
autoware_auto_vehicle_msgs/msg/TurnIndicatorsReport
type:...
topic: /vehicle/status/velocity_status
topic: /vehicle/status/velocity_status
type: 
autoware_auto_vehicle_msgs/msg/VelocityReport
type:...
LOW LEVEL CONTROLLER ACTUATION (CAN, Serial etc.)
LOW LEVEL CONTROLLER ACTUATION (CAN, Serial etc.)
node: 
/<YOUR-OWN-INTERFACE-NODE>
node:...
Vehicle Interface
Vehicle Interface
vehicle_status msgs
vehicle_status msgs
control msgs
control msgs
Text is not SVG - cannot display
\ No newline at end of file diff --git a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/images/differential_vehicle.svg b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/images/differential_vehicle.svg new file mode 100644 index 00000000000..04ad335b294 --- /dev/null +++ b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/images/differential_vehicle.svg @@ -0,0 +1,4 @@ + + + +
Turn Direction
Turn Direction
$$v_r$$
$$v_l$$
$$v_r$$
$$v_l$$
Turn Direction
Turn Direction
Robot 1
Robot 1
Robot 2
Robot 2
Text is not SVG - cannot display
\ No newline at end of file diff --git a/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/vehicle-interface.md b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/vehicle-interface.md new file mode 100644 index 00000000000..24ad28031b2 --- /dev/null +++ b/docs/how-to-guides/integrating-autoware/creating-vehicle-interface-package/vehicle-interface.md @@ -0,0 +1,86 @@ +# Vehicle interface + +## What is the vehicle interface? + +The purpose of the vehicle interface package is to convert the control messages calculated from the autoware into a form that the vehicle can understand and transmit them to the vehicle (CAN, Serial message, etc.) and to decode the data coming from the vehicle and publish it through the ROS 2 topics that the autoware expects. +So, we can say that the purposes of the vehicle_interface are: + +1. Converting Autoware control commands to a vehicle-specific format. Example control commands of autoware: + + - lateral controls: steering tire angle, steering tire rotation rate + - longitudinal controls: speed, acceleration, jerk + +2. Converting vehicle status information in a vehicle-specific format to Autoware messages. + +Autoware publishes control commands such as: + +- Velocity control +- Steering control +- Car light commands +- etc. + +Then, the vehicle interface converts these commands into actuation such like: + +- Motor and brake activation +- Steering-wheel operation +- Lighting control +- etc. + +So think of the vehicle interface as a module that runs the vehicle's control device to realize the input commands provided by Autoware. + +
+ ![vehicle_interface_IO](images/Vehicle-Interface-Bus-ODD-Architecture.drawio.svg){ align=center } +
+ An example of inputs and outputs for vehicle interface +
+
+ +There are two types of interfaces for controlling your own vehicle: + +1. Target steering and target velocity/acceleration interface. (It will be named as Type A for this document) +2. Generalized target command interface (i.e., accel/brake pedal, steering torque). (It will be named as Type B for this document) + +For Type A, +where the control interface encompasses target steering and target velocity/acceleration. + +- So, at this type, speed control is occurred by desired velocity or acceleration. +- Steering control is occurred by desired steering angle and/or steering angle velocity. + +On the other hand, Type B, characterized by a generalized target command interface (e.g., accel/brake pedal, steering torque), +introduces a more dynamic and adaptable control scheme. +In this configuration, +the vehicle +controlled to direct input from autoware actuation commands which output of the `raw_vehicle_cmd_converter`, +allowing for a more intuitive and human-like driving experience. + +If you use your own vehicle like this way +(i.e., controlling gas and brake pedal), +you need +to use [raw_vehicle_cmd_converter](https://github.com/autowarefoundation/autoware.universe/tree/main/vehicle/raw_vehicle_cmd_converter) package +to convert autoware output control cmd to brake, gas and steer map. +In order to do that, you will need brake, gas and steering calibration. +So, +you can get the calibration with using [accel_brake_map_calibrator](https://github.com/autowarefoundation/autoware.universe/tree/main/vehicle/accel_brake_map_calibrator/accel_brake_map_calibrator) package. +Please follow the steps for calibration your vehicle actuation. + +The choice between these control interfaces profoundly influences the design and development process. +If you are planning to use Type A, +then you will control velocity or acceleration over drive by-wire systems. +If type B is more suitable for your implementation, +then you will need to control your vehicle's brake and gas pedal. + +### Communication between the vehicle interface and your vehicle's control device + +- If you are planning to drive by autoware with your vehicle, then your vehicle must satisfy some requirements: + +| Type A | Type B | +| ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | +| Your vehicle can be controlled in longitudinal direction by the target velocity or acceleration. | Your vehicle can be controlled in longitudinal direction by the specific target commands. (i.e., brake and gas pedal) | +| Your vehicle can be controlled in lateral direction by the target steering angle. (Optionally, you can use steering rate as well) | Your vehicle can be controlled in lateral direction by the specific target commands. (i.e., steering torque) | +| Your vehicle must provide velocity or acceleration information and steering information which is described at the vehicle status topics above. | Your vehicle must provide velocity or acceleration information and steering information which is described at the vehicle status topics above. | + +- You can also use mixed Type A and Type B, for example, you want to use lateral controlling with a steering angle and longitudinal controlling with specific targets. In order to do that, you must subscribe `/control/command/control_cmd` for getting steering information, and you must subscribe `/control/command/actuation_cmd` for gas and brake pedal actuation commands. Then, you must handle these messages on your own vehicle_interface design. +- You must adopt your vehicle low-level controller to run with autoware. +- Your vehicle can be controlled by the target shift mode and also needs to provide Autoware with shift information. +- If you are using CAN communication on your vehicle, please refer to [ros2_socketcan](https://github.com/autowarefoundation/ros2_socketcan) package by Autoware. +- If you are using Serial communication on your vehicle, you can look at [serial-port](https://github.com/fedetft/serial-port/tree/master/3_async).