170 likes | 374 Views
Problem Solving & Algorithm Design for Robots. Nawwaf Kharma. Outline. Programming as Problem Solving with Applied Algorithms Algorithm Design as Instruction selection, configuration and sequencing The intimate relationship between robotic hardware and controlling software
E N D
Problem Solving & Algorithm Design for Robots Nawwaf Kharma
Outline • Programming as Problem Solving with Applied Algorithms • Algorithm Design as Instruction selection, configuration and sequencing • The intimate relationship between robotic hardware and controlling software • Several robotic (and human) programming problems, with hints! • Lessons learned and guidance issued
Programming as Problem Solving • One definition of programming is it is applied problem solving - You have a problem (e.g. need a program to calculate the area of the circle). - What inputs and outputs are needed? • How does what is entered produce the right output? • What needs to be done?
Group Exercise • Problem: An ant is in a corner of a room at the ceiling. There is a bowl of sugar at the opposite diagonal corner of the room on the floor. The room is a cube with the width of the room 3m. • In groups of 2 or 3 • Discuss different ways for solving the problem. • Use speech, writing and drawing to explain your ideas. • Can you use drawing to help you solve the problem? • Come up with a preferredsolution. • Can you prove that your solution is correct?
bumpIt(int time1) Using both touch sensors on ports 1 and 3 : If either touch sensor is true then move the robot backwards. bumper(x) Using a touch sensor on port x: Returns true if contact is made. checkBumpers() Using both touch sensors on ports 1 and 3 : If either touch sensor makes contact then true is returned else false is. checkLight(x) Uses a light sensor on port x: Returns true if the sensor is above a black line halt() Stops the robot until the view button is pressed change_direction(A,B,C) A sets the duration, B power to left motor and C power to the right motor checkLight_x(X) which produces true value for light levels measured to be between 33 and 42 by the light sensor on port X. measureLight(X) Returns the light level as an integer for a particular sensor port X. [from Lego] stop(); Stops both motors, then moves onto the next instructio; if you want it stop and wait use halt(). forward(time1); This moves the robot forward for time1 milliseconds (ms). spinRight(time1); Moves robot in a tight circle to the right using both motors time1 ms. turnRight(time1); This moves the robot to the right in a looser circle than spinRight() using both motors time1 ms. spinLeft(time1); This moves the robot in a tight circle to the left using one motor for time1 ms. turnLeft(time1); Moves robot to the left in a looser circle than spinLeft() using 1 motor time1 ms. backward(time1); This moves robot backward time1 ms.
Types of Instructions A. Get inputs from sensors B. Process inputs (and state variables) C. Make decisions D. Send outputs to effectors • Example: If (checkLight(1) && !checkLight(2)) { turnRight(1000); }
Instructions Relate 2 Hardware • Although: (a) instructions are given, such as the set of instructions for Lego Mindstorms robots or the Atmega8 chip; (b) and processing and decision making instructions are related to robot software design; • The actual number and especially meaning of the inputs and of the outputs are determined by robot hardware design: you map I/O from/to the real-world Distance ahead (x2) Movement of a leg (x6)
Instructions Relate 2 Software • Software are programs and programs are applied algorithms • Definition: algorithm is an effective method for solving a problem using a finite sequence of instructions[http://en.wikipedia.org/wiki/File:LampFlowchart.svg] • So, given a set of instructions, and a hardware design, the next thing is figuring our how to • Configure instructions: how many milliseconds? • Sequence instructions: check first then move. • Example If (checkLight_x(1) AND ! checkLight_x(2)) turnRight(2000);
Provisional Summary • The programmablecontroller of a robot determines your basic set of instructions • The hardware design of a robot determines the number and meaning of the inputs and outputs • These two (controller and hardware) define the limits of possible software solutions, where software = applied algorithm • So, algorithm design is really: instruction selection, mapping, configuration and sequencing.
Problem 1 Create an algorithm then program, using the instructions provided, to make a robot trace out a square. Each side of the square will be the same length as the distance covered by the robot when it moves forward a second. A. What algorithm came to your mind? Why? B. What does this algorithm demand in terms of inputs and outputs? C. Is this the only solution? Which one do you prefer and why? [problems 1-4 adapted from Problem Solving with Robots by Scott Turner]
Problem 2 • Get two identical robots to do a little dance. The moves are up to you. A robot will initiate the dance (a) when it has been moving for 5 seconds (without incident) and (b) upon detection of the other robot- you may assume there are no other objects in the area. When a dance terminates, the robots should select an arbitrary direction to move in. • What are the robots “states of existence”? • For every state, what inputs and outputs does it need? • What is the dance routine, and how does a robot select an arbitrary direction? • How would the addition of 4 walls (of an empty room) change your approach?
Problem 3 (human) • Write down a detailed list of instructions for opening a fizzy drinks bottle. • Your instructions must clear enough so that somebody could use to open the bottle based ONLY on your instructions. The person should not get wet whilstopening the bottle. • Constraints: • It is a person opening the bottle. • The bottle top is a screw top and is not glued down. • The person has use of both hands and is strong enough to open the bottle under normal circumstances. • The person understands simple words such as grip, turn, clockwise, anti-clockwise, left and right, on off and combinations ‘right hand on bottle top’. • You do need to specify which hand is used. • Your instruction should not be able to interpreted in an other way.
Problem 4 • Produce a line following robot routine. The robot should follow a black line. You may configure the robot with any number of light sensors in any configuration. If a light sensor is above a black line it returns a ‘true’ otherwise ‘false’. You may assume that 2 sensors can over the width of a black line. • What are all the robots “states of existence”? What defines every state? How do you decide a change of state? • When in a state, what routine should be executed? • Did you include start and end states? • How would the addition of noise (e.g. variable-width line) affect your design? • Should you design for a perfect world then • add “noise” or are you better off designing • For the real world?
Summary • Robot Based Problem Solving is actually the co-design of hardware and software (i.e. algorithmic) solutions to real world problems • Generally speaking, one should design a combined solution, which is implemented through hardware and software • In many cases, hardware design restricts (and as such defines the scope of) algorithmic solutions • One may approach robot control algorithms as one does a state machine, with • Different states each with its own handling routine • It is important, however, not to assume that your simplified model of the world is the real world!