Skip to content

Commit

Permalink
Cleans up some code
Browse files Browse the repository at this point in the history
- Updates formatting to match PEP8 standard  for the ado filter python script.
- Removes unused imports for ado filter python script.
  • Loading branch information
exoticDFT committed Sep 25, 2020
1 parent 2b6e9cc commit 230a3b5
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions script/game_ado_vehicle_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from std_msgs.msg import Header, ColorRGBA

import numpy as np
import math
import random


class GameAdoCarFilter(object):
'''
Expand All @@ -24,7 +23,7 @@ class GameAdoCarFilter(object):
def __init__(self):
'''
Initializes the class.
Note: If self.enable_lane_filter is set to true, the filter will take
into account the lane in which the ado object is present.
'''
Expand Down Expand Up @@ -79,12 +78,11 @@ def __init__(self):
# Class timer
self.timer = rospy.Timer(rospy.Duration(0.1), self.timer_cb)


def ego_vehicle_cb(self, msg):
'''
This is a callback for the ego vehicle that fills out the ego vehicle's
odometry information and set the ego_ready variable.
Parameters
----------
msg : Odometry
Expand All @@ -95,12 +93,11 @@ def ego_vehicle_cb(self, msg):
if not self.ego_ready:
self.ego_ready = True


def nearby_car_cb(self, msg):
'''
This is a callback that fills out the nearby objects for the ego vehicle
and set the nearby_ready variable.
This is a callback that fills out the nearby objects for the ego
vehicle and set the nearby_ready variable.
Parameters
----------
msg : ObjectArray
Expand All @@ -112,13 +109,12 @@ def nearby_car_cb(self, msg):
if not self.nearby_ready:
self.nearby_ready = True


def timer_cb(self, event):
'''
This is a callback for the class timer, which will be called every tick.
The callback will filter out objects not relevant to the ego vehicle and
publish to the ROS topics defined in the class.
This is a callback for the class timer, which will be called every
tick. The callback will filter out objects not relevant to the ego
vehicle and publish to the ROS topics defined in the class.
Parameters
----------
event : rospy.TimerEvent
Expand All @@ -128,7 +124,7 @@ def relevant_filter(pos_x, pos_y, yaw, object):
'''
Determines if the object is in the circle and relevant to the
current ego position.
Parameters
----------
pos_x : float64
Expand All @@ -139,7 +135,7 @@ def relevant_filter(pos_x, pos_y, yaw, object):
The yaw, heading, of the ego vehicle.
object : derived_object_msgs.Object
The converted Carla object.
Returns
-------
bool, int, float
Expand Down Expand Up @@ -191,7 +187,7 @@ def relevant_filter(pos_x, pos_y, yaw, object):
# Object's relative postion is relevant
if (
distance_tangent > -15 and
distance_tangent < 25 and
distance_tangent < 25 and
abs(distance_normal) < 25
):
if distance_tangent > 0:
Expand All @@ -201,18 +197,17 @@ def relevant_filter(pos_x, pos_y, yaw, object):
rospy.logdebug("Ado object %d is behind.", object.id)
return True, 0, np.linalg.norm(ori_rel)

# Object is in the circle, but not relevant to ego location
# Object is in the circle, but not relevant to ego location
rospy.logdebug("Ado object %d is not relevant.", object.id)
return False, 0, 0


def relevant_filter_entrance(pos_x, pos_y, object):
'''
Determines if the object is trying to enter the circle and relevant
to the current ego position. The filter will take into account
whether the object is ahead of the ego and whether to base its
relevancy on the object's current lane.
Parameters
----------
pos_x : float64
Expand All @@ -221,7 +216,7 @@ def relevant_filter_entrance(pos_x, pos_y, object):
The y location of the ego vehicle.
object : derived_object_msgs.Object
The converted Carla object.
Returns
-------
bool
Expand All @@ -239,14 +234,14 @@ def relevant_filter_entrance(pos_x, pos_y, object):
return True
return False
elif pos_x <= 0 and pos_y >= 0:
if (pos_car[0] < -20 and pos_car[1]< 0):
if (pos_car[0] < -20 and pos_car[1] < 0):
return True
return False
else:
if pos_car[0] > 0 and pos_car[1] < -20:
return True
return False
else: #TODO: Update to use waypoint information
else: # TODO: Update to use waypoint information
if pos_x > 0 and pos_y < 0:
if (pos_car[0] > 15 and pos_car[1] > 0 and pos_car[1] < 7):
return True
Expand All @@ -273,7 +268,7 @@ def relevant_filter_entrance(pos_x, pos_y, object):
if (
(
pos_car[0] > 0 and
pos_car[0] < 5 and
pos_car[0] < 5 and
pos_car[1] < -20
) or
(
Expand All @@ -287,7 +282,6 @@ def relevant_filter_entrance(pos_x, pos_y, object):

return False


if self.ego_ready and self.nearby_ready:
self.ego_odom_pub.publish(self.ego_odom)

Expand Down Expand Up @@ -378,11 +372,10 @@ def relevant_filter_entrance(pos_x, pos_y, object):
color_opp = ColorRGBA(1.0, 0.0, 0.0, 1.0)
self.viz_cars([ado_object], header, color_opp, self.ado_marker_pub)


def viz_cars(self, obj_list, header, color_rgba, publisher):
'''
Publish objects to the provied rviz publisher.
Parameters
----------
obj_list : [Objects]
Expand Down

0 comments on commit 230a3b5

Please sign in to comment.