Questions Tagged With cs373http://forums.udacity.com/tags/cs373/?type=rssquestions tagged <span class="tag">cs373</span>enTue, 12 Aug 2014 09:02:42 -0400- A* Implementation - All result are correct!!!???http://forums.udacity.com/questions/100216296/a-implementation-all-result-are-correct<p>I tried the two cases discussed in the "Lesson 4 - Search (Implement A*)" , the one with:</p>
<p>grid = [[0, 0, 0, 0, 0, 0],<br>
[0, 1, 0, 0, 0, 0],<br>
[0, 1, 0, 0, 0, 0],<br>
[0, 1, 0, 0, 0, 0],<br>
[0, 1, 0, 0, 1, 0]]</p>
<p>and I got the following output:</p>
<p>[[ 0, 1, 2, 3, 4, 5], <br>
[-1, -1, -1, -1, -1, 6], <br>
[-1, -1, -1, -1, -1, 7], <br>
[-1, -1, -1, -1, -1, 8], <br>
[-1, -1, -1, -1, -1, 9]]</p>
<p>then the one with:</p>
<p>grid = [[0, 0, 0, 0, 0, 0],<br>
[0, 1, 1, 1, 1, 0],<br>
[0, 1, 0, 0, 0, 0],<br>
[0, 1, 0, 0, 0, 0],<br>
[0, 1, 0, 0, 1, 0]]</p>
<p>and I got the following output:</p>
<p>[[ 0, 1, 2, 3, 4, 5], <br>
[-1, -1, -1, -1, -1, 6], <br>
[-1, -1, -1, -1, -1, 7], <br>
[-1, -1, -1, -1, -1, 8], <br>
[-1, -1, -1, -1, -1, 9]]</p>
<p>It seems to me that the results are correct. <br>
Why in the movie is said that in these cases the A * algorithm is not performing? Why is that?</p>
<p>The code that I have implemented, and that gives me the previous results, is as follows:</p>
<p>grid = [[0, 0, 0, 0, 0, 0],<br>
[0, 1, 1, 1, 1, 0],<br>
[0, 1, 0, 0, 0, 0],<br>
[0, 1, 0, 0, 0, 0],<br>
[0, 1, 0, 0, 1, 0]]<br>
heuristic = [[9, 8, 7, 6, 5, 4],<br>
[8, 7, 6, 5, 4, 3],<br>
[7, 6, 5, 4, 3, 2],<br>
[6, 5, 4, 3, 2, 1],<br>
[5, 4, 3, 2, 1, 0]]</p>
<p>init = [0, 0]<br>
goal = [len(grid)-1, len(grid[0])-1]<br>
cost = 1</p>
<p>delta = [[-1, 0 ], # go up<br>
[ 0, -1], # go left<br>
[ 1, 0 ], # go down<br>
[ 0, 1 ]] # go right</p>
<p>delta_name = ['^', '<', 'v', '>']</p>
<p>def search(grid,init,goal,cost,heuristic):<br>
# ----------------------------------------<br>
# modify the code below<br>
# ----------------------------------------<br>
closed = [[0 for row in range(len(grid[0]))] for col in range(len(grid))]<br>
closed[init[0]][init[1]] = 1</p>
<pre><code>expand = [[-1 for row in range(len(grid[0]))] for col in range(len(grid))]
action = [[-1 for row in range(len(grid[0]))] for col in range(len(grid))]
x = init[0]
y = init[1]
g = 0
h = heuristic[x][y]
f = g + h
open = [[f, h, g, x, y]]
found = False # flag that is set when search is complete
resign = False # flag set if we can't find expand
count = 0
while not found and not resign:
if len(open) == 0:
resign = True
return "Fail"
else:
open.sort()
open.reverse()
next = open.pop()
x = next[3]
y = next[4]
g = next[1]
expand[x][y] = count
count += 1
if x == goal[0] and y == goal[1]:
found = True
else:
for i in range(len(delta)):
x2 = x + delta[i][0]
y2 = y + delta[i][1]
if x2 >= 0 and x2 < len(grid) and y2 >=0 and y2 < len(grid[0]):
if closed[x2][y2] == 0 and grid[x2][y2] == 0:
g2 = g + cost
h2 = heuristic[x2][y2]
f2 = g2 + h2
open.append([f2, h2, g2, x2, y2])
closed[x2][y2] = 1
return expand
</code></pre>
<p>print search(grid,init,goal,cost,heuristic)</p>GIANFRANCOTue, 12 Aug 2014 09:02:42 -0400http://forums.udacity.com/questions/100216296/a-implementation-all-result-are-correctunit4-12m-48646839cs373
- Passed, but my solution produces weird results for some gridshttp://forums.udacity.com/questions/100215817/passed-but-my-solution-produces-weird-results-for-some-grids<p>My solution did produce the right results and was accepted, but when I examine some other grids it produces some unintuitive results. For example:</p>
<pre><code>grid = [[0, 1, 0, 0],
[0, 1, 0, 1],
[0, 1, 0, 1],
[0, 0, 0, 1]]
goal = [0, len(grid[0])-1] # Goal is in top right corner
cost_step = 1
collision_cost = 300
success_prob = 0.5
</code></pre>
<p>The output is</p>
<pre><code>[301.0, 1000, 130.0, 0]
[300.42857142857144, 1000, 216.0, 1000]
[298.8571428571429, 1000, 259.0, 1000]
[295.7142857142857, 290.0, 278.0, 1000]
['^', ' ', '>', '*']
['v', ' ', '^', ' ']
['v', ' ', '^', ' ']
['>', '>', '^', ' ']
</code></pre>
<p>Why does it want to move up when it is in the top left corner? At collision_cost=400 it does go down. </p>Robin-177Sun, 10 Aug 2014 14:47:57 -0400http://forums.udacity.com/questions/100215817/passed-but-my-solution-produces-weird-results-for-some-gridsm-48702474ps4-5cs373
- After two weeks I got it!http://forums.udacity.com/questions/100215771/after-two-weeks-i-got-it<p>It was a hard problem!</p>
<p>Thanks for the course. </p>Jorge Borrego SevillaSun, 10 Aug 2014 11:10:32 -0400http://forums.udacity.com/questions/100215771/after-two-weeks-i-got-itm-670128585unit22-11-projectcs373
- function move()http://forums.udacity.com/questions/100214819/function-move<p>Why in the move () function in the class robot, it must create a new instance of robot?<br>
........<br>
res = robot()<br>
.........<br>
The previous line of code creates, in fact, the instance res of robot. But when I create an instance of robot is not randomly assigned a position? <br>
If I call the function move many times within the main program will then create as many instances of robots with many random locations? <br>
Would not it be more appropriate not to instantiate robot inside the function (class method robot)?<br>
The variable self is already an instance of robot or not?<br>
In the previous exercise (# 3.4) so I wrote my move function: </p>
<p>..............<br>
def move(self, motion, tolerance=0.001): # Do not change the name of this function</p>
<pre><code> # ADD CODE HERE
alpha = motion[0]
d = motion[1]
if abs(alpha) > max_steering_angle:
raise ValueError, 'Exceding max steering angle'
if d < 0.0:
raise VaueError, 'Moving backwards is not valid'
L = self.length
# apply noise
alpha = random.gauss(alpha, self.steering_noise)
d = random.gauss(d, self.distance_noise)
beta = (d/L)*tan(alpha)
theta = self.orientation
x = self.x
y = self.y
if beta != 0:
R = d/beta
cx = x - sin(theta)*R
cy = y + cos(theta)*R
self.x = cx + sin(theta + beta)*R
self.y = cy - cos(theta + beta)*R
else:
self.x = x + d *cos(theta)
self.y = y + d *sin(theta)
self.orientation = ((theta + beta) % (2*pi))
return self
</code></pre>
<p>...........</p>
<p>and it worked because I was in the main program I initialized robot:</p>
<p>....<br>
myrobot = robot(length)<br>
myrobot.set(0.0, 0.0, 0.0)<br>
.......</p>
<p>and then used the move ():<br>
.......<br>
print 'Robot: ', myrobot<br>
for t in range(T):<br>
myrobot = myrobot.move(motions[t])<br>
print 'Robot: ', myrobot<br>
.......</p>
<p>In the final exercise I could not use self inside move () and I had to necessarily create an instance res of robot :</p>
<p>......<br>
def move(self, motion, tolerance=0.001): # Do not change the name of this function</p>
<pre><code> # ADD CODE HERE
alpha = motion[0]
d = motion[1]
if abs(alpha) > max_steering_angle:
raise ValueError, 'Exceding max steering angle'
if d < 0.0:
raise VaueError, 'Moving backwards is not valid'
res = robot()
res.length = self.length
res.bearing_noise = self.bearing_noise
res.steering_noise = self.steering_noise
res.distance_noise = self.distance_noise
# apply noise
alpha = random.gauss(alpha, self.steering_noise)
d = random.gauss(d, self.distance_noise)
beta = (d/res.length)*tan(alpha)
x = self.x
y = self.y
theta = self.orientation
if beta >= tolerance:
R = d/beta
cx = x - sin(theta)*R
cy = y + cos(theta)*R
res.orientation = (theta + beta) % (2*pi)
res.x = cx + sin(res.orientation)*R
res.y = cy - cos(res.orientation)*R
else:
res.x = x + d *cos(theta)
res.y = y + d *sin(theta)
res.orientation = ((theta + beta) % (2*pi))
return res #
</code></pre>
<p>........</p>
<p>Is correct to instantiate robot inside move ()?</p>GIANFRANCOThu, 07 Aug 2014 06:05:17 -0400http://forums.udacity.com/questions/100214819/function-moveps3-6m-48717416spoilerfunctioncs373staff
- How do we get the posterior Gaussian distribution?http://forums.udacity.com/questions/100214683/how-do-we-get-the-posterior-gaussian-distribution<p>Prof.Thrun just give the formula directly without explanation. But I really want to figure it out. It seems like something in Probability.</p>JiaxuWed, 06 Aug 2014 20:14:39 -0400http://forums.udacity.com/questions/100214683/how-do-we-get-the-posterior-gaussian-distributionm-48686761unit2-12cs373
- 4-19 Bug in my codehttp://forums.udacity.com/questions/100213611/4-19-bug-in-my-code<p>I have this solution for 4-19. I am getting the right path, but the labels are wrong. Can anyone help me?</p>
<pre><code>enter code here:
# Implement the function optimum_policy2D below.
# You are given a car in grid with initial state
# init. Your task is to compute and return the car's
# optimal path to the position specified in goal;
# the costs for each motion are as defined in cost.
# There are four motion directions: up, left, down, and right.
# Increasing the index in this array corresponds to making a
# a left turn, and decreasing the index corresponds to making a
# right turn.
forward = [[-1, 0], # go up
[ 0, -1], # go left
[ 1, 0], # go down
[ 0, 1]] # go right
forward_name = ['up', 'left', 'down', 'right']
# action has 3 values: right turn, no turn, left turn
action = [-1, 0, 1]
action_name = ['R', '#', 'L']
# EXAMPLE INPUTS:
# grid format:
# 0 = navigable space
# 1 = unnavigable space
grid = [[1, 1, 1, 0, 0, 0],
[1, 1, 1, 0, 1, 0],
[0, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 1, 1],
[1, 1, 1, 0, 1, 1]]
init = [4, 3, 0] # given in the form [row,col,direction]
# direction = 0: up
# 1: left
# 2: down
# 3: right
goal = [2, 0] # given in the form [row,col]
cost = [2, 1, 20] # cost has 3 values, corresponding to making
# a right turn, no turn, and a left turn
# EXAMPLE OUTPUT:
# calling optimum_policy2D with the given parameters should return
# [[' ', ' ', ' ', 'R', '#', 'R'],
# [' ', ' ', ' ', '#', ' ', '#'],
# ['*', '#', '#', '#', '#', 'R'],
# [' ', ' ', ' ', '#', ' ', ' '],
# [' ', ' ', ' ', '#', ' ', ' ']]
# ----------
# ----------------------------------------
# modify code below
# ----------------------------------------
def optimum_policy2D(grid,init,goal,cost):
policy2D = [[' ' for row in range(len(grid[0]))] for col in range(len(grid))]
value = [[99 for row in range(len(grid[0]))] for col in range(len(grid))]
change = True
while change:
change = False
direc = init[2]
for x in range(len(grid)):
for y in range(len(grid[0])):
if goal[0] == x and goal[1] == y:
if value[x][y] > 0:
value[x][y] = 0
policy2D[x][y] = '*'
change = True
elif grid[x][y] == 0:
for a in range(len(forward)):
x2 = x + forward[a][0]
y2 = y + forward[a][1]
if x2 >= 0 and x2 < len(grid) and y2 >= 0 and y2 < len(grid[0]) and grid[x2][y2] == 0:
i = action.index(x -x2)
v2 = value[x2][y2] + cost[i]
if v2 < value[x][y]:
change = True
value[x][y] = v2
policy2D[x][y] = action_name[i]
direc = a
return policy2D
print optimum_policy2D(grid,init,goal,cost)
</code></pre>
<p>My result: </p>
<p>[[' ', ' ', ' ', 'R', '#', '#'],<br>
[' ', ' ', ' ', 'R', ' ', 'R'],<br>
['*', '#', '#', '#', '#', '#'],<br>
[' ', ' ', ' ', 'L', ' ', ' '],<br>
[' ', ' ', ' ', 'L', ' ', ' ']]</p>DhyeyMon, 04 Aug 2014 03:33:40 -0400http://forums.udacity.com/questions/100213611/4-19-bug-in-my-codeunit4-19m-48646840cs373
- Grading script issue?http://forums.udacity.com/questions/100213116/grading-script-issue<p>My code below works well when I set grid as [[0, 1], [0, 0]] when I hit the "Test Run" feature. However, when I hit submit, it says an exception has occurred. I am guessing this is happening since I don't have all the code in the search function... is there some simple workaround? Or is something else the issue...</p>
<h1>----------</h1>
<h1>User Instructions:</h1>
<h1></h1>
<h1>Define a function, search() that returns a list</h1>
<h1>in the form of [optimal path length, x, y]. For</h1>
<h1>the grid shown below, your function should output</h1>
<h1>[11, 4, 5].</h1>
<h1></h1>
<h1>If there is no valid path from the start point</h1>
<h1>to the goal, your function should return the string</h1>
<h1>'fail'</h1>
<h1>----------</h1>
<h1>Grid format:</h1>
<h1>0 = Navigable space</h1>
<h1>1 = Occupied space</h1>
<p>grid = [[0, 0, 1, 0, 0, 0],<br>
[0, 0, 1, 0, 0, 0],<br>
[0, 0, 0, 0, 1, 0],<br>
[0, 0, 1, 1, 1, 0],<br>
[0, 0, 0, 0, 1, 0]]</p>
<h1>grid = [[0, 1],</h1>
<h1>[0, 0]]</h1>
<p>init = [0, 0]<br>
goal = [len(grid)-1, len(grid[0])-1]<br>
cost = 1</p>
<p>delta = [[-1, 0], # go up<br>
[ 0,-1], # go left<br>
[ 1, 0], # go down<br>
[ 0, 1]] # go right</p>
<p>delta_name = ['^', '<', 'v', '>']</p>
<p>open_locations = [[0, init[0], init[1]]]<br>
previous_grid_locations = []</p>
<h1>print 'Length of grid is', len(grid[0])</h1>
<h1>------------------------------------------------------------------</h1>
<h1>This function checks if the goal is reached</h1>
<h1>-------------------------------------------------------------------</h1>
<p>def check_if_reached_goal(goal, open_locations):<br>
flag = 0<br>
for i in range(len(open_locations)):<br>
if ((open_locations[i][1] == goal[0]) & (open_locations[i][2] == goal[1])): <br>
#print('Reached goal')<br>
print open_locations[i]<br>
flag = 1<br>
return flag </p>
<h1>-------------------------------------------------------------------</h1>
<h1>This function figures out the next "open" grid locations</h1>
<h1>-------------------------------------------------------------------</h1>
<p>def next_one(grid,open_locations):</p>
<pre><code>candidates = []
# For anything on the open list, see next possible grid locations
for i in range(len(open_locations)):
# Now look for grid locations on the top, see if they are applicable, add g value of 1
if (open_locations[i][1] != 0) and (grid[(open_locations[i][1]-1)][open_locations[i][2]] == 0):
next_location_with_g_value = [(open_locations[i][0]+1), (open_locations[i][1]-1),(open_locations[i][2])]
candidates.append(next_location_with_g_value)
# Now look for grid locations on the bottom, see if they are applicable, add g value of 1
if (open_locations[i][1] < (len(grid)-1)):
if (grid[(open_locations[i][1]+1)][open_locations[i][2]] == 0):
next_location_with_g_value = [(open_locations[i][0]+1), (open_locations[i][1]+1),(open_locations[i][2])]
candidates.append(next_location_with_g_value)
# Now look for grid locations on the right, see if they are applicable, add g value of 1
if (open_locations[i][2] < (len(grid[0])-1)):
if (grid[(open_locations[i][1])][open_locations[i][2]+1] == 0):
next_location_with_g_value = [(open_locations[i][0]+1), (open_locations[i][1]),(open_locations[i][2]+1)]
candidates.append(next_location_with_g_value)
# Now look for grid locations on the left, see if they are applicable, add g value of 1
if (open_locations[i][2] != 0) and (grid[(open_locations[i][1])][open_locations[i][2]-1] == 0):
next_location_with_g_value = [(open_locations[i][0]+1), (open_locations[i][1]),(open_locations[i][2]-1)]
candidates.append(next_location_with_g_value)
candidates = remove_duplicates(candidates)
#print candidates
new = previous_check(open_locations, candidates)
#print new
return new
</code></pre>
<h1>-------------------------------------------------------------------</h1>
<h1>This function maintains a list of previous grid locations</h1>
<h1>-------------------------------------------------------------------</h1>
<p>def previous_check(open_locations, candidates):<br>
global previous_grid_locations<br>
# Updates the previous grid locations<br>
for i in range(len(open_locations)):<br>
previous_grid_locations.append([open_locations[i][1], open_locations[i][2]])<br>
#print ('Previous grid locations are', previous_grid_locations)<br>
trash = []<br>
#print 'Candidates are', candidates<br>
#print 'Previous grid locations are', previous_grid_locations<br>
# Removes the previously used grid locations<br>
for j in range(len(candidates)):<br>
for k in range(len(previous_grid_locations)):<br>
#print ('Candidates (j,1) are', candidates[j][1])<br>
if (((candidates[j][1]) == previous_grid_locations[k][0]) & (candidates[j][2] == previous_grid_locations[k][1])):<br>
#print 'candidate that needs to be removed is', candidates[j]<br>
trash.append(candidates[j])<br>
#candidates.remove(trash)<br>
#print 'Trash is', trash<br>
trash = remove_duplicates(trash)<br>
for i in range(len(trash)):<br>
candidates.remove(trash[i])</p>
<pre><code>return candidates
</code></pre>
<h1>--------------------------------------------------------------------</h1>
<h1>Remove duplicates</h1>
<h1>--------------------------------------------------------------------</h1>
<p>def remove_duplicates(seq):<br>
# order preserving<br>
checked = []<br>
for e in seq:<br>
if e not in checked:<br>
checked.append(e)<br>
return checked</p>
<h1>-------------------------------------------------------------------</h1>
<h1>This is the main body of the program</h1>
<h1>-------------------------------------------------------------------</h1>
<p>def search(grid,init,goal,cost):<br>
global open_locations<br>
while (check_if_reached_goal(goal, open_locations) == 0):<br>
open_locations = next_one(grid, open_locations)</p>
<p>search(grid, init, goal, cost)</p>Deepak-169Sat, 02 Aug 2014 14:39:50 -0400http://forums.udacity.com/questions/100213116/grading-script-issuem-48726347unit4-8cs373
- Can someone explain the Move function of the class Robot? I want to increase the simulation accuracy by including tire slippage.http://forums.udacity.com/questions/100212338/can-someone-explain-the-move-function-of-the-class-robot-i-want-to-increase-the-simulation-accuracy-by-including-tire-slippage<p>So given the move function given here (specifically the execute motion part)</p>
<p>%%%%%%%%%%%%%%%%%%%%%%<br>
def move(self, steering, distance, <br>
tolerance = 0.001, max_steering_angle = pi / 4.0):<br>
if steering > max_steering_angle:<br>
steering = max_steering_angle<br>
if steering < -max_steering_angle:<br>
steering = -max_steering_angle<br>
if distance < 0.0:<br>
distance = 0.0<br>
# make a new copy<br>
res = robot()<br>
res.length = self.length<br>
res.steering_noise = self.steering_noise<br>
res.distance_noise = self.distance_noise<br>
res.steering_drift = self.steering_drift<br>
# apply noise<br>
steering2 = random.gauss(steering, self.steering_noise)<br>
distance2 = random.gauss(distance, self.distance_noise)<br>
# apply steering drift<br>
steering2 += self.steering_drift<br>
# Execute motion<br>
<strong>turn = tan(steering2) * distance2 / res.length</strong><br>
if abs(turn) < tolerance:<br>
# approximate by straight line motion<br>
res.x = self.x + (distance2 * cos(self.orientation))<br>
res.y = self.y + (distance2 * sin(self.orientation))<br>
res.orientation = (self.orientation + turn) % (2.0 * pi)<br>
else:<br>
<strong># approximate bicycle model for motion<br>
radius = distance2 / turn<br>
cx = self.x - (sin(self.orientation) * radius)<br>
cy = self.y + (cos(self.orientation) * radius)<br>
res.orientation = (self.orientation + turn) % (2.0 * pi)<br>
res.x = cx + (sin(res.orientation) * radius)<br>
res.y = cy - (cos(res.orientation) * radius)</strong></p>
<p>%%%%%%%%%%%%%%%%%</p>
<p>Can someone explain the approximate bicycle motion code?</p>
<p>I am confused with - "turn = tan(steering2) * distance2 / res.length" and the "approximate bicycle model for motion" calculations.</p>
<p>I want to use a steering model that takes tire slippage into account, but I am failing to implement the simulation of the movement. </p>Garrett-89Thu, 31 Jul 2014 10:57:35 -0400http://forums.udacity.com/questions/100212338/can-someone-explain-the-move-function-of-the-class-robot-i-want-to-increase-the-simulation-accuracy-by-including-tire-slippageunit5-14m-48728346cs373
- The measurements are still an indicator of particle accuracy regardless of N.http://forums.udacity.com/questions/100210972/the-measurements-are-still-an-indicator-of-particle-accuracy-regardless-of-n<p>I don't agree with the answer that the particle filter with N=1 ignores robot measurements. The explanation given is that because the lone particle is always resampled that the measurements/weights aren't useful. </p>
<p>From my perspective, resampling is an intermediate technique in order to iteratively shrink the set of particles into the most likely candidate particles (with some randomness). The real value of the measurements is in their evaluation of the accuracy of the particles; while this is normally calculated into weights, it can be valuable even with only one particle in that it tells you if the particle is an accurate estimation or not--which is likely the end goal of the particle filter.</p>Igor M. BorushekSun, 27 Jul 2014 14:24:06 -0400http://forums.udacity.com/questions/100210972/the-measurements-are-still-an-indicator-of-particle-accuracy-regardless-of-nm-48726343cs373ps3-3
- Robotics Classhttp://forums.udacity.com/questions/100210553/robotics-class<p>It will be great to see more AI , Robotics , practical machine learning , computer vision classes very soon all through python</p>tushantSat, 26 Jul 2014 10:12:58 -0400http://forums.udacity.com/questions/100210553/robotics-classunit3-1-qam-48271828cs373
- Particle Filterhttp://forums.udacity.com/questions/100210426/particle-filter<p>I would like to implement particle filters and see its implementation on simulator . Is there any linux based simulator(mainly robot) where we can implement this algorithm </p>tushantFri, 25 Jul 2014 20:51:34 -0400http://forums.udacity.com/questions/100210426/particle-filterunit3-14m-48311865cs373
- kalman filterhttp://forums.udacity.com/questions/100209708/kalman-filter<p>is the values on measurement , measurement_sig , motion_sig etc are taken blindly just for showing what it does ? If so then what will be the values of them in real world and how it is taken </p>tushantWed, 23 Jul 2014 21:57:11 -0400http://forums.udacity.com/questions/100209708/kalman-filterunit2-21cs373m-48665923
- Visualizing Particle Filters with turtlehttp://forums.udacity.com/questions/100208465/visualizing-particle-filters-with-turtle<p>I was inspired by the turtle visualization code that was posted to help out with the final project to go back and see if I could visualize the robot and particles in the particle filter homework. It turned out to work pretty well. If you want to use this you need to run it offline. I recommend using the anaconda distribution and the Spyder IDE. </p>
<p>Here's how I did it:</p>
<p>Imports:</p>
<pre><code>import turtle
</code></pre>
<p>Setup the screen and landmarks:</p>
<pre><code>ROBOT_COLOR = 'blue'
PARTICLE_COLOR = 'red'
screen = turtle.Screen()
screen.title('Robot Localization by Particle Filter in Beacon World')
screen.bgcolor('White')
screen.setworldcoordinates(-0.5*world_size,1.5*world_size,1.5*world_size,-0.5*world_size)
landmark_turtle = turtle.Turtle(shape='circle',visible=False)
landmark_turtle.penup()
for landmark in landmarks:
landmark_turtle.setposition(landmark)
landmark_turtle.stamp()
</code></pre>
<p>Add turtle to Robot class:</p>
<pre><code>class robot:
def __init__(self, length = 20.0):
...
self.turtle = None
def set_turtle(self,a_turtle):
self.turtle = turtle.Turtle(shape=a_turtle.shape(),visible=False)
self.turtle.radians()
self.turtle.penup()
self.turtle.color(*a_turtle.color())
# put the turtle where it was
self.turtle.setposition(a_turtle.xcor(),a_turtle.ycor())
self.turtle.setheading(a_turtle.heading())
#draw the transition if the pen was down
if a_turtle.isdown():
self.turtle.pendown()
# move it to the new place
self.turtle.setposition(self.x, self.y)
self.turtle.setheading(self.orientation + pi/2.)
if a_turtle.isvisible():
self.turtle.showturtle()
def move(self, motion):
# the move code we had to add which creates result, a new robot
...
#after result of move is created update its turtle with the old turtle
if self.turtle is not None:
result.set_turtle(self.turtle)
return result
</code></pre>
<p>Add visualizations in generate_ground_truth to see the robot move:</p>
<pre><code>def generate_ground_truth(motions):
myrobot = robot()
myrobot.set_noise(bearing_noise, steering_noise, distance_noise)
myturtle = turtle.Turtle(visible=False)
myturtle.radians()
myturtle.penup()
myturtle.color(ROBOT_COLOR)
myrobot.set_turtle(myturtle)
myrobot.turtle.pendown()
myrobot.turtle.showturtle()
screen.delay(10)
Z = []
T = len(motions)
for t in range(T):
oldturtle = myrobot.turtle
myrobot = myrobot.move(motions[t])
oldturtle.hideturtle()
Z.append(myrobot.sense())
return [myrobot, Z]
</code></pre>
<p>Add visualizations in particle_filter to see the movement/sampling:</p>
<pre><code>def particle_filter(motions, measurements, N=500): # I know it's tempting, but don't change N!
screen.delay(0)
p_turtle = turtle.Turtle(visible=False)
p_turtle.radians()
p_turtle.penup()
p_turtle.color(PARTICLE_COLOR)
p = []
for i in range(N):
r = robot()
r.set_noise(bearing_noise, steering_noise, distance_noise)
r.set_turtle(p_turtle)
r.turtle.showturtle()
p.append(r)
for t in range(len(motions)):
# motion update (prediction)
p2 = []
for i in range(N):
p2.append(p[i].move(motions[t]))
# hide the old turtles
for particle in p:
particle.turtle.hideturtle()
p = p2
# measurement update
w = []
for i in range(N):
w.append(p[i].measurement_prob(measurements[t]))
# resampling
p3 = []
index = int(random.random() * N)
beta = 0.0
mw = max(w)
for i in range(N):
beta += random.random() * 2.0 * mw
while beta > w[index]:
beta -= w[index]
index = (index + 1) % N
p3.append(p[index])
# hide the old turtles
for particle in p:
if particle not in p3:
particle.turtle.hideturtle()
p = p3
return get_position(p)
</code></pre>robert-90Sat, 19 Jul 2014 17:41:26 -0400http://forums.udacity.com/questions/100208465/visualizing-particle-filters-with-turtleps3-6m-48717416cs373
- Monte Carlo Optimization?http://forums.udacity.com/questions/100207765/monte-carlo-optimization<p>I think there is an error here. We went over histogram filters, not monte carlo optimization which is particle filters. Maybe meant to say Markov optimization.</p>Igor M. BorushekThu, 17 Jul 2014 18:59:17 -0400http://forums.udacity.com/questions/100207765/monte-carlo-optimizationm-48696467cs373ps1-5
- Making an autonomous Legos Robothttp://forums.udacity.com/questions/100207353/making-an-autonomous-legos-robot<p>Hey everyone,</p>
<p>I was thinking of recording some videos and posting the code I used to make an autonomous legos NXT robot. Would anyone be interested in watching some of them? They're are tutorial based, so I'd like to cover how to implement the algorithms we've discussed here into the robot.</p>Alejandro-207Wed, 16 Jul 2014 22:40:25 -0400http://forums.udacity.com/questions/100207353/making-an-autonomous-legos-robotcs373
- Total probability in bayes rulehttp://forums.udacity.com/questions/100207150/total-probability-in-bayes-rule<p>Isn't the total probability formula the denominator in the bayes rule formula?</p>Igor M. BorushekWed, 16 Jul 2014 14:04:15 -0400http://forums.udacity.com/questions/100207150/total-probability-in-bayes-rulem-48311862unit2-9cs373
- Resamplinghttp://forums.udacity.com/questions/100205194/resampling<p>I was wondering, currently have implemented in MATLAB, why not create a new set of particles that contains with particles represented proportional to their weights and randomly select the new set from this bag..?<br>
I believe it would be unbiased...!<br>
My Matlab code is a follows:</p>
<pre><code>function p = resample(pOld, W)
L = length(pOld);
Temp_Set = [];
W2O = ceil(W./min(W));
for i = 1:L
for j = 1:W2O(i)
Temp_Set = cat(1,Temp_Set,p(i))
end
end
index = randi(length(Temp_Set),[1, length(Temp_Set)]);
Temp_Set = Temp_Set(index);
index = randi(length(Temp_Set),[1,L]);
p = Temp_Set(index);
</code></pre>
<p>I know this may not be the fastest resampling algorithm, particularly due to the large number of iterations in creating the Temp_Set that contains particles represented proportional to their probability and hence should be unbiased. <br>
Any comments?</p>SivasathivelThu, 10 Jul 2014 15:03:57 -0400http://forums.udacity.com/questions/100205194/resamplingcs373
- Got the correct answer but wasn't graded correcthttp://forums.udacity.com/questions/100204479/got-the-correct-answer-but-wasnt-graded-correct<p>I have this code which brings out the correct answers for the task but doesn't get graded correctly:</p>
<pre><code>def move(self, motion): # Do not change the name of this function
# ADD CODE HERE
beta=((motion[1])/length)*math.tan(motion[0])
result = robot(length)
result.set(self.x, self.y, self.orientation)
result.set_noise(bearing_noise, steering_noise, distance_noise)
if beta<0.001:
result.x=result.x+motion[1]*math.cos(result.orientation)
result.y=result.y+motion[1]*math.sin(result.orientation)
result.orientation=result.orientation
else:
R=motion[1]/beta
result.x=self.x-R*(math.sin(result.orientation))+(math.sin(result.orientation+beta))*R
result.y=self.y+R*(math.cos(result.orientation))-(math.cos(result.orientation+beta))*R
result.orientation=(result.orientation+beta)%(2*pi)
return result
</code></pre>Andreas-289Tue, 08 Jul 2014 23:39:34 -0400http://forums.udacity.com/questions/100204479/got-the-correct-answer-but-wasnt-graded-correctps3-4m-48727645cs373
- Maintaining OPEN list as a heap to make the code more efficienthttp://forums.udacity.com/questions/100203457/maintaining-open-list-as-a-heap-to-make-the-code-more-efficient<p>Sebastian's code sorts the OPEN list every step. I would suggest maintain the OPEN list as a heap by using the heapq module. Every step just heappop the smallest item, and heappush the unexplored adjacent feasible cells into the OPEN list.</p>Kai-98Sun, 06 Jul 2014 09:16:27 -0400http://forums.udacity.com/questions/100203457/maintaining-open-list-as-a-heap-to-make-the-code-more-efficientm-48726347unit4-8cs373
- probability of sensor being correcthttp://forums.udacity.com/questions/100203082/probability-of-sensor-being-correct<p>In Localization problem<br>
we have pHit = 0.6<br>
pMiss = 0.2</p>
<p>how do we calculate these probabilities given raw sensor data?</p>monica-8Sat, 05 Jul 2014 04:55:53 -0400http://forums.udacity.com/questions/100203082/probability-of-sensor-being-correctcs373
- IndexError: list index out of rangehttp://forums.udacity.com/questions/100202395/indexerror-list-index-out-of-range<p><strong>Help me please. I got this error:</strong> </p>
<p>Traceback (most recent call last):<br>
File "vm_main.py", line 33, in <module><br>
import main<br>
File "/tmp/vmuser_wgxuqtgobd/main.py", line 675, in <module><br>
result = online_slam(data, N, num_landmarks, motion_noise, measurement_noise)<br>
File "/tmp/vmuser_wgxuqtgobd/main.py", line 599, in online_slam<br>
<strong>Omega.value[m+b][m+b] += 1.0 / measurement_noise</strong><br>
IndexError: list index out of range</p>
<p><strong>I can not find the error, I have enough time looking for it</strong></p>
<p><strong>Here is part of the program:</strong></p>
<p>def online_slam(data, N, num_landmarks, motion_noise, measurement_noise):</p>
<pre><code># Enter your code here!
# Set the dimension of the filter
dim = 2 * (1 + num_landmarks)
# make the constraint information matrix and vector
Omega = matrix()
Omega.zero(dim, dim)
Omega.value[0][0] = 1.0
Omega.value[1][1] = 1.0
Xi = matrix()
Xi.zero(dim, 1)
Xi.value[0][0] = world_size / 2.0
Xi.value[1][0] = world_size / 2.0
# process the data
for k in range(len(data)):
measurement = data[k][0]
motion = data[k][1]
# integrate the measurements
for i in range(len(measurement)):
# m is the index of the landmark coordinate in the matrix/vector
m = 2 * (1 + measurement[i][0])
# update the information maxtrix/vector based on the measurement
for b in range(2):
Omega.value[b][b] += 1.0 / measurement_noise
Omega.value[m+b][m+b] += 1.0 / measurement_noise
Omega.value[b][m+b] += -1.0 / measurement_noise
Omega.value[m+b][b] += -1.0 / measurement_noise
Xi.value[b][0] += -measurement[i][1+b] / measurement_noise
Xi.value[m+b][0] += measurement[i][1+b] / measurement_noise
</code></pre>
<p><strong>The program is run with this:</strong></p>
<p>num_landmarks = 5 # number of landmarks<br>
N = 20 # time steps<br>
world_size = 100.0 # size of world<br>
measurement_range = 50.0 # range at which we can sense landmarks<br>
motion_noise = 2.0 # noise in robot motion<br>
measurement_noise = 2.0 # noise in the measurements<br>
distance = 20.0 # distance by which robot (intends to) move each iteratation </p>
<p>-# Uncomment the following three lines to run the online_slam routine.</p>
<p>data = make_data(N, num_landmarks, world_size, measurement_range, motion_noise, measurement_noise, distance)<br>
result = online_slam(data, N, num_landmarks, motion_noise, measurement_noise)<br>
print_result(1, num_landmarks, result[0])</p>Marco Antonio Alonso PĂ©rezThu, 03 Jul 2014 10:57:27 -0400http://forums.udacity.com/questions/100202395/indexerror-list-index-out-of-rangem-48683841cs373ps6-2
- Unit 1 - Video 40 (late starter here)http://forums.udacity.com/questions/100200560/unit-1-video-40-late-starter-here<p>Can Some one explain to me from how the eqn P(X4) = 0.8 P(x2) +0.1P(x1) +0.1P(x3) comes into being? I did get the intuitive reasoning, not the mathematical one.</p>
<p>Video is named Limit Distribution Quiz.</p>Merin-1Sun, 29 Jun 2014 17:34:18 -0400http://forums.udacity.com/questions/100200560/unit-1-video-40-late-starter-herecs373
- Why can't I use list comprehension?http://forums.udacity.com/questions/100200273/why-cant-i-use-list-comprehension<p>I wanted to use list comprehension but the division sign won't work</p>Ian-428Sun, 29 Jun 2014 00:40:03 -0400http://forums.udacity.com/questions/100200273/why-cant-i-use-list-comprehensionunit1-6cs373m-48742190
- shortest pathshttp://forums.udacity.com/questions/100198468/shortest-paths<p>How will the alogorithm for the shortest path in a continuous model look like?</p>Robin-170Wed, 25 Jun 2014 04:41:29 -0400http://forums.udacity.com/questions/100198468/shortest-pathsm-48717419cs373unit4-17
- Are you ready to adopt Google's self-driving car?http://forums.udacity.com/questions/100197005/are-you-ready-to-adopt-googles-self-driving-car<p>Hey folks,</p>
<p>could you please help me in filling out this survey please????</p>
<p>I am doing research on Google's self-driving car and would be really delighted if you could participate in the survey. </p>
<p>It is not a business markting survey nor do I work for Google.</p>
<p>I am simply interested in YOUR voice as this survey is part of a longer-term project, including my master thesis and PhD. </p>
<p><a rel="nofollow" href="https://docs.google.com/a/student.utwente.nl/forms/d/11rSv2oZ61tvfa70Iy6Pww6GCj9lqzm0m0tsKT5q985U/viewform?usp=send_form">https://docs.google.com/a/student.utwente.nl/forms/d/11rSv2oZ61tvfa70Iy6Pww6GCj9lqzm0m0tsKT5q985U/viewform?usp=send_form</a></p>
<p>It is a bit long but around 270 people already participated so it takes not that much of your time!!!</p>
<p>I would highly welcome your response!</p>
<p>You can also spread the survey in your community! </p>
<p>Many, many thanks and greetings from Berlin!!!!!</p>
<p>Sina</p>Sina-21Sat, 21 Jun 2014 11:40:05 -0400http://forums.udacity.com/questions/100197005/are-you-ready-to-adopt-googles-self-driving-carcs373
- Opportunity to contribute to MOOC research projecthttp://forums.udacity.com/questions/100196919/opportunity-to-contribute-to-mooc-research-project<p>Hi everyone,</p>
<p>My name is Emily and I'm conducting a survey of Massive Open Online Course (MOOC) users as part of my doctoral research at the Australian National University. As a Udacity user, I would really appreciate your input.</p>
<p>The survey is targeted people undertaking the free courseware stream of Udacity's courses, rather than the full paid course options. The main focus of the survey is on your attitudes and experiences of MOOCs as someone who uses such free online courseware. </p>
<p>The survey can be accessed here <a rel="nofollow" href="https://apollo.anu.edu.au/apollo/default.asp?pid=8079">https://apollo.anu.edu.au/apollo/default.asp?pid=8079</a>. Respondents say that it takes 10-30 minutes to complete. </p>
<p><strong>If you have not already done the survey (in this or in any other course), please consider doing it now.</strong> Your responses will be highly valued and will help create greater understanding of MOOCs generally.</p>
<p>Thank you for your time and consideration.</p>
<p>Kind regards,</p>
<p>Emily Longstaff</p>Emily-213Sat, 21 Jun 2014 06:18:33 -0400http://forums.udacity.com/questions/100196919/opportunity-to-contribute-to-mooc-research-projectst101ud675cs101ud651cs253cs373cs046cs387cs291cs222
- If you're confused... Read this.http://forums.udacity.com/questions/100195487/if-youre-confused-read-this<p>The peaks of the distribution follows where you're most likely to be as you move, and not the location of the doors. So it only makes sense that after sensing you are next to a door that the distribution shows peaks where there are doors, and it then also make sense that the peaks follow your motion (since they correlate with where you're most likely to be).</p>
<p>Possible confusion: Peaks show where there are doors.</p>
<p>Reality: Peaks indicate where you're most likely to find yourself. (and yes, sometimes you find yourself next to a door.)</p>
<p>Put simply, peaks appear in front of every door because you're sensing a door, which means you most probably are in 1 of 3 locations where there are doors (hence the 3 peaks). Since the peaks indicate your most likely position, moving right will produce a shift to the right (convolution) in the probability distribution.</p>Philippe-7Tue, 17 Jun 2014 23:24:36 -0400http://forums.udacity.com/questions/100195487/if-youre-confused-read-thisunit1-3m-48673629cs373
- Where did this come from?http://forums.udacity.com/questions/100195463/where-did-this-come-from<p>I'm lost... I followed the course upto here and I can't tell how I was supposed to know the answer to that question.<br>
Plus, with that explanation, I can't tell why it scales exponentially. 20 values for X, 20 values for Y, and 20 values for Orientation, in my mind, it adds up to 60 (20 * n ) values... </p>Philippe-7Tue, 17 Jun 2014 22:12:57 -0400http://forums.udacity.com/questions/100195463/where-did-this-come-fromps1-2m-48700566cs373
- Unit 5: Visualization of the PID control using matplotlibhttp://forums.udacity.com/questions/100194837/unit-5-visualization-of-the-pid-control-using-matplotlib<p>Using the example in the unit 5 (a car with a steerable front axle, reference trajectory and PID control), I have drawn the behaviour of the system for several cases.</p>
<p>The output figures show the following information:</p>
<ul>
<li>
<p>PID data ("PID control: cp,cd,ci-bias"), where cp, cd and ci are the proportional, derivative and integral parameters, and bias is the systematic bias.</p>
</li>
<li>
<p>Plot 1: the Y car coordinate along the time, where the desired trajectory is Y=0. </p>
</li>
<li>
<p>Plot 2: the calculated error for P, D and I parameters</p>
</li>
<li>
<p>Plot 3: the control action and the steering angle of the car</p>
</li>
</ul>
<p>The considered cases are the following:</p>
<p>a) The car starts at Y=0, no systematic bias. The trajectory is perfect. PID control is not neccesary.<br>
<img src="https://forums.udacity.com/upfiles/control1.png" alt="add your post above this line, enter image description here"></p>
<p>b) A bias of 10 degrees is considered. PID is not implemented. <br>
<img src="https://forums.udacity.com/upfiles/control2.png" alt="add your post above this line, enter image description here"></p>
<p>c) P controller is implemented (Kp=cp=0.2)<br>
<img src="https://forums.udacity.com/upfiles/control3.png" alt="add your post above this line, enter image description here"></p>
<p>d) PD controller is implemented adding the D term (Kd=cd=3.0)<br>
<img src="https://forums.udacity.com/upfiles/control4.png" alt="add your post above this line, enter image description here"></p>
<p>e) PID controller is implemented adding the I term (Ki=ci=0.004)<br>
<img src="https://forums.udacity.com/upfiles/control5.png" alt="add your post above this line, enter image description here"></p>
<p>f) PID with its parameters obtained using Twiddle algorithm. The figure shows a better behavior than before.<br>
<img src="https://forums.udacity.com/upfiles/control6-twiddle-values.png" alt="add your post above this line, enter image description here"> </p>
<p>The code:</p>
<pre><code>def run(cp, cd, ci, bias):
...
state = (i, myrobot.x, myrobot.y, myrobot.orientation, crosstrack_error, diff_crosstrack_error, int_crosstrack_error, steer)
result.append(state)
return result
# ------------------------------
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
dwfont = FontProperties()
dwfont.set_size('small')
lglocation = 'best'
tn = [v[0] for v in result]
px = [v[1] for v in result]
py = [v[2] for v in result]
orient = [v[3] for v in result]
cte = [v[4] for v in result]
dcte = [v[5] for v in result]
icte = [v[6] for v in result]
control = [v[7] for v in result]
conditions = str(cp)+","+str(cd)+","+str(ci)+"-"+str(bias)
plt.figure(1)
plt.subplot(3,1,1)
plt.xlabel('Tsim')
plt.ylabel('y')
plt.title('PID control:' + conditions)
plt.grid(True)
plt.plot(tn, py, '-')
plt.subplot(3,1,2)
plt.xlabel('Tsim')
plt.ylabel('error')
plt.grid(True)
plt.plot(tn, cte, '-', tn, dcte, '-', tn, icte, '-')
plt.legend(('CTE', 'difCTE', 'intCTE'), prop = dwfont, loc = lglocation)
plt.subplot(3,1,3)
plt.xlabel('Tsim')
plt.ylabel('angles')
plt.grid(True)
plt.plot(tn, orient, '-', tn, control, '-')
plt.legend(('orientation', 'steer'), prop = dwfont, loc = lglocation)
plt.show()
</code></pre>DOMINGOMon, 16 Jun 2014 08:36:27 -0400http://forums.udacity.com/questions/100194837/unit-5-visualization-of-the-pid-control-using-matplotlibpidcs373unit5
- There was an error running your solution: 103http://forums.udacity.com/questions/100191205/there-was-an-error-running-your-solution-103<p>I even experience that issue when I'm running the code of the correct solution and hit submit:</p>
<p>"There was an error running your solution: 103"</p>Benjamin-453Sat, 14 Jun 2014 14:26:23 -0400http://forums.udacity.com/questions/100191205/there-was-an-error-running-your-solution-103technical-supportcs373