1909 Old Mountain Creek Road, Greenville, SC 29609 tel:864.233.8330 fax:864.233.8331
 


SMt Applications

Hobby Robotics

In the example below, Simple Multi-tasking 'SMt' allows the Parallax BS2 to handle 8 Tasks* effectively in parallel and without interrupts. The additional resources needed are just 3 bits + 1 nibble of storage. The User code is virtually the same as would be used in a single-tasking program.

* For a specific micro - A Task is defined as any code that normally occupies the CPU long enough to prohibit other critical or essential code from executing. 

Examples for a BS2: wheel encoder, servo, software UART etc..

Robotics Template:

The Robotics Template is a framework to drop in User code for specific sensors, and write the servo calculation code. This is certainly the most simple implementation of SMt, yet it completely transforms the BS2 for the needs of Robotics. 

From the flow charts below it can be seen that all execution is based on the Tick timing. The example uses a 25ms Tick to satisfy the Servo needs. Any multiple of 5mS is possible. The Fig 1A shows the standard SMt components, of which only the Scheduler is needed for this particular Robotic program.

Pseudo BackGround Tasks:

The Pseudo BackGround code in the Template takes care of both the wheel encoders and the servos. Servicing the Encoders immediately after the Tick ensures consistent timing. The minimum Encoder pulse width is determined right there. Any User tasks that must be included on every Tick would also be located alongside.

In our example, the BackGround code leaves a safe 15mS remaining in each slot ready for the User. They can drop in their code for various sensors, and calculations for the next Servo settings.

The number of Ticks per cycle must be determined by the User. Even one Tick would be sufficient if just 2 Wheel Encoders, 2 Servos plus one SRF04 and an efficient calculation. And no feedback to the PC. 

 

 

The traced execution below is based on the template 'Tmpl_Rob.BS2' and has a cycle of 5 Ticks, of which 2 are used to feed data back to the PC as shown below.

Trace details top downwards:

Busy: A spare pin driven high whenever the BS2 was working.

  • Five equally spaced ellipses indicate the PulsOut periods for the two servos (blue if seen in color).
  • First intermediate ellipse left to right (green) for shifting in 2 Sharp GP2D02 sensor readings – their cycles were initiated 80 mS earlier – adjustable. Time remains for 4-6 more if power available.
  • Second (yellow) for a DevanTech SRF04. Time for more if guaranteed an echo.
  • Servo calculations (red) allotted 15 mS for 60+ Pbasic lines of code

PC Transmit (28,800 Baud) supplying 3 real-time User bytes from 2 sliders and a set of 8 Debug switches in the demo - time for more. Eight times per second.

BS2 Transmit (28,800 Baud) a total of 20+ bytes for the Application & Debug screens of the microGUI interface, plus a handshake with the PC. Eight times per second.

Two Wheel Encoders with 36 segments for 60 counts/sec total in above diagram – capable of 80/sec if precise mark/space. Trade possible for double speed.


Combining with microGUI for a Visual Demo:

Hardware:

Even without a BOE-BOT, establishing a 28,800 baud, bi-directional link between a PC and the BS2 will be worthwhile for other applications. 

Software:

BS2 Code:

With the hardware still fresh in mind, take a copy of Demo_Rob.BS2 from the CD's \Green directory and re-allocate the DPin, CPin and Tick as needed. Already the code for 5 sensors (2 wheel, 2 Sharp, 1 DevanTech) has been commented out. This leaves the pin allocation for the 4 connections made above, plus the 2 servos, to be adjusted.

At the same time look for the following code under 'INITIALIZATION':
Shiftout DPin, C1Pin, MsbFirst,[$05,$0D,$00,3]
If you are using an RS232 buffer rather than the resister shown above, then change the
$0D to $05. Adding '8' to baud rate#5, says 'Using a resister / no-inversion'. It is now ready to be loaded.

PC Code:

There is a Demo version of microGUI provided as a simple means of interfacing with the PC. It is self-extracting and can be found here: \ Demos \ microGUI \ microGUI.exe.

Once installed, replace the startup project with \ Projects \ Demo_Rob.Prj to achieve the screen below. The Comm settings need 28,800 Baud, Full Duplex and Header Length options.

Because SMt can squeeze in PC communication without compromising its own control tasks, the internal operation can be revealed in real-time. That means better insight and therefore solutions.

With wheels raised off the bench, hit 'On-Line'. The Amber LED's should start flashing. If not, and even after double checking all of the above, then pull the PC transmit and receive wires from the breadboard, connect together and try again. This will determine whether it is a PC or BS2 problem.

Once running, the servo controls and feedback will be active - all other BS2 code is still commented out. Now is the time to bring that code back in with your own pin allocation. Or to write your own code to drop into those time slots.

The BS2 code listing reveals which bytes are being exchanged with the PC. That includes the 6 switches on the right so that they can be used as remote controls of the BS2's internal operation.

Real-Time Analog View:

Aside from code, seeing the sensor outputs in analog form can really help finding the optimum angle/position. Move objects, change light levels, simulate low/loaded system voltage, and see the results on the screen, real-time. Beats any LCD, and costs less. 

 

  SMt Initialization Bytes:
  Byte#1 Byte#2 Byte#3 Byte#4
Tick Period Baud Rate Qualifier Receive Length
Details Units of 5ms 0-1200
1-2400
2-4800
3-9600
4-19200
5-28,800
6-38,400
7-57,600
Qualifier byte that must be received before accepting data Number of bytes to receive
Special cases None +8 says Resistor Input (no RS-232 buffer IC)

+16 says a CheckSum at end of Data  

Zero says a Qualifier will not be used Zero says the 1st data byte will specify the number of bytes to follow 
Example 5

25mS

8+5

No C/S, Resister I/P, 28k Baud

0

No Qualifier

6

6 Bytes

SETTING UP THE SMt:
Shiftout DPin, C1Pin, MsbFirst,[$05,$05,$00,6] 
$05 for Real-Time Clock specifies 5*5=25mS Ticks
$0D for Serial Receive specifies ---/---/---/CSum//INVERT/BD2/bd1/BD0
No checksum, Resistor 'Buffer', 28.8kBd (0-5=1.2 2.4 4.8 9.6 19.2 28.8)
$00 for Qualifier means 'None'
$06 specfies 6 bytes - the same length as set for the PC's Transmit Buffer
PulsOut C1Pin, EOXfer
Says 'End Of Transfer' - avoids specifying message lengths, & allows aborts
 

Download Example Files