Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects."— Presentation transcript:

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

2 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.

3 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)

4 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.

5 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

6 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

7 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. “

8 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.

9 RoboPong Start Program Template Dim taskStack(1 to 80) as Byte ' Memory allocation for 2nd task Dim continueFlag as Boolean = true ' Motor IO pins const p0 as byte = 5 const p1 as byte = 6 const p2 as byte = 7 const p3 as byte = 8 ' Data for Bottom Photoresistor to read start light const p15 as byte = 20 'IO pin for bottom light sensor const startLightThreshold as integer = 300 Dim bottomLightVal as Integer = 1 ' where we store sensor value

10 RoboPong Start Program Template Sub Main() ' Wait for start light signal while bottomLightVal < startLightThreshold ' read photoresistor value bottomLightVal = 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() Loop End Sub

11 RoboPong Start Program Template Sub 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

12 RoboPong Start Program Template Sub GetAllSensorVals() End Sub Sub 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 Servos End Sub Sub SetSideForMatch() End Sub

13 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

14 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)

15 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.

16 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.

17 Team Project Timeline Wed, January 12 – Tuesday, January 18 Teams work on project Wednesday-Friday, January 19-21 Team Presentations (2 per day)


Download ppt "PHY 235 Robotics Workshop Day 8 IO, Multi-tasking Sample Start Program Team Projects."

Similar presentations


Ads by Google