1 / 24

IN.1010, IN.0111, IN.0114, IN.1910, IN.0300 Robotics Project Autumn Semester 2013

IN.1010, IN.0111, IN.0114, IN.1910, IN.0300 Robotics Project Autumn Semester 2013 Lecture 2: Basic Coding & Introduction to the Physical Arena Prof. B. Hirsbrunner (beat.hirsbrunner@unifr.ch) Thomas Rouvinez (thomas.rouvinez@unifr.ch). Today. Goals of Today's Course Comments Variables

bethan
Download Presentation

IN.1010, IN.0111, IN.0114, IN.1910, IN.0300 Robotics Project Autumn Semester 2013

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IN.1010, IN.0111, IN.0114, IN.1910, IN.0300 Robotics ProjectAutumn Semester 2013 Lecture 2: Basic Coding & Introduction to the Physical Arena Prof. B. Hirsbrunner (beat.hirsbrunner@unifr.ch) Thomas Rouvinez (thomas.rouvinez@unifr.ch)

  2. Today • Goals of Today's Course • Comments • Variables • Assignment • Constants • Expressions • Events • Navigation • Exercise

  3. Goals of Today's Course • Learn to write ASEBA scripts • Apply programming language basics: • Comment and indent your code • Assign variables • Use constants • Execute expressions • Receive events • Experiment with the use of the e-puck motors

  4. Comments (1) A comment starts with ’#’and ends with the line Commenting your code properly is mandatory • In English (best practice) • It should help you and other people to better understand your code Example : # Comment line 1 # Comment line 2

  5. Comments (2) • Place comments at key locations (above a function, within a portion of cryptic code, etc.) • Place in all your codes a header :##### ROBOTICS PROJECT 2013                             #                                            # Author: Sheldon Cooper # Group: 01  # Created: 22.09.2013                    # Last modified:  24.09.2013#                            # Description: e-puck implementation for ...      #                                            ###

  6. Code Formatting (1) • Correct formatting makes reading code easier

  7. Code Formatting (2) • Weuseindentation (usuallyonetabcharacter per levelofindentation) • A levelisdefinedby an instruction (do, while, if, etc.)

  8. Code Formatting (3) Withoutformatting oneventevt.lockDoorifargs[0] == col.BLUEthenevt.blueFound = TRUE elseifargs[0] == col.REDthenevt.redFound = TRUE end With proper carriagereturn oneventevt.lockDoorif (args[0] == col.BLUE) thenevt.blueFound = TRUE elseif (args[0] == col.RED) thenevt.redFound = TRUE end With proper carriagereturnandindentation oneventevt.lockDoorif (args[0] == col.BLUE) thenevt.blueFound = TRUE elseif (args[0] == col.RED) thenevt.redFound = TRUE end

  9. Variables • Named reference to one or several values: var demo_variable (also ok: demoVariable) var demo_table[5] • English and lower case letters only • Name should be memorisable and informative • In ASEBA, unsigned integers with 16 bits ranging from -32768 to 32767 0 1 2 3 4

  10. Assignment (1) • Assign an initial value to a variable: var demo_variable demo_variable = 1 var demo_table[5] = 31, -23, 37, -43, 578 1 0 1 2 3 4 31 -23 37 -43 578

  11. Assignment (2) • Change the value of a variable: demo_variable = 2 demo_table[0] = 8 demo_table[3] = 14 2 Variables that can hold multiple values are called arrays! 0 1 2 3 4 8 -23 37 14 578

  12. Constants • A constant is a named reference to a value which doesn't change (can be defined only once) • It's a convention in some programming language that constants are in upper case letters with seperator ‘_’

  13. Expressions (1) • Expressions allow us to do mathematical calculations • Operators (sorted by priority): • Multiplication (*), division (/), modulo (%), • addition (+), substraction (-), shift left (<<), shift right (>>) • You can use brackets '()' to change the priority

  14. Expressions (2) • Bitwise left shift: • The last 0/1 to the left is lost • 0 is inserted on the right 1 << 1 = 2, in bits: 01 << 1 = 10 • Bitwise right shift: • The first 0/1 on the right is lost • 0 is inserted on the left 3 >> 1 = 1, in bits: 11 >> 1 = 01

  15. Internal Events (1) • A robot interacts with the environment by: • Perceiving the environment through sensors • Making decisions with the internal processor • Executing actions with it's motors and leds robot computer sensors motors environment

  16. Internal Events (2) • Internal events happen forexample, whenthevalueswhichareobtainedbythecameraarerefreshed. This happens in regular time intervalsandtherobotgetsnotifiedbytherefresh-events (e1, e2, ...). robot computer e1 e2 e3 e4 e5 e6 e7 sensors motors time environment

  17. Internal Events (3) • Wheneverthecameraobtainsfreshpixelvalues, itreceives an eventandtheprogramcounterjumpstothelabeloneventcameraandexecutesthecodeuntilitreachesthenextlabel. onevent camera # the camera values have been updated ... onevent ir_sensors if behaviour == EXPLORE then ....

  18. External Events (1) • A robot can interact with other robots using events Size of the array variable that is sent with the external event onevent demo_event # TODO: write event received code here # TODO: use arguments received with the event # Use args[0] to get transmitted value

  19. External Events (2) • External events are not caused by sensors, they are created by the programmer to send information to other robots. Remember the code from exercise 1: # e-puck number 4 will execute this sequence onevent backward # TODO: complete the code # right after e-puck number 1 has sent the event emit backward speed # wait loop

  20. External Events (3) • A robot can send an event to another robot with: var event_argument = 1 emit demo_event event_argument

  21. Restrictions • All e-pucks contain a microprocessorwith a limited amountofmemory • Script sizetoobigfortargetbytecodesize • Amountofexecutablecodeis limited by: • Code complexity (stackorheapoverflow) • Code length (dataoverflow) • Write simple andefficientcode

  22. Navigation • Motor: • Numberofsteps per seconds • Positive values == rotatesclockwise • Negative values == rotatescounterclockwise • Trajectory: dependingofthevaluesofspeed.leftandspeed.right, therobot will waitormove : • straightforwardorbackward • straightorwith a curve : rightorleft, forwardorbackward

  23. Exercise • Series 2: Run yoyo-wiggle.aesl in the physical arena

  24. Thank you for your attention

More Related