View the step-by-step solution to:

# CS 135 Fall 2012 Ali,Fraser,Goldberg,Hoey, Kaplan,Kogan,Petrick,Tompkins Assignment: 3 Due: Language level: Files to submit: Warmup exercises:...

Please solve Question 2 for me. I have no idea where to start. :(
2. In this question you will write a robot navigator. A robot’s state is given by its ( x,y ) position. Submit your answer in the ﬁle robot.rkt . (a) Give a structure deﬁnition and accompanying data deﬁnition for a robot navigation command structure RobotCmd that should have two ﬁelds in the following order: dist (a distance the robot should travel from the current robot location) and dir (that is one of the four symbols ’ north , ’ east , ’ south , or ’ west ). Observe that a value of dist is natural (including zero). (b) Write a function to help a robot accept directional movement commands. Your function should follow the following contract: ;; robot-ctrl: Posn RobotCmd Posn The ﬁrst parameter is a current robot position and the second is a navigation command. The function should produce a new robot location after moving the distance in the given direction from its current position that are speciﬁed in a navigation command. ( robot-ctrl ( make-posn 0 0 ) ( make-robotcmd 5 north )) ( make-posn 0 5 ) ( robot-ctrl ( make-posn 0 0 ) ( make-robotcmd 5 south )) ( make-posn 0 - 5 ) ( robot-ctrl ( make-posn 0 0 ) ( make-robotcmd 5 west )) ( make-posn - 5 0 ) ( robot-ctrl ( make-posn 0 0 ) ( make-robotcmd 5 east )) ( make-posn 5 0 ) (c) An obstacle is deﬁned by its position. If during navigation a robot meets an obstacle then the obstacle’s position is the new position of the robot. Write a function that should follow the following contract: ;; robot-obstacle-ctrl: Posn RobotCmd Posn Posn The function consumes three parameters: a current robot position, a navigation com- mand and a position of the obstacle. The function should produce a new robot’s posi- tion. If the robot does not encounter the obstacle then it will proceed to its ﬁnal location as in the previous question. If at the beginning the robot’s position coincides with the position of the obstacle then the robot does not move. ( robot-obstacle-ctrl ( make-posn 0 0 ) ( make-robotcmd 5 north ) ( make-posn 0 3 )) ( make-posn 0 3 ) ( robot-obstacle-ctrl ( make-posn 0 0 ) ( make-robotcmd 5 north ) ( make-posn 0 7 )) ( make-posn 0 5 ) ( robot-obstacle-ctrl ( make-posn 0 0 ) ( make-robotcmd 5 north ) ( make-posn 0 0 )) ( make-posn 0 0 ) (d) Assume that a robot can be controlled remotely by two controllers. Each controller is deﬁned by its position. The robot executes the order given by the closest controller to its current position at the time the order is issued. If the distance from the original robot location to the both controllers is the same then the robot does not move. Observe that a robot will pass through controllers (controllers are not obstacles). Give a structure deﬁnition and accompanying data deﬁnition for a structure RobotCtrlCmd that should CS 135 — Fall 2012 Assignment 3 2
Show entire document
Sign up to view the entire interaction

Dear Student, We have reviewed your assignment thoroughly based on details of your assignment... View the full answer

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

### -

Educational Resources
• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents