170 likes | 312 Views
IN.1010, IN.0111, IN.0114, IN.1910, IN.0300 Robotics Project Autumn Semester 2013 Lecture 3 : Energy Management Prof. B. Hirsbrunner (beat.hirsbrunner@unifr.ch) Thomas Rouvinez (thomas.rouvinez@unifr.ch). Today. Quick review Goals Debugging Conditional statements Boolean values
E N D
IN.1010, IN.0111, IN.0114, IN.1910, IN.0300 Robotics ProjectAutumn Semester 2013 Lecture 3: Energy Management Prof. B. Hirsbrunner (beat.hirsbrunner@unifr.ch) Thomas Rouvinez (thomas.rouvinez@unifr.ch)
Today • Quick review • Goals • Debugging • Conditional statements • Boolean values • Events with several arguments • Energy pool • Exercise
Quick Review (2) • How can we store integers in ASEBA? • Will this code run? demo_table[5] demo_table = 1, 2, 3, 4, 5 • Which operators do we have? • Why are arguments useful for events?
Goals of Today's Course • Debugging in Aseba • Programming language basics: • Conditional statements • Events with several arguments • Using native functions • Using and managing an energy pool with the e-pucks
Debugging • Debugto find errors in implementedalgorithms • Controltheexecutionoftheprogram • In ASEBA • Stoptheprogramduringexecutionwith break points • Observethecontentof different variables duringexecution • Emitcontroleventsatcertainpoints • Controlexecutionofprogramcode
Debugging 1. break points 2. observe variables 3. control events 4. execution
Conditional Statements (1) • Only execute a portion of the instructions depending on a condition: var limit = 20 var demo_variable = 10 if demo_variable < limit then demo_variable = demo_variable + 1 end
Conditional Statements (2) • Choose a different setofinstructionsdepending on 'if' condition : trueorfalse varlimit = 20 vardemo_variable = 10 ifdemo_variable < limitthen demo_variable = demo_variable + 1 else demo_variable = limit end
Comparison Operators if demo_variable == limit then # equals if demo_variable != limit then # is different from if demo_variable > limit then # is larger than if demo_variable < limit then # is smaller than if demo_variable >= limit then # is larger or equal if demo_variable <= limit then # is smaller or equal
Combined Conditionals • Both conditions have to be met: if (demo_variable >= lower_limit) and (demo_variable <= upper_limit) then ... • At least one condition has to be met: if (demo_variable == lower_limit) or (demo_variable == upper_limit) then ... • Negative condition: if not (demo_variable >= upper_limit) then
Boolean Values • Boolean valuescanonlybetrueorfalse • Manyprogramminglanguageshavesupportforbooleans, but ASEBA doesn't • In ASEBA, youcanuseconstants varis_changed = FALSE varis_blue = TRUE
Event Arguments • A robot can send an event to other robots with 0 to 32 arguments: var one_arg = 1 var multi_args[2] = 10, 20 emit create_no_arg emit create_one_arg one_arg emit create_multi_args multi_args Number of arguments
Energy Pool (1) • Use of native functions: • Predefined functions and functions written in C • Native functions are called with the keyword ‘call’ • Native functions take their arguments by reference, i.e. their value can be changed in the function • No return value Note: C supports only argument passing by value, i.e. their value cannot be changed in the function. Call-by-reference is simulated in C by passing an address.
Energy Pool (2) • Native energy functions: • send: send energy into the pool (can only be called if energy in the e-puck > 9) • receive: receive energy from pool • amount: get the amount of energy available in pool var pool_amount = 0 call energy.send(5) call energy.receive(5) call energy.amount(pool_amount)
Exercise Session 3 • Complete the exercise series 3 and hand in your solution by next Monday at 2 pm.