diff --git a/.devcontainer/.env.example b/.devcontainer/.env.example new file mode 100644 index 0000000..06fe735 --- /dev/null +++ b/.devcontainer/.env.example @@ -0,0 +1,7 @@ +# This files is meant to be used as an example for the .env file, +# which sets the username variable for the dev container +# You should duplicate this file, change the name of the copy to +# '.env' and edit the variable's value +# This might not be necessary for linux +USERNAME=your_username # Necessary for windows at least +# If it doesnt work, include "export USERNAME=your_username" in the Dockerfile diff --git a/.devcontainer/.gitignore b/.devcontainer/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.devcontainer/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..0fb55eb --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,40 @@ +FROM ros:iron-ros-base-jammy +ARG USERNAME=USERNAME +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Create the user +RUN groupadd --gid "$USER_GID" "$USERNAME" \ + && useradd --uid "$USER_UID" --gid "$USER_GID" -m "$USERNAME" \ + # + # [Optional] Add sudo support. Omit if you don't need to install software after connecting. + && apt-get update \ + && apt-get install -y sudo \ + && echo "$USERNAME" ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/"$USERNAME" \ + && chmod 0440 /etc/sudoers.d/"$USERNAME" \ + && apt-get clean + +# Install dependencies +RUN apt update && apt upgrade -y \ + && apt install -y python3-pip \ + && apt install ros-"$ROS_DISTRO"-rviz2 -y \ + && apt install openssh-client -y \ + && apt install openssh-server -y \ + && apt install git -y \ + && apt install vim -y \ + && apt install python-is-python3 -y \ + && apt install clang-format -y \ + && apt install bear -y \ + && apt install curl -y \ + && curl -s https://deb.nodesource.com/setup_16.x | sudo bash \ + && apt install nodejs -y \ + && pip install black \ + && pip install rosbags \ + && pip install PyQT5 \ + && apt install ros-$ROS_DISTRO-xacro -y \ + && apt clean + +RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> /home/"$USERNAME"/.bashrc +ENV SHELL /bin/bash +USER $USERNAME +CMD ["/bin/bash"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..b7f114a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,51 @@ +{ + "name": "ROS 2 Development Container", + "privileged": true, + "remoteUser": "${localEnv:USERNAME}", + "build": { + "dockerfile": "Dockerfile", + "args": { + "USERNAME": "${localEnv:USERNAME}" + } + }, + "features": { + "ghcr.io/itsmechlark/features/act:1": {}, + "ghcr.io/devcontainers/features/docker-in-docker:2": {} + }, + "workspaceFolder": "/home/ws", + "workspaceMount": "source=${localWorkspaceFolder},target=/home/ws,type=bind", + "customizations": { + "vscode": { + "extensions":[ + "ms-vscode.cpptools", + "ms-azuretools.vscode-docker", + "ms-vscode.cpptools-extension-pack", + "twxs.cmake", + "donjayamanne.python-extension-pack", + "eamodio.gitlens", + "ms-iot.vscode-ros", + "GitHub.vscode-github-actions" + ] + } + }, + "containerEnv": { + "DISPLAY": "unix:0", + "ROS_AUTOMATIC_DISCOVERY_RANGE": "LOCALHOST", + "ROS_DOMAIN_ID": "42" + }, + "runArgs": [ + "--net=host", + "--ipc=host", + "--pid=host", + "-e", "DISPLAY=${env:DISPLAY}" + ], + "mounts": [ + "source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind,consistency=cached", + "source=/dev/dri,target=/dev/dri,type=bind,consistency=cached", + "source=${localWorkspaceFolder}/cache/iron-ros-base-jammy/build,target=/home/ws/build,type=bind", + "source=${localWorkspaceFolder}/cache/iron-ros-base-jammy/install,target=/home/ws/install,type=bind", + "source=${localWorkspaceFolder}/cache/iron-ros-base-jammy/log,target=/home/ws/log,type=bind" + ], + "postCreateCommand": "sudo apt update && rosdep update && rosdep install --from-paths src --ignore-src -y && sudo chown -R ${localEnv:USERNAME} /home/ws/", + "initializeCommand": "echo Initialize...." +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 720ac47..b090b59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ +**/build/* +**/install/* +**/log/* +*.db3 +!.vscode/settings.json +!.vscode/c_cpp_properties.json .vscode/* -__pycache__/ \ No newline at end of file +__pycache__/ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..d870c8f --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "/opt/ros/iron/include/**", + "/usr/include/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..cad7657 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cmake.configureOnOpen": false +} \ No newline at end of file diff --git a/README.md b/README.md index b7ec658..29d668d 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,11 @@ We provide an example launch file (example.launch.py) which shows an example of The sensors and vehicle model are configured using config files. Examples are provided in the config folder. Things such as the discipline or the path of the track file or config files are defined using ros2 parameters. -The default vehicle model provided is rather simple and just meant to be a starting point. You are encouraged to integrate your own vehicle model by implementing the `IVehicleModel` class +The default vehicle model provided is rather simple and just meant to be a starting point. You are encouraged to integrate your own vehicle model by implementing the `IVehicleModel` class. + +## Docker Dev Container + +A [Dockerfile](./.devcontainer/Dockerfile) is configured that already contains all the dependencies. It can be used with a [dev container environment](./.devcontainer) or launched independently wiht the [docker-compose](./docker-compose.yml) file. For more info, check the [docs folder](./doc/docker_usage.md). # Contributing Contributions in any form (reports, feedback, requests, submissions) are welcome. Preferably create an Issue or Pull request for that. @@ -51,4 +55,4 @@ The initial version was developed at Elbflorace by: * Alexander Phieler (Main development) * Niklas Leukroth (Track and Config file parser) * Sergio Antuna (Artwork) -* Tim Hanel (3d car model integration) \ No newline at end of file +* Tim Hanel (3d car model integration) diff --git a/config/mainConfig.yaml b/config/mainConfig.yaml index b2e723d..b9b9c4d 100644 --- a/config/mainConfig.yaml +++ b/config/mainConfig.yaml @@ -1,6 +1,6 @@ pacsim: timeouts: - start: 60 # time to trigger first timekeeping gate + start: 300 # time to trigger first timekeeping gate acceleration: 25 autocross: 300 skidpad: 90 @@ -10,8 +10,6 @@ pacsim: doo_detect: true uss_detect: true finish_validate: true - - cog_frame_id_pipeline: "cog" # name of the cog frame in the autnomous pipeline + cog_frame_id_pipeline: "car" # name of the cog frame in the autnomous pipeline broadcast_sensors_tf2: true - - pre_transform_track: true # transform track such that starting pose also seems to be the origin of the track \ No newline at end of file + pre_transform_track: true # transform track such that starting pose also seems to be the origin of the track diff --git a/config/perception.yaml b/config/perception.yaml index 464ef70..e904d3c 100644 --- a/config/perception.yaml +++ b/config/perception.yaml @@ -10,7 +10,7 @@ perception_sensors: orientation: [0.0,0.0,0.0] observation: min_range: 1 - max_range: 45 + max_range: 20 min_angle_horizontal: -1.0472 max_angle_horizontal: 1.0472 min_angle_vertical: -0.2181662 @@ -18,8 +18,8 @@ perception_sensors: detection: prob_min_dist: 0.99 - prob_decrease_dist_linear: 0.01 - prob_decrease_dist_quadratic: 0.00012 + prob_decrease_dist_linear: 0.001 + prob_decrease_dist_quadratic: 0.000012 min_prob: 0.1 classification: diff --git a/doc/docker_usage.md b/doc/docker_usage.md new file mode 100644 index 0000000..f6212c3 --- /dev/null +++ b/doc/docker_usage.md @@ -0,0 +1,32 @@ +# How to use + +## Docker Compose + +The simulator is inside a docker container, which by running it, the simulator will also be launched. To do this, run the following command on your terminal: + +```bash +docker compose up +``` + +The *docker-compose.yml* file uses the same Docker image as the development container (Image in [.devcontainer folder](../.devcontainer)) and executes the [entrypoint.sh script](./entrypoint.sh) at startup. + +## Code Development - Dev Container + +In case you want to do some work inside the container, by using the Dev Containers extension in VSCode the process becomes very simple, since there is a .devcontainer which contains the configuration for a development container for that purpose. + +To run this, first you need to install some extensions. You can get them through here [Remote Development Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack). +Then you need to create some cache folders. This can be done by running the following commands: + +```bash +./environment_setup.sh +``` +Finally do Ctrl + Shift + P and choose the option: + +- Dev Containers: Rebuild and Reopen in container + +## General Notes + +For the simulator to communicate with your system, make sure to set the ROS Domain ID to the same value in both systems: +```sh +export ROS_DOMAIN_ID=42 +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..305c036 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +services: + pacsim: + container_name: pacsim-container + image: pacsim-pacsim + build: + context: . + dockerfile: .devcontainer/Dockerfile + args: + USERNAME: "${USERNAME}" + environment: + DISPLAY: "${DISPLAY}" + ROS_AUTOMATIC_DISCOVERY_RANGE: "LOCALHOST" + ROS_DOMAIN_ID: "42" + volumes: + - type: bind + source: "./" + target: /home/ws + - type: bind + source: "/tmp/.X11-unix" + target: "/tmp/.X11-unix" + consistency: cached + - type: bind + source: "/dev/dri" + target: "/dev/dri" + consistency: cached + - type: bind + source: "./cache/iron-ros-base-jammy/build" + target: "/home/ws/build" + - type: bind + source: "./cache/iron-ros-base-jammy/install" + target: "/home/ws/install" + - type: bind + source: "./cache/iron-ros-base-jammy/log" + target: "/home/ws/log" + network_mode: host + ipc: host + pid: host + command: > + bash -c "cd /home/ws/ && ./entrypoint.sh" + + diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..d0461fb --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,11 @@ +#! /bin/bash +sudo apt update && +rosdep update && +rosdep install --from-paths src --ignore-src -y && +colcon build & + +wait $! + +cd /home/ws/ && +source ./install/setup.bash && +ros2 launch pacsim example.launch.py diff --git a/environment_setup.sh b/environment_setup.sh new file mode 100755 index 0000000..aa20f49 --- /dev/null +++ b/environment_setup.sh @@ -0,0 +1,4 @@ +#!/bin/sh +mkdir -p ./cache/iron-ros-base-jammy/build +mkdir -p ./cache/iron-ros-base-jammy/install +mkdir -p ./cache/iron-ros-base-jammy/log \ No newline at end of file diff --git a/launch/example.launch.py b/launch/example.launch.py index 709d314..335ca02 100644 --- a/launch/example.launch.py +++ b/launch/example.launch.py @@ -52,8 +52,6 @@ def generate_launch_description(): executable='robot_state_publisher', name='robot_state_publisher', output='screen', - parameters=[{'use_sim_time':True}, {'publish_frequency':float(1000), - 'robot_description': Command(['xacro',' ',xacro_path]) - }], + parameters=[{'use_sim_time':True}, {'publish_frequency':float(1000),}], arguments=[xacro_path]) return LaunchDescription([nodePacsim, nodePacsimShutdownEventHandler, robot_state_publisher]) \ No newline at end of file diff --git a/src/VehicleModel/VehicleModelBicycle.cpp b/src/VehicleModel/VehicleModelBicycle.cpp index e81b535..3c7234c 100644 --- a/src/VehicleModel/VehicleModelBicycle.cpp +++ b/src/VehicleModel/VehicleModelBicycle.cpp @@ -123,13 +123,13 @@ class VehicleModelBicycle : public IVehicleModel double avgRatio = 0.5 * (this->innerSteeringRatio + this->outerSteeringRatio); if (in > 0) { - this->steeringAngles.FL = this->innerSteeringRatio * in; - this->steeringAngles.FR = this->outerSteeringRatio * in; + this->steeringAngles.FL = this->innerSteeringRatio * in / avgRatio; + this->steeringAngles.FR = this->outerSteeringRatio * in / avgRatio; } else { - this->steeringAngles.FL = this->outerSteeringRatio * in; - this->steeringAngles.FR = this->innerSteeringRatio * in; + this->steeringAngles.FL = this->outerSteeringRatio * in / avgRatio; + this->steeringAngles.FR = this->innerSteeringRatio * in / avgRatio; } return; } @@ -179,7 +179,7 @@ class VehicleModelBicycle : public IVehicleModel Eigen::Vector3d vFront = vCog + omega.cross(rFront); Eigen::Vector3d vRear = vCog + omega.cross(rRear); - double rpm2ms = this->wheelRadius * 2.0 * M_PI / (this->gearRatio * 60.0); + double rpm2ms = this->wheelRadius * 2.0 * M_PI / 60; bool stillstand = (vCog.norm() < 0.1) && (std::abs(this->angularVelocity.z()) < 0.001); diff --git a/track_editor/README.md b/track_editor/README.md new file mode 100644 index 0000000..a0dbd39 --- /dev/null +++ b/track_editor/README.md @@ -0,0 +1,14 @@ +# Track Generator + +## Dependencies + +- PyQT5 (```pip install PyQT5```) + +## Using + +To run the track generator: + +```sh +cd track_editor # if you are not in this folder already +python main.py +``` diff --git a/urdf/separate_model.xacro b/urdf/separate_model.xacro index 7f3f89c..8e0f397 100644 --- a/urdf/separate_model.xacro +++ b/urdf/separate_model.xacro @@ -10,7 +10,7 @@ - + @@ -19,7 +19,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -36,7 +36,7 @@ - + @@ -44,7 +44,7 @@ - + @@ -52,7 +52,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -68,7 +68,7 @@ - + @@ -76,7 +76,7 @@ - +