1 / 24

Arduino for Robots

Arduino for Robots. Seminars at RSSC.org Sergei Grichine slg@quakemap.com. Agenda. Why Arduino Common boards – Uno, Mega , Pro Mini, Leonardo and just a chip. Why Arduino. Well designed cheap hardware Insanely simple programming at the beginning

vhowell
Download Presentation

Arduino for Robots

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. Arduino for Robots Seminars at RSSC.org Sergei Grichine slg@quakemap.com

  2. Agenda • Why Arduino • Common boards – Uno, Mega, Pro Mini, Leonardo and just a chip

  3. Why Arduino • Well designed cheap hardware • Insanely simple programming at the beginning • Friendly IDE – “keep it simple-stupid!” • Exceptional documentation • Community support, samples, forums, experts • Have a question? Just google it!

  4. Common boards: Uno

  5. Common boards: Mega 2560

  6. Leonardo – full USB

  7. A no-board solution – just an ATmega328 chip

  8. Pro Mini 328 5V

  9. Tools –

  10. Arduino Specs • Not much power – 16 MHz crystal, close to 16 MIPS • 8-bit AVR instruction set • Uno / ATmega328 • Flash Memory: 32 KB of which 0.5 KB used by bootloader • SRAM: 2 KB (a.k.a. RAM) • EEPROM: 1 KB (persistent storage for settings) • Mega: • Flash Memory: 256 KB of which 8 KB used by bootloader • SRAM: 8 KB • EEPROM: 4 KB

  11. Code tips • Not C++, Not quite Java – but close • Google “arduino reference” • Functions - http://arduino.cc/en/Reference/HomePage • http://arduino-info.wikispaces.com/HOME

  12. Code tour • Code: • Serial communication to a PC • Cooperative Multitasking • Preemptive Multitasking

  13. Serial Communication • BalancerHeadServo • Short ASCII messages (one-liners) • Start symbol (for example, *) • Channel • Command • Position-based, separated values • Checksum *3 5 456 553 87 214

  14. Serial Communication (PC side)

  15. Serial Communication (Arduino side) • BalancerHeadServo

  16. Serial Communication (Timing) • At 115200 baud = 10K bytes/sec *3 5 456 553 87 214 • 20 characters = 2ms • At 9600 baud – 25ms

  17. Multitasking • Typical tasks: • Read Sensors • Compute • Actuate • Communicate

  18. Cooperative Multitasking • Call functions from the loop() • Expect functions to return promptly • Common “tick” maintained by the loop code • Individual timing logic for each function

  19. Cooperative Multitasking • BalancerDfr

  20. Cooperative Multitasking • Everything is tied together • Delays can cause failure • Poor separation of code

  21. Preemptive Multitasking • Some kind of OS/Dispatcher required • Tasks are independent functions • Tasks are interrupted at any time • Tasks can sleep() and yield() • Use “volatile” for shared variables

  22. Preemptive Multitasking BalancerHeadServo #include <AVR_OS.h> AVR_OS os = AVR_OS(); // Create instance of OS multitasker os.os_init(); os.os_schedule_task(taskReadFeedbackPot, NULL, 0); os.os_schedule_task(taskActuate, NULL, 0); os.os_schedule_task(taskRemote, NULL, 0); os.os_schedule_task(taskReportState, NULL, 0); loop() { os.os_loop(); }

  23. Preemptive Multitasking // Define task 3 - check for commands over the serial line void taskRemote(void *arg) { while(1) { if(!CheckSerial()) // false if no input { os.os_sleep(20); // no input; must be at least TICK_INTERVAL 2 } else { os.os_yield(); // have more to read } } }

  24. Arduino for Robots Seminars at RSSC.org Sergei Grichine slg@quakemap.com

More Related