Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
RUST IS FOR ROBOTS
Building an autonomous vehicle with
Rust and the Raspberry Pi
Andy Grove - Boulder/Denver Rust Meetup -...
PLEASE ASK QUESTIONS!
ABOUT ME
• Co-Founder & Chief Architect @ AgilData
• Started in C++, then 20 years Java, now Scala & Rust
• AgilData is bu...
G-FORCE
(ironic name)
WHY THIS PROJECT?
• I was inspired by the last Rust meetup and I agreed
to give a talk at this one
• Sparkfun Autonomous V...
OBJECTIVES
• Navigate to pre-determined waypoints (GPS co-ordinates)
• Using GPS and compass to determine location and hea...
COMPONENTS
DIGITAL IO INTERFACES
• GPIO - General Purpose IO
• Turning pins on and off, or reading high/low inputs from pins
• SPI - ...
WHY RASPBERRY PI?
• Great support for Linux (Raspbian)
• Designed for hacking hardware
• Hardware support for GPIO, SPI, a...
RASPBERRY PI 3
WHY RUST?• Better performance than Java or scripting languages
(assumption)
• Safe language - nobody wants their robot to ...
SERIAL IO
• Linux presents serial IO devices as files e.g.
/dev/ttyUSB0
• Use udev rules to map to convenient names e.g.
/...
SERIAL IO
PARSING GPS DATA
• GPS data uses NMEA format
• Simple comma-separated format
• Example: $GPGLL,4916.45,N,12311.12,W,225444...
SPI
• SPI devices are represented as files too!
• Example: /dev/spidev0.0
• Use spidev crate to interact
I2C
• I2C devices are represented as… yes, files!
• Example: /dev/i2c-1
• Use i2cdev crate
GPIO
• GPIO devices are represented as files too, but the sysfs_gpio crate abstracts this
• GPIO is the simplest interface...
CALLING C CODE
USING FFI
OPENCV
AUGMENTING VIDEO
DEMO
SPARKFUN AVC PRACTICE
https://www.youtube.com/watch?v=IaBiMtyEZOs
WHAT WENT WRONG?
• Ultrasonic sensors aren’t fantastic at detecting hay bales,
especially at an oblique angle
• LIDAR woul...
RUST/PI CHALLENGES
• Compilation is SLOW on the Pi
• Splitting project into multiple crates helps a lot
• Incremental comp...
RESOURCES
WEB SITES
• For inspiration, tutorials, blogs, parts, visit these sites:
• sparkfun.com
• adafruit.com
• instructables.com...
MAKER COMMUNITY
• Local maker spaces
• Solid State Depot (Boulder)
• The Gizmo Dojo (Broomfield)
• Tinkermill (Longmont)
•...
QUESTIONS?
• Source code
• https://github.com/andygrove/rust-avc
• Contact
• Twitter: @andygrove73
• Email: andy.grove@agi...
Upcoming SlideShare
Loading in …5
×

Rust is for Robots!

3,988 views

Published on

My experiences building an autonomous vehicle with Rust and the Raspberry Pi.

Published in: Technology
  • Be the first to comment

Rust is for Robots!

  1. 1. RUST IS FOR ROBOTS Building an autonomous vehicle with Rust and the Raspberry Pi Andy Grove - Boulder/Denver Rust Meetup - 9/21/16
  2. 2. PLEASE ASK QUESTIONS!
  3. 3. ABOUT ME • Co-Founder & Chief Architect @ AgilData • Started in C++, then 20 years Java, now Scala & Rust • AgilData is building its next product in Rust • Also offering Rust consultancy and project kick-start services • I enjoy being a “Maker” in my spare time • Digital electronics, robotics, 3D printing, woodworking, etc, etc.
  4. 4. G-FORCE (ironic name)
  5. 5. WHY THIS PROJECT? • I was inspired by the last Rust meetup and I agreed to give a talk at this one • Sparkfun Autonomous Vehicle Competition (AVC) was coming up • This was a great opportunity for me to learn about using Rust on the Raspberry Pi and get to share that knowledge • And four weeks was plenty of time, right?
  6. 6. OBJECTIVES • Navigate to pre-determined waypoints (GPS co-ordinates) • Using GPS and compass to determine location and heading • Change speed of left/right motors to control movement • Avoid obstacles • Using ultra-sonic sensors to detect distance to objects • Record instrumented video • Essential for debugging
  7. 7. COMPONENTS
  8. 8. DIGITAL IO INTERFACES • GPIO - General Purpose IO • Turning pins on and off, or reading high/low inputs from pins • SPI - Serial Peripheral Interface • Four wire interface (MISO, MOSI, SCLK + dedicated SS per slave) • I2C - Inter-Integrated Circuit (pronounced I-squared-C) • Two wire interface (SDA - Serial Data & SCL - Serial Clock) • Each device has unique 7-bit address • Serial • Familiar to most of use - same as file or network i/o
  9. 9. WHY RASPBERRY PI? • Great support for Linux (Raspbian) • Designed for hacking hardware • Hardware support for GPIO, SPI, and I2C • Support for webcams and video processing (with GPU acceleration) • USB makes it easy to connect to serial devices • Built-in WiFi • All this for $35 !
  10. 10. RASPBERRY PI 3
  11. 11. WHY RUST?• Better performance than Java or scripting languages (assumption) • Safe language - nobody wants their robot to fail with a segmentation fault or null pointer exception • Crates already exist for interfacing with GPIO, SPI, I2C and Serial • Rust is natively supported on the Pi using rustup.rs • Easy to call existing C libraries such as OpenCV with zero overhead
  12. 12. SERIAL IO • Linux presents serial IO devices as files e.g. /dev/ttyUSB0 • Use udev rules to map to convenient names e.g. /dev/gps • USB-Serial adapter required to connect to serial devices • serial-rs crate makes it easy to configure baud rate, parity, etc • Use std::io::Read and std::io::Write to interact with device
  13. 13. SERIAL IO
  14. 14. PARSING GPS DATA • GPS data uses NMEA format • Simple comma-separated format • Example: $GPGLL,4916.45,N,12311.12,W,225444,A
  15. 15. SPI • SPI devices are represented as files too! • Example: /dev/spidev0.0 • Use spidev crate to interact
  16. 16. I2C • I2C devices are represented as… yes, files! • Example: /dev/i2c-1 • Use i2cdev crate
  17. 17. GPIO • GPIO devices are represented as files too, but the sysfs_gpio crate abstracts this • GPIO is the simplest interface - simply read or write 1 or 0 to an individual pin • Raspberry Pi does not support analog IO directly • Suitable for: • Interacting with digital circuits • Blinking LEDs • Not suitable for: • Driving high current devices like motors
  18. 18. CALLING C CODE USING FFI
  19. 19. OPENCV
  20. 20. AUGMENTING VIDEO
  21. 21. DEMO SPARKFUN AVC PRACTICE
  22. 22. https://www.youtube.com/watch?v=IaBiMtyEZOs
  23. 23. WHAT WENT WRONG? • Ultrasonic sensors aren’t fantastic at detecting hay bales, especially at an oblique angle • LIDAR would have been better, but also more $$ • Magnetometer (compass) was not correctly calibrated and I also hadn’t accounted for magnetic declination (8 degrees!) • Four weeks wasn’t quite long enough for this project • But I learned a lot!
  24. 24. RUST/PI CHALLENGES • Compilation is SLOW on the Pi • Splitting project into multiple crates helps a lot • Incremental compilation will be here soon • Compilation on the Mac natively is not possible since the libraries are Linux-specific • Cross-compiling is a pain to set up, but probably worth the investment • Docker can help • Severe lack of sample code or existing libraries in Rust for any sensors, so you have to write your own (using Arduino libraries as a reference)
  25. 25. RESOURCES
  26. 26. WEB SITES • For inspiration, tutorials, blogs, parts, visit these sites: • sparkfun.com • adafruit.com • instructables.com • hackaday.com • make.com • tindie.com
  27. 27. MAKER COMMUNITY • Local maker spaces • Solid State Depot (Boulder) • The Gizmo Dojo (Broomfield) • Tinkermill (Longmont) • Mini Maker Faires • NoCo Mini Maker Faire (Loveland) - October 8/9 • Denver Mini Maker Faire - Summer 2017
  28. 28. QUESTIONS? • Source code • https://github.com/andygrove/rust-avc • Contact • Twitter: @andygrove73 • Email: andy.grove@agildata.com • Blog: http://theotherandygrove.com

×