phy 235 robotics workshop day 8 io, multi-tasking sample start program team projects

17
PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

Upload: marian-mccarthy

Post on 17-Jan-2018

215 views

Category:

Documents


0 download

DESCRIPTION

IO Planning Possible uses for remaining 7 pins: DC Motor – This will require another motor controller board and 2-4 pins (1-2 motors) Servo Motors – This will require 1 signal pin for each servo IR distance/proximity sensor – 1 pin Other photo-resistors – 1 pin Bump (Whisker, Switch) sensor – 1 pin Ping – 1 pin LCD Display (This uses up to 4 of your IO pins)

TRANSCRIPT

Page 1: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

PHY 235 Robotics Workshop

Day 8

IO, Multi-tasking Sample Start Program

Team Projects

Page 2: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

IO Planning

• When planning the design of your robot, keep in mind how you will use the IO pins. You will need at least:• 4 pins for Lego Motor control• 4 pins for IR Beacon (discussed tomorrow)• 1 pin for bottom photo-resistor to sense start

light• This makes 9 pins that are necessary, leaving 7

pins for your use.

Page 3: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

IO Planning

• Possible uses for remaining 7 pins:• DC Motor – This will require another motor controller

board and 2-4 pins (1-2 motors)• Servo Motors – This will require 1 signal pin for each

servo• IR distance/proximity sensor – 1 pin • Other photo-resistors – 1 pin • Bump (Whisker, Switch) sensor – 1 pin• Ping – 1 pin• LCD Display (This uses up to 4 of your IO pins)

Page 4: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

Multi-Tasking

• Multi-tasking refers to the ability to create a program that will carry out more than one process at the same time.

• Zbasic allows for multi-tasking. If there is more than one task, then a task scheduler switches back and forth between tasks every CPU time tic (about 1.95 micro-sec’s)

• For the user, this gives the appearance of the two tasks happening simultaneously.

Page 5: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

Multi-Tasking

• The subroutine Main() is a single task. To create another task we need to do two things:

• Reserve space for the new task on the Task Stack. The task stack is a portion of RAM set aside exclusively for the new task.

• Create the task by writing

CallTask “NameOfTask” , taskStack

Page 6: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

Multi-Tasking - Example

• Here is an example:

Dim taskStack(1 to 80) as Byte Sub Main() CallTask "MyTask", taskStack Do Debug.Print "Hello from Main" Call Delay(1.0) Loop End Sub Sub MyTask() Do Debug.Print "Hello from MyTask" Call Delay(2.0) Loop End Sub

Page 7: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

Multi-Tasking - Example

• From the Zbasic Reference: “This program has two tasks: Main and MyTask. The Main task is created automatically and its task stack is automatically allocated all of the remaining User RAM after explicitly defined variables are allocated. In contrast, additional tasks such as MyTask have to be explicitly invoked using the CallTask statement and each task’s stack must also be explicitly allocated, for example by defining a Byte array as shown above. A task is said to be “active” if it has been invoked by CallTask and has not yet terminated. Both of the tasks above never terminate so they are always active. “

Page 8: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

RoboPong Start Program Template

• For our contest, we will need to have the robot keep track of time and shut itself off at the end of 60 seconds. • The best way to do this is to create a second task that will just sleep for 60 seconds and then shut things down. • The code on the next slide is a prototype you can use for developing your program.

Page 9: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

RoboPong Start Program TemplateDim taskStack(1 to 80) as Byte ' Memory allocation for 2nd taskDim continueFlag as Boolean = true

' Motor IO pinsconst p0 as byte = 5 const p1 as byte = 6const p2 as byte = 7const p3 as byte = 8

' Data for Bottom Photoresistor to read start lightconst p15 as byte = 20 'IO pin for bottom light sensorconst startLightThreshold as integer = 300 Dim bottomLightVal as Integer = 1 ' where we store sensor value

Page 10: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

RoboPong Start Program TemplateSub Main() ' Wait for start light signal while bottomLightVal < startLightThreshold

' read photoresistor valuebottomLightVal = GetADC(p15)

wend ' Start the timing task CallTask "StopAfter60Seconds", taskStack ' Determine which side you are on - white or black Call SetSideForMatch() ' Main loop - read sensors and take action Do until continueFlag = false Call GetAllSensorVals() Call TakeAction() LoopEnd Sub

Page 11: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

RoboPong Start Program TemplateSub StopAfter60Seconds() 'Sleep for 60 seconds Call sleep(60.0) ' Lock this task so no other tasks can execute Call LockTask() ' Set the continueFlag just in case some other task ' is still executing continueFlag = false ' Turn off all motors call ShutDownMotors() ' Exit the Main() task - should exit the program call ExitTask()End Sub

Page 12: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

RoboPong Start Program TemplateSub GetAllSensorVals() End SubSub TakeAction() ' Motors rotate one direction call putpin(p0, 1) call putpin(p1, 0) call putpin(p2, 1) call putpin(p3, 0) call delay(0.5) ' Motors rotate other direction call putpin(p0, 0) call putpin(p1, 1) call putpin(p2, 0) call putpin(p3, 1) call delay(0.5)End Sub

Sub ShutDownMotors() ' Stop both Lego Motors call Putpin(p0, 0) call Putpin(p1, 0) call Putpin(p2, 0) call Putpin(p3, 0) ' Stop any other DC motors or ServosEnd Sub

Sub SetSideForMatch() End Sub

Page 13: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

Team Projects

• In addition to preparing for the RoboPong contest, each team will research a specific advanced sensor (or interface device) to the Boe-bot CPU. • The sensors are in three categories:

I. Basic Sensor – Complex Usage• Break Beam Sensor (See F. Martin Text)• Shaft Encoding (See F. Martin Text)• Sharp GP2D02 Distance sensor (Optical) (See F. Martin Text)• Parallax 2-axis Joystick (Go to parallax.com for doc’s and examples

Page 14: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

Team Projects

II. Sensor Using Synchronous Serial IO (- Hvidsten Slides)• Honeywell HMC6352 Compass • Hitachi H48C Tri-Axis Accelerometer• Parallax ColorPal Color Sensor• Parallax Passive Infrared Motion Sensor• DS1620 Digital Thermometer(Go to parallax.com for doc’s and examples on these)

III. Interface to Winbond audio board (I have some ref’s for this project)

Page 15: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

Team Projects

• The projects in group II require the use of Synchronous-Serial Interfacing. I have slides from a previous course on this topic. • The most challenging project is the one in group III. I will assist any group who wishes to tackle this one.• The 6 teams will work on 6 different projects. Teams will be given the opportunity to choose a project type based on a random selection of team order.

Page 16: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

Team Project Requirements

• Each team will do research on their project, develop code, and produce two products:

1. A team presentation to the class on their project. The presentation should include:a. Background and theory on how sensor (device)

works.b. Sample code to show how to use sensor/device.c. Demo of Robot (Lego or Boe-bot) using the device.

2. A written AppNote. This is a 2-3 page document which explains the sensor, shows breadboard/schematic and shows sample code. An example of such an AppNote is included on the Documents page of the course web site.

Page 17: PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects

Team Project Timeline

Wed, January 12 – Tuesday, January 18Teams work on project

Wednesday-Friday, January 19-21Team Presentations (2 per day)