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

Add all_cars_in_dragway python demo; Remove C++ automotive_demo #396

Merged
merged 3 commits into from
May 10, 2018
Merged
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
16 changes: 0 additions & 16 deletions backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,6 @@ install(TARGETS simulation_runner
ARCHIVE DESTINATION lib
)

# ----------------------------------------
# Automotive demo
#
add_executable(automotive-demo
automotive_demo.cc
system.h
)

target_link_libraries(automotive-demo
simulation_runner
automotive_simulator
${drake_LIBRARIES}
)

install(TARGETS automotive-demo RUNTIME DESTINATION bin)

delphyne_install_includes(
${PROJECT_NAME}${PROJECT_MAJOR_VERSION}/${PROJECT_NAME}/backend
system.h
Expand Down
186 changes: 0 additions & 186 deletions backend/automotive_demo.cc

This file was deleted.

3 changes: 1 addition & 2 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ install(

install(
PROGRAMS
examples/demo_launcher.py
examples/all_cars_in_dragway.py
examples/keyboard_controlled_simulation.py
examples/loadable_agent_simulation.py
examples/railcar_in_multilane.py
examples/realtime_rate_changer.py
examples/road_loading.py
Expand Down
69 changes: 63 additions & 6 deletions python/delphyne/simulation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@

from contextlib import contextmanager
from delphyne.bindings import (
AutomotiveSimulator
Any,
AutomotiveSimulator,
MaliputRailcarParams,
MaliputRailcarState
)
from delphyne.launcher import Launcher
from pydrake.automotive import (
LaneDirection,
SimpleCarState
)

Expand Down Expand Up @@ -69,11 +73,7 @@ def build_simple_car_simulator(initial_positions=None):
simulator = AutomotiveSimulator()
car_id = 0
for car_position in initial_positions:
state = SimpleCarState()
state.set_y(car_position[0])
state.set_x(car_position[1])
simulator.AddLoadableAgent("simple-car", {}, str(car_id), state)

add_simple_car(simulator, car_id, car_position[1], car_position[0])
car_id += 1
return simulator

Expand Down Expand Up @@ -102,3 +102,60 @@ def launch_visualizer(launcher, layout_filename):
layout_path = os.path.join(get_delphyne_resource_root(), layout_filename)
teleop_config = layout_key + layout_path
launcher.launch([ign_visualizer, teleop_config])


def add_simple_car(simulator, robot_id, position_x=0, position_y=0):
"""Instantiates a new Simple Prius Car
and adds it to the simulation.
"""
# Creates the initial car state for the simple car.
simple_car_state = SimpleCarState()
simple_car_state.set_x(position_x)
simple_car_state.set_y(position_y)
# Instantiates a Loadable Simple Car
simulator.AddLoadableAgent(
"simple-car", {}, str(robot_id), simple_car_state)


def add_mobil_car(simulator, robot_id, road, position_x=0, position_y=0):
"""Instantiates a new MOBIL Car and adds
it to the simulation.
"""
# Creates the initial car state for the MOBIL car.
mobil_car_state = SimpleCarState()
mobil_car_state.set_x(position_x)
mobil_car_state.set_y(position_y)
mobil_params = {
"initial_with_s": Any(True),
"road": Any(road)
}
# Instantiates a Loadable MOBIL Car.
simulator.AddLoadableAgent(
"mobil-car", mobil_params, str(robot_id), mobil_car_state)


def add_maliput_railcar(simulator, robot_id, road, s_coordinate=0, speed=0):
"""Instantiates a new Maliput Railcar and adds
it to the simulation.
"""
# Defines the lane that will be used by the dragway car.
lane = road.junction(0).segment(0).lane(1)
# Creates the initial car state for the Railcar.
maliput_car_state = MaliputRailcarState()
maliput_car_state.s = s_coordinate
maliput_car_state.speed = speed
lane_direction = LaneDirection(lane, True)
start_params = MaliputRailcarParams()
start_params.r = 0
start_params.h = 0
railcar_params = {
"road": Any(road),
"initial_with_s": Any(True),
"lane_direction": Any(lane_direction),
"start_params": Any(start_params)
}
# Instantiates a Loadable Rail Car.
simulator.AddLoadableAgent("rail-car",
railcar_params,
str(robot_id),
maliput_car_state)
Loading