Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamped multi car simulation #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions launch/multi_car.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<launch>
<arg name="num_cars" default="2" />
<node name="launchcars" pkg="mushr_sim" type="multi_car.py">
<param name="num_cars" type="int" value="$(arg num_cars)"/>
</node>
</launch>
4 changes: 2 additions & 2 deletions launch/multi_teleop.launch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<launch>

<arg name="car1_name" default="car1" />
<arg name="car2_name" default="car2" />
<arg name="car1_name" default="car0" />
<arg name="car2_name" default="car1" />

<!-- Set to 1 if you want to run the map_server -->
<arg name="map_server" value = "1"/>
Expand Down
6 changes: 3 additions & 3 deletions launch/teleop.launch
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<launch>

<!-- Set to 1 if you want to run the map_server -->
<arg name="map_server" value = "1" />
<arg name="map_server" default="1" />

<arg name="car_name" default="car" />

<arg name="racecar_color" default="" />
<!-- Launch map server-->
<group if="$(arg map_server)">
<include file="$(find mushr_sim)/launch/map_server.launch" />
Expand All @@ -22,7 +22,7 @@
<!-- The colors of the racecar, should be of the form "-<platform_color>-<inset_color>" -->
<!-- An empty string will result in the default URDF -->
<!-- Check CMakeLists.txt of mushr_description for appropriate values -->
<arg name="racecar_color" value="" />
<arg name="racecar_color" value="$(arg racecar_color)" />

<arg name="car_name" value="$(arg car_name)" />
</include>
Expand Down
27 changes: 27 additions & 0 deletions src/multi_car.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python2

import rospy
import roslaunch
import sys
rospy.init_node("launchcars")
uuid = roslaunch.rlutil.get_or_generate_uuid(None, False)
roslaunch.configure_logging(uuid)

#number of cars
n = rospy.get_param("~num_cars")

launches = []
mapserver = 1
colors = ['','-green-black','-red-white','-teal-purple','-purple-gold']
for x in range(n):
file_name='teleop.launch'
cli_args = ['mushr_sim', file_name, 'car_name:=car'+str(x), 'racecar_color:='+ colors[x%5], 'map_server:='+ str(mapserver)]
roslaunch_file = roslaunch.rlutil.resolve_launch_arguments(cli_args)[0]
roslaunch_args = cli_args[2:]
launches.append((roslaunch_file, roslaunch_args))
if(mapserver == 1):
mapserver = 0
parent = roslaunch.parent.ROSLaunchParent(uuid, launches)
parent.start()
while not rospy.is_shutdown():
rospy.sleep(1)