This is the github repository for thedevelopment of the F1TENTH 3D Environment based on unity.
- Download this repo
$ git clone https://github.com/mlab-upenn/f1tenth-3D_environment.git- Install Unity Editor through unity hub. The project is developed under Unity Version: 2019.3.0f1
- Install the dependecies in the
requirements.txtaspip install -r requirements.txt - Install the gym environment
$ cd f1tenth_gym-camera_dev_billy
$ pip3 install --user -e gym/- Start the Unity Build at
ZeroMQ_Bridge/Build/v0.x86_64 - In the root folder, type the following command which would start two cars racing.
cd f1tenth_gym-camera_dev_billy/examples
python3 waypoint_follow_multi.py- Click the button
Switch Methodfor one car racing - In the root folder, type the following command which would start one car racing.
cd f1tenth_gym-camera_dev_billy/examples
python3 waypoint_follow_single.py- Start Unity project
Unity_ZeroMQand open theZeroMQ_Demoscene through unity hub which you installed before, and click thePlaybutton. - In the root folder, type the following command which would start two cars racing.
cd f1tenth_gym-camera_dev_billy/examples
python3 waypoint_follow_multi.py- In the unity
Playmode, one can click the buttonSwitch Methodfor one car racing - In the root folder, type the following command which would start one car racing.
cd f1tenth_gym-camera_dev_billy/examples
python3 waypoint_follow_single.py- Under the
ROS_catkin_wsbuild the relevant packages
catkin_make
source /devel/setup.bash
- Bring up Websocket, F1tenth simulator, a simple controller. Go to the terminal that bring up F1tenth simulator, press
nto get the vehicle run
roslaunch rosbridge_server rosbridge_websocket.launch
roslaunch f1tenth_simulator simulator.launch
rosrun wall_following xiaozhou_zhang_wallfollow.py
- Bring up the bridge from F1tenth to Unity and Unity to F1tenth
rosrun unity_bridge posePublisher.py
rosrun unity_bridge test_listener_ros.py
- Start Unity project
Unity_ROS_Bridgeand open theROS_Bridge_Demoscene and click thePlaybutton
The ZeroMQ_Bridge has the structure as
- ZeroMQ_Bridge
/* demo zmq code for the gym */
- Python_ZeroMQ
/* demo zmq client code receiving img from the unity side. used for reference in the gym environment */
- client.py
/* demo zmq server code sending pos info to the unity side. used for reference in the gym environment */
- server.py
/* Unity files */
- Unity_ZeroMQ
- Assets // used Unity assets //
- ARCADE - FREE Racing Car // car model assets
- Concrete textures pack // concrete wall material
- Free // wall model assets
- Maps // maps used in the gym side
- Materials // other materials
- Plugins // ZeroMQ plugins
- Prefabs // ground and wall prefabs
- Scenes // saved ZeroMQ_Demo scene
- Scripts // used scripts
- CameraC.cs // mount the camera onto the car and follow its translation and orientation
- MapReader.cs // read the map from ../Maps and generate the walls on the floor
- Publisher.cs // publish the camera img to the gym side
- Subscriber.cs // subscribe the location and orientation info of the car from the gym side
- SwitchMethod // a button for switching between one car racing and two cars racing
- Other derivativesThe scene has the following hierarchy
- MapReader // an empty object loading MapReader.cs
- Plane // the floor object
- Player1 // car#1
- Main Camera // cam mounted on car#1
- ZmqConnector // empty object loading Publisher.cs and Subscriber.cs for car#1
- Free_Racing_Car_Blue // car model object for car#1
- Player2 // car#2
- Main Camera2 // cam mounted on car#2
- ZmqConnector2 // empty object loading Publisher.cs and Subscriber.cs for car#2
- Free_Racing_Car_Red // car model object for car#1
- Canvas // canvas for the switching button
- Button // switch methond
- EventSystem // system object for switching function- MapReader.cs
Map // the same map file from the gym with the config below
Wall Object // object for generating the wall
Material // wall material
Resolution // the same map resolution of the gym side- CameraC.cs
Target // the mounted car's transform
Offset Position // the translation between cam's frame and the car's frameFor the physical camera stats, one can refer to Unity Physical Cameras and the Inspector info listed on the camera object. The FPS is 30.
- Publisher.cs
PortNum // zmq port num for publishing img to the gym side. hardcoded as 12346 now on the gym side
Image Camera // the camera object
Resolution Width/Height // camera resolution
Quality level // published img qualityIt refers to this repo.
- Subscriber.cs
Player // the car object
PortNum // zmq port num for subscribing car's pose fromt he gym side. hardcoded as 12345 now on the gym sideIt refers to this repo.
- SwitchMethod.cs
Second Car // the car#2 objectThe car model and floor/wall materials I used in downloaded from the Unity Asset Store. One can access to the Unity Asset Store in the Unity Editor. In the navigation bar, click Window -> Asset Store.
Once you visit the Asset Store, you can search for the assests you need. For example you can type car in the search bar and download the asset you want.
When you done so, go to My Assets by clicking the avatar on the up right corner, and import the asset you download to your project.
Car model: In the scene hierarchy, you need to switch the Free_Racing_Car car object to your assets in Player1/Player2. And in the ZmqConnector object, add the car object to the params of Subscriber.cs. In the Main Camera object, add the car's transform to the params of CameraC.cs.
Material: To change the material of the floor, you can go to the Plane object. Under the Mesh Renderer property on the right Inspector window, switch the Materials' Element 0 to your material.
TO change the material of the wall, you can go to the MapReader object. Under the Mesh Renderer property on the right Inspector window, switch the Materials' Element 0 to your material. Add also change the Material in the MapReader.cs params.
In the Unity Editor, one can release a build by clicking File -> Build Setting. In the open window, click Add Open Scences and select the platform you want. Then Click Build and save it to a seperate location outside of the Unity project.
