diff --git a/introduction/figure_8_graphs/distances.png b/introduction/figure_8_graphs/distances.png new file mode 100644 index 0000000000000000000000000000000000000000..22e724eff516f6c8a524ae69d90f0bea0a723075 Binary files /dev/null and b/introduction/figure_8_graphs/distances.png differ diff --git a/introduction/figure_8_graphs/locations.png b/introduction/figure_8_graphs/locations.png new file mode 100644 index 0000000000000000000000000000000000000000..1251a2c541cd8e401d55f96dcb61c054dec64a6d Binary files /dev/null and b/introduction/figure_8_graphs/locations.png differ diff --git a/introduction/launch/fibonacci.launch b/introduction/launch/fibonacci.launch index df85825c4fe89b750ca19c583b6a80591648b6ca..44ea7080397acf4deddf2f46b1d4086f52a6fdfc 100644 --- a/introduction/launch/fibonacci.launch +++ b/introduction/launch/fibonacci.launch @@ -36,7 +36,7 @@ using the launch file argument from above. --> <!-- BEGIN QUESTION 1.3 --> - <!-- REPLACE THIS LINE --> + <param name="fibonacci_index" value="$(arg index)" /> <!-- END QUESTION 1.3 --> </node> </launch> diff --git a/introduction/map_change/cse2_2map.png b/introduction/map_change/cse2_2map.png new file mode 100644 index 0000000000000000000000000000000000000000..e4f032e415b65b709ef75c377a0ea2b23e23883a Binary files /dev/null and b/introduction/map_change/cse2_2map.png differ diff --git a/introduction/runtime_comparison.png b/introduction/runtime_comparison.png new file mode 100644 index 0000000000000000000000000000000000000000..f647475d3b4f0bd184c29ca7bee27aca5df628d7 Binary files /dev/null and b/introduction/runtime_comparison.png differ diff --git a/introduction/scripts/fibonacci b/introduction/scripts/fibonacci index 1e580aeff415bda4bfa6d350c19d9f861cdafa71..0cec5464b00664611d8cc313ec3fe3edaad8e5db 100755 --- a/introduction/scripts/fibonacci +++ b/introduction/scripts/fibonacci @@ -14,8 +14,8 @@ from introduction.fibonacci import compute_fibonacci # False and code inside won't run. if __name__ == "__main__": # You can uncomment the following lines after completing compute_fibonacci. - # fibonacci_numbers = [compute_fibonacci(i) for i in range(11)] - # print(fibonacci_numbers) + fibonacci_numbers = [compute_fibonacci(i) for i in range(11)] + print(fibonacci_numbers) # Every node registers itself with the ROS master process, so we must pass a # name for the node. (A good practice is to use the same name as the script, @@ -32,7 +32,7 @@ if __name__ == "__main__": # to make sure it's the right type (an integer)! Feel free to specify a # default value. # BEGIN QUESTION 1.2 - "*** REPLACE THIS LINE ***" + fib_index = rospy.get_param("~fibonacci_index", 1) # END QUESTION 1.2 # Here's an example to create a ROS publisher. The queue_size defines how @@ -48,7 +48,7 @@ if __name__ == "__main__": # what type of messages do we want to publish from our Fibonacci publisher? # (Hint: check the imports at the top of the file.) # BEGIN QUESTION 1.2 - "*** REPLACE THIS LINE ***" + fib_publisher = rospy.Publisher(fib_topic, Int64, queue_size=1) # END QUESTION 1.2 # It can take some time for the publisher to be ready, so we'll wait before @@ -61,5 +61,5 @@ if __name__ == "__main__": # Call compute_fibonacci with the index you obtained earlier, then publish # the resulting Fibonacci number. # BEGIN QUESTION 1.2 - "*** REPLACE THIS LINE ***" + fib_publisher.publish(compute_fibonacci(fib_index)) # END QUESTION 1.2 diff --git a/introduction/scripts/pose_listener b/introduction/scripts/pose_listener index f72381fd94488b945f93fbefe43c761635bf14bf..48b5ee8fa4d1bcbda4b280891cd51c7d9fd36c31 100755 --- a/introduction/scripts/pose_listener +++ b/introduction/scripts/pose_listener @@ -48,5 +48,10 @@ if __name__ == "__main__": # Use norm_numpy to compute the distance from the origin over time. Then, # plot the distance over time as a line chart and save the plot. # BEGIN QUESTION 2.5 - "*** REPLACE THIS LINE ***" + plt.figure() + plt.plot(range(len(locations)), norm_numpy(locations)) + plt.title("Car Distance from origin over time") + plt.xlabel("Time") + plt.ylabel("Distance from Origin (m)") + plt.savefig("distances.png") # END QUESTION 2.5 diff --git a/introduction/src/introduction/fibonacci.py b/introduction/src/introduction/fibonacci.py index 4bbe1f5b81e2c9f13d93d51c76e011cf483a9379..c45e75f3122547c2bbed37941236f035b422bf3f 100644 --- a/introduction/src/introduction/fibonacci.py +++ b/introduction/src/introduction/fibonacci.py @@ -13,5 +13,15 @@ def compute_fibonacci(n): 3 """ # BEGIN QUESTION 1.1 - "*** REPLACE THIS LINE ***" + if n == 0: + return 0 + if n == 1: + return 1 + prev_num = 0 + next_num = 1 + for i in range(n-1): + intermed = prev_num + next_num + prev_num = next_num + next_num = intermed + return next_num # END QUESTION 1.1 diff --git a/introduction/src/introduction/indexing.py b/introduction/src/introduction/indexing.py index ef82445ebac3a492fcbbf6d025b1723f3b9deb32..0a0b9e9756bf756033785c282d66bdd4d6cfebee 100644 --- a/introduction/src/introduction/indexing.py +++ b/introduction/src/introduction/indexing.py @@ -1,4 +1,4 @@ -# from introduction.fibonacci import compute_fibonacci +from introduction.fibonacci import compute_fibonacci def extract_fibonacci_rows(data): @@ -17,7 +17,8 @@ def extract_fibonacci_rows(data): [34, 37, 38]]) """ # BEGIN QUESTION 3.1 - "*** REPLACE THIS LINE ***" + n , d = data.shape + return data[[compute_fibonacci(i) for i in range(n) if compute_fibonacci(i) < n]] # END QUESTION 3.1 @@ -44,5 +45,5 @@ def increment_rows_with_odd_first_element(data): [16, 17, 18]]) """ # BEGIN QUESTION 3.2 - "*** REPLACE THIS LINE ***" + data[data[: , 0] % 2 == 1] += 1 # END QUESTION 3.2 diff --git a/introduction/src/introduction/listener.py b/introduction/src/introduction/listener.py index 6a0b5aa8378d9b7fad5815ca47881eefde98cb77..11da8e14c61da68601ee2a7a62a42b4c3375b135 100644 --- a/introduction/src/introduction/listener.py +++ b/introduction/src/introduction/listener.py @@ -2,7 +2,7 @@ import numpy as np import rospy # BEGIN QUESTION 2.3 -"*** REPLACE THIS LINE ***" +from geometry_msgs.msg import PoseStamped # END QUESTION 2.3 @@ -17,7 +17,11 @@ def norm_python(data): n, d = data.shape norm = np.zeros(n) # BEGIN QUESTION 2.1 - "*** REPLACE THIS LINE ***" + for i in range(n): + sqrd_sum = 0 + for j in range(d): + sqrd_sum += (data[i, j] ** 2) + norm[i] = sqrd_sum ** (0.5) # END QUESTION 2.1 return norm @@ -33,7 +37,7 @@ def norm_numpy(data): # You can call np.sqrt, np.sum, np.square, etc. # Hint: you may find the `axis` parameter useful. # BEGIN QUESTION 2.2 - "*** REPLACE THIS LINE ***" + return np.sqrt(np.sum(np.square(data), axis=1)) # END QUESTION 2.2 @@ -50,7 +54,7 @@ class PoseListener: # "X_msgs/Y", the Python import would be "from X_msgs.msg import Y". # BEGIN QUESTION 2.3 "*** REPLACE THIS LINE ***" - self.subscriber = None + self.subscriber = rospy.Subscriber("/car/car_pose", PoseStamped, self.callback) # END QUESTION 2.3 def callback(self, msg): @@ -62,7 +66,8 @@ class PoseListener: # Extract and store the x and y position from the message data # BEGIN QUESTION 2.4 - "*** REPLACE THIS LINE ***" + position = msg.pose.position + self.storage.append((position.x, position.y)) # END QUESTION 2.4 if len(self.storage) == self.size: self.done = True diff --git a/introduction/tight_figure_8_graphs/distances.png b/introduction/tight_figure_8_graphs/distances.png new file mode 100644 index 0000000000000000000000000000000000000000..63fea24cf30483ab143542223f3e3e4ea9885dc6 Binary files /dev/null and b/introduction/tight_figure_8_graphs/distances.png differ diff --git a/introduction/tight_figure_8_graphs/locations.png b/introduction/tight_figure_8_graphs/locations.png new file mode 100644 index 0000000000000000000000000000000000000000..fcf7e9c331298d3de143c0a7a47cd3d52db276d1 Binary files /dev/null and b/introduction/tight_figure_8_graphs/locations.png differ diff --git a/introduction/writeup/README.md b/introduction/writeup/README.md index eff76ebff23d5004c8a8438702afcc4dba24d3ab..5d3d992ce139de5331b9563bfdb9169abbcd7230 100644 --- a/introduction/writeup/README.md +++ b/introduction/writeup/README.md @@ -1,4 +1,19 @@ # Project 1: Introduction [](../../../pipelines/submit-proj1/latest) -Replace this with your own writeup! +1. A node is a process responsible for handling a certain task. A topic is associated with a node, and responsible for communication between nodes by publishing some information processed by the node. A publisher is a set of rules that describe what information should be published to a certain topic and how it should be done. A subscriber is a set of rules used by certain node which ingest and process published information from topics. +2. A launch file is responsible for starting multiple nodes at once. This is useful when trying to do complex tasks with multiple dependent nodes. + +3. Screenshot of Map +  + +4. Runtime Comparison Graph +  + +5. Distance and Location graphs for figure 8 path +  +  + +6. Distance and Location graphs for tight figure 8 path +  + 