Laboratory 3 - Chess - Center for Hybrid and Embedded Software

advertisement
Laboratory 3:
Cal Climber Part I
Orientation & Avoidance in C
Authors:
Jeff C. Jensen (National Instruments)
Trung N. Tran (National Instruments)
Instructors:
Edward A. Lee
Sanjit A. Seshia
University of California, Berkeley
EECS 149
February 20, 2011
1
Introduction
1.1
Goals
In this lab, you will:
1. Become familiar with the Cal Climber cyber-physical system.
2. Program a VxWorks embedded application in C.
3. Interface an external analog sensor.
4. Program basic navigation and object avoidance on an autonomous robot.
This lab should take 3 hours to complete. This is the first lab of a four-week sequence.
1.2
Required Reading
Read the following material in advance of your laboratory session:
1. Lee & Seshia [1]
(a) Ch. 3 §3.3 “Finite-State Machines” pp. 50-58.
(b) Ch. 7 §7.1.1 “Microcontrollers,” pp. 175.
(c) Ch. 7 §7.2 “Circular Buffers,” pp. 183.
(d) Ch. 9 §9.1.3 “Serial Interfaces,” pp. 232-236.
2. iRobot Create Owner’s Guide [2]
3. iRobot Create Open Interface [3]
4. ADXL322: Small and Thin 2g Accelerometer [4]
(a) §“Introduction”, pp. 1.
(b) §“Theory of Operation”, pp. 11-13.
5. sbRIO NI-9632 User’s Guide [5]
(a) Fig. 9, “Pinout of I/O Connector J7,” Analog I/O, pp. 12.
(b) §“Understanding Ground Connections,” pp. 15.
(c) §“Using the Reset Button,” pp. 21.
(d) §“Understanding LED Indications,” pp. 21.
(e) §“Analog Input,” pp. 39-42.
6. Wind River Workbench 2.5 Product Note [6]
(a) pp. 1-12.
7. Wind River Workbench User’s Guide [7]
(a) Ch. 1, “Introduction,” pp. 3-12.
(b) Ch. 2, §2.3.4 - 2.4.5, pp. 17-24.
(c) Ch. 19-20, pp. 231-238.
(d) Ch. 23, §23.2 “Launching a Kernel Task or Process,” pp. 284-289.
(e) Ch. 25, §25.1 - 25.4, pp. 305-311.
1
1.3
Equipment
1. PC computer running Windows XP.
2. Wind River Workbench 2.5 for VxWorks 6.3
3. PCI or USB 802.11g wireless card
4. Cal Climber
(a) iRobot Create
(b) National Instruments single-board RIO (sbRIO) NI-9632
(c) Asus WL-330ge wireless router
(d) Analog Devices ADXL-322
(e) DC voltage regulator
1.4
Cal Climber
The Cal Climber [8] is a cyber-physical system based on a commercially available robotics platform similar
to the the iRobot Roomba autonomous vacuum cleaner. The off-the-shelf platform is capable of driving,
sensing bumps and cliffs, executing simple scripts, and communicating with an external controller. The Cal
Climber is comprised of the iRobot Create, a National Instruments NI-9632 microcontoller, and an Analog
Devices ADXL-322 two-axis analog accelerometer. The Cal Climber demonstrates the composition of cyberphysical systems, where a robotics platform is modeled as a subsystem and treated as a collection of sensors
and actuators located beyond a network boundary.
1.4.1
iRobot Create
The iRobot Create [2] is a complete robot development kit that can be controlled without consideration of
mechanical assembly or machine code. It is important to understand that you are not directly programming
the iRobot, but a microcontroller which sends serial instructions to the iRobot according to iRobots proprietary Open Interface (OI) standard [3]. Instruction handling and actuation on the iRobot are handled by
an internal microprocessor. The iRobot OI defines the electronic and software interface for controlling the
iRobots behavior and reading of its sensors.
NOTE: The iRobot can be finicky about its state while charging; there are some modes in which the
robot will be connected to a charging source but will not actually charge. When correctly charging, the
iRobot Power LED should be red, slowly fading on and off. Solid red or flashing red indicate a charging
error. Solid green is, unfortunately ambiguous: it may indicate charging is complete, or it may indicate the
robot is powered on and running. You may disambiguate this by removing the charging source: if the robot
was powered and running, the power LED will remain solid green. If the robot is fully charged, the power
LED will turn off. If you have difficulty charging your robot, first unplug any charging sources, power off
the robot, and power off any internal devices such as the wireless router. Then connect the charging source.
Charge often and be sure to verify your robot is in charging mode when you leave the lab.
1.4.2
National Instruments sbRIO NI-9632
We have customized your embedded microcontroller with a “fixed-personality” FPGA; that is, an FPGA
that implements predetermined hardware peripherals. Your FPGA exposes:
1. UART serial port (3.3V TTL)
2. Analog input (8 channels, [−10V, 10V])
3. Analog output (8 channels, [−10V, 10V])
2
4. Digital input (8 channels, [0V, 3.3V])
5. Digital output (8 channels, [0V, 3.3V])
6. Pulse-width modulation (PWM) (4 channels)
7. Microsecond counter (64-bit)
A C driver library to support these peripherals has been provided. Review the header files in your template
project for further documentation.
Your desktop computer communicates with sbRIO over a standard ethernet connection. Each controller
has been assigned a static IP address, and automatically connects to a custom wireless network to allow
untethered communication. Please note that when powering on the robot, the wireless router and embedded
controller will take a few moments to connect to the network. You may ping the IP address of your target
to verify connection.
The sbRIO and wireless router are powered by the iRobot battery, and will power-on when the robot
does. There is a separate power switch in the cargo bay of your robot to turn off the wireless router in order
to save battery.
3
2
2.1
Procedure
Configure Equipment
Verify that you can ping the static IP address of your target when it is powered on and has had time to join
the wireless network.
2.2
Load the Template Project
Download the file lab03files.zip from the course website, and extract it to the U:\EECS149 folder. Extracting to this location will prevent several errors when loading the workspace and navigating to files needed
for debugging your target. The files for this lab should, after extraction, reside in U:\EECS149\Lab3
folder.
From the Start menu, open Wind River Workbench 2.5. When asked to select a workspace, navigate to
U:\EECS149\Lab3. This will open the project containing the code to get you started.
2.3
Review the Template Code
The template C program implements a simple state machine with three states, DRIVE, TURN, and STOP.
The template program simply drives for a fixed distance, then turns through a fixed angle, and repeats,
where distance and angle are reported by the iRobot Create. The Advance button on the iRobot signals the
program to stop.
Should any errors be returned by your program (they are the final value you see in the target console),
they may be found in the header file NiFpga.h.
2.4
Debugging
Standard output for printf() is directed to a target console that may be viewed from within your Workbench
development environment. This is a valuable way to get debugging information from your code. Consult the
Workbench User’s Guide for instructions on how to open the target console.
Your project has already been populated with target connections, one for each Cal Climber. Your Run
configuration is preconfigured for an unknown target; you will need to change this by selecting the correct
target in the ”Run...” menu.
To connect to your target, Workbench requires a copy of the kernel of the real-time operating system
you are using. This has been saved to your project folder; if you did not extract your project to the correct
location, you may need to configure your target connection with the correct location. The default location
is U:\EECS149\Lab3\VxWorks .
Ensure you can connect to your target, and are able to run the default code. WARNING: the default
program instructs the robot to drive, so make sure your robot is on the floor and away from obstacles when
the program begins.
3
Acknowledgment
We thank the University of California, Berkeley, Department of EECS Instructional Support Group (ISG)
and Electronics Support Group (ESG) for their continued efforts in supporting this lab.
4
References
[1] E.A. Lee and S.A. Seshia, Introduction to Embedded Systems - A Cyber-Physical Systems Approach, digital version 1.03. Berkeley, California, 2010. Available: http://leeseshia.org/releases/LeeSeshia_
DigitalV1_03.pdf. [Accessed January 25th , 2011].
[2] iRobot Corporation, iRobot Create Owner’s Guide. Available: http://www.irobot.com/filelibrary/
pdfs/hrd/create/Create%20Manual_Final.pdf. [Accessed February 2nd , 2011].
[3] iRobot Corporation, iRobot Create Open Interface version 2. Available: http://www.irobot.com/
filelibrary/pdfs/hrd/create/Create%20Open%20Interface_v2.pdf. [Accessed February 2nd , 2011].
[4] Analog Devices, “ADXL322: Small and Thin 2g Accelerometer” datasheet revision 0. Available: http://
www.analog.com/static/imported-files/data_sheets/ADXL322.pdf. [Accessed January 30th , 2011].
[5] National Instruments, “NI sbRIO-961x/963x/964x and NI sbRIO-9621XT/9632XT/9642XT User Guide”
June 10th , 2010 edition, National Instruments. Available: http://www.ni.com/pdf/manuals/375052c.
pdf. [Accessed January 27th , 2011].
[6] Wind River, “Wind River Workbench Product Note” version 2.5. Available: http://www.windriver.
com/products/product-notes/workbench-product-note.pdf. [Accessed February 5th , 2011].
[7] Wind River, “Wind River Workbench User’s Guide” version 2.5. Available: http://chess.eecs.
berkeley.edu/eecs149/documentation/wr_workbench_vxworks_users_guide_2.5.pdf.
[Accessed
February 5th , 2011].
[8] J.C. Jensen, E.A. Lee, and S.A. Seshia, “An Introductory Capstone Design Course in Embedded Systems,” IEEE Symposium on Circuits and Systems. Rio de Janeiro, Brazil, May 2011 (to appear).
5
4
Laboratory 3: Cal Climber Part I
Orientation & Avoidance in C
Objectives and Checkout
Name:
Date:
Lab Section:
1. (
/ 25) Connect to your target, build, download, and run the template project. Your robot
should drive in a square, and stop when the Advance button is pressed.
2. (
/ 75) Program the robot to avoid obstacles while driving in a fixed orientation. Software
must respond to collisions detected by momentary bump sensors on the front of the robot, and to
cliffs detected by infrared distance sensors on the bottom of the robot. After collision avoidance, your
robot should return to its original orientation. Use infrared cliff sensors, mechanical bump triggers,
and mechanical wheel drop triggers to detect collisions or cliffs. Keep in mind that a collision or cliff
event may occur during your collision avoidance algorithm.
/ 0) BONUS (up to +5): Configure your state machine so that the Play button serves as a
3. (
”play / pause” button; that is, when pressed, your robot toggles between running and dormant states.
5
Lab Writeup Prompts
In your lab writeup, please address the following questions:
1. Describe the process of compiling code in your development environment and how the output is transferred and executed on your target.
2. Describe your collision avoidance algorithm.
3. Which states did you add to your state machine, and why?
4. What did you like about this lab, and what would you change?
6
6
Laboratory 3: Cal Climber Part I
Orientation & Avoidance in C
Prelab Exercises
Name:
Date:
Lab Section:
1. How many sensors are on the bottom of the iRobot? Given the placement of some of the sensors, what
problems might this cause?
2. According to iRobot OI, what sequence of bytes must be sent to drive the iRobot forward (straight),
at a velocity of 300mm/s?
3. What is the command sequence to request a single sensor packet from the iRobot? The sensor group
requested is arbitrary, and can take on values in [0, 42].
4. What is the command sequence to enable a continuous stream of sensor packets?
5. What is the command sequence to enable a continuous stream of sensor packets?
6. How is the software for the template project architected? Is it an interrupt driven system? Polling?
Explain.
7
7. In the provided project template, UART functions use the xqueue data structure, which requires the
size of the data buffer to be a power of two. Why is this size restricted, and to what benefit? [Hint:
review the file xqueue.h].
8. Review the template project and describe how it processes errors.
8
Download