From 84a35d50678e4dfeb89ea916367586166f4ea5a9 Mon Sep 17 00:00:00 2001 From: Matas Keras Date: Fri, 12 Aug 2022 15:04:08 -0400 Subject: [PATCH] added comments to obstacle_test.py --- src/obstacle_detection.py | 10 +++++----- src/obstacle_test.py | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/obstacle_detection.py b/src/obstacle_detection.py index 10499da..c8e6b93 100755 --- a/src/obstacle_detection.py +++ b/src/obstacle_detection.py @@ -37,7 +37,7 @@ def get_balance(min_radius, balance_queue, average_balance): #depends on the average over the past 14 measurements of the minimum radius, #with lower minimum radius meaning a preference for obstacle avoidance #first we calculate the balance for this cycle - balance = (75-min_radius)/50 + balance = (25-min_radius)/20 #the balance value is moved to be between 0 and 1 if balance>1: balance = 1.0 @@ -45,8 +45,8 @@ def get_balance(min_radius, balance_queue, average_balance): balance=0.0 #now we update the average balance, and update the list of past balance #values - average_balance=average_balance-balance_queue.pop(0)/14 - average_balance=average_balance+balance/14 + average_balance=average_balance-balance_queue.pop(0)/4 + average_balance=average_balance+balance/4 balance_queue.append(balance) #finally, we return the average value, and the list of past values return balance_queue, average_balance @@ -113,7 +113,7 @@ def avoidance(weights): #next we calculate the magnitude of the velocity in the xy direction, #and the magnitude of the acceleration vector needed magnitude_velocity = np.sqrt(velocity[1]*velocity[1]+velocity[0]*velocity[0]) - magnitude_acceleration = 1*(magnitude_velocity*magnitude_velocity)/(min_radius) + magnitude_acceleration = 0.1*(magnitude_velocity*magnitude_velocity)/(min_radius) #if the velocity is too low (below 5m/s) we also have an additional forward #acceleration if magnitude_velocity<5: @@ -257,7 +257,7 @@ def accel_publisher(): #create variables for smoothing out the change between avoidance and #straight line flight balance_queue = [] - for x in range(14): + for x in range(4): balance_queue.append(0) balance = 0 #Here is where we start doing navigation control diff --git a/src/obstacle_test.py b/src/obstacle_test.py index 47f1bc2..433f9eb 100755 --- a/src/obstacle_test.py +++ b/src/obstacle_test.py @@ -10,8 +10,8 @@ from sensor_msgs.msg import LaserScan from std_msgs.msg import Header def velocity_callback(data): - global center_vector - center_vector = (data.twist.linear.x,data.twist.linear.y) + global velocity + velocity = (data.twist.linear.x,data.twist.linear.y) def pose_callback(data): @@ -19,15 +19,16 @@ def pose_callback(data): pose = data.pose.position def intersection(line1, line2): - #get y intercept from y = b2-b1/m1-m2 + #get x of intercept from x = b2-b1/m1-m2 x = (line2[1]-line1[1])/(line1[0]-line2[0]) + #get y of intercept from y = mx+b (for either line y = x*line1[0]+line1[1] return np.array([x,y]) def distance_to_line(line1,vector1, center1, line2, bound1, bound2): intersect = intersection(line1,line2) #if the intersection point is outside where the line actually exists, return inifinity - if not (intersect[0]>bound1[0] and intersect[1]>bound1[1] and intersect[0]bound1 and intersect[0]