Skip to content

Commit

Permalink
add obstacles for target
Browse files Browse the repository at this point in the history
  • Loading branch information
ShisatoYano committed Dec 13, 2023
1 parent 8c9fbb1 commit 5610cf2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/components/visualization/global_xy_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GlobalXYVisualizer:
Visualization class for global 2D X-Y plot
"""

def __init__(self, x_lim, y_lim, time_params, gif_name=None):
def __init__(self, x_lim, y_lim, time_params, show_zoom=True, gif_name=None):
"""
Constructor
x_lim: MinMax object of x axis
Expand All @@ -30,6 +30,7 @@ def __init__(self, x_lim, y_lim, time_params, gif_name=None):
self.time_params = time_params
self.gif_name = gif_name
self.show_plot = True
self.show_zoom = show_zoom

def add_object(self, obj):
"""
Expand Down Expand Up @@ -68,7 +69,7 @@ def update(self, i, elems, axes):
if hasattr(obj, "update"): obj.update(self.time_params.get_interval_sec())

# show data between x-y min and max range
if self.time_params.simulation_finished(i):
if not self.show_zoom or self.time_params.simulation_finished(i):
axes.set_xlim(self.x_lim.min_value(), self.x_lim.max_value())
axes.set_ylim(self.y_lim.min_value(), self.y_lim.max_value())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
sys.path.append(abs_dir_path + relative_path + "sensors")
sys.path.append(abs_dir_path + relative_path + "sensors/lidar")
sys.path.append(abs_dir_path + relative_path + "mapping/ndt")
sys.path.append(abs_dir_path + relative_path + "course/sin_curve_course")
sys.path.append(abs_dir_path + relative_path + "control/pure_pursuit")


# import component modules
Expand All @@ -34,6 +36,8 @@
from sensor_parameters import SensorParameters
from omni_directional_lidar import OmniDirectionalLidar
from ndt_global_mapper import NdtGlobalMapper
from sin_curve_course import SinCurveCourse
from pure_pursuit_controller import PurePursuitController


# flag to show plot figure
Expand All @@ -45,23 +49,37 @@ def main():
"""
Main process function
"""

# start position


# set simulation parameters
x_lim, y_lim = MinMax(-30, 30), MinMax(-30, 30)
vis = GlobalXYVisualizer(x_lim, y_lim, TimeParameters(span_sec=20))
x_lim, y_lim = MinMax(-5, 55), MinMax(-20, 25)
vis = GlobalXYVisualizer(x_lim, y_lim, TimeParameters(span_sec=25), show_zoom=False)

# create course data instance
course = SinCurveCourse(0, 50, 0.5, 20)
vis.add_object(course)

# create obstacle instances
obst_list = ObstacleList()
obst1 = Obstacle(State(x_m=15.0, y_m=15.0), length_m=10, width_m=5)
obst_list.add_obstacle(obst1)
obst_list.add_obstacle(Obstacle(State(x_m=10.0, y_m=15.0), length_m=10, width_m=8))
obst_list.add_obstacle(Obstacle(State(x_m=40.0, y_m=0.0), length_m=2, width_m=10))
obst_list.add_obstacle(Obstacle(State(x_m=10.0, y_m=-10.0, yaw_rad=np.rad2deg(45)), length_m=5, width_m=5))
obst_list.add_obstacle(Obstacle(State(x_m=30.0, y_m=15.0, yaw_rad=np.rad2deg(10)), length_m=5, width_m=1))
vis.add_object(obst_list)

# create vehicle instance
spec = VehicleSpecification()
sensor_params = SensorParameters(lon_m=spec.wheel_base_m/2)
pure_pursuit = PurePursuitController(spec, course)
sensor_params = SensorParameters(lon_m=spec.wheel_base_m/2, max_m=20)
lidar = OmniDirectionalLidar(obst_list, sensor_params)
mapper = NdtGlobalMapper(sensor_params=sensor_params)
vehicle = FourWheelsVehicle(State(color=spec.color), spec, sensors=Sensors(lidar=lidar), mapper=mapper, show_zoom=False)
mapper = NdtGlobalMapper(sensor_params=sensor_params, center_x_m=25.0, center_y_m=5.0)
vehicle = FourWheelsVehicle(State(color=spec.color), spec,
controller=pure_pursuit,
sensors=Sensors(lidar=lidar),
mapper=mapper,
show_zoom=False)
vis.add_object(vehicle)

# plot figure is not shown when executed as unit test
Expand Down

0 comments on commit 5610cf2

Please sign in to comment.