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

moving duckiebots controller updated to handle other moving bots #192

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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: 14 additions & 2 deletions gym_duckietown/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ def __init__(self, obj, domain_rand, safety_radius_mult, wheel_dist,
self.robot_width = robot_width
self.robot_length = robot_length

# Robot Safety circle radius
self.agent_safety_rad = (max(robot_length, robot_width) / 2) * safety_radius_mult

# FIXME: this does not follow the same signature as WorldOb
def step(self, delta_time, closest_curve_point, objects):
"""
Take a step, implemented as a PID controller
"""

# Find the curve point closest to the agent, and the tangent at that point
closest_point, closest_tangent = closest_curve_point(self.pos, self.angle)

closest_point, closest_tangent = closest_curve_point(self.pos, self.angle)
iterations = 0

lookup_distance = self.follow_dist
Expand All @@ -163,6 +165,16 @@ def step(self, delta_time, closest_curve_point, objects):
dot = np.dot(self.get_right_vec(self.angle), point_vec)
steering = self.gain * -dot

# checking for other moving duckiebots to slow down if another bot is moving in front
for obj in objects:
if not obj.static and obj.kind == "duckiebot":
if abs(obj.pos[0] - self.pos[0]) <0.12: # to check if this object is on my same lane
collision_penalty = abs(obj.proximity(self.pos, self.agent_safety_rad))
if collision_penalty > 0 :
# this means we are approaching and we need to slow down
self.velocity *= collision_penalty
break

self._update_pos([self.velocity, steering], delta_time)

def get_dir_vec(self, angle):
Expand Down