ooPIC Logo

ooPIC Programmer's Guide

 Chapter 15 - URCP

Main Index
Prg Index
Back to top of pageConcepts

The Uniform Robotic Control Protocol (URCP) is a protocol that is the result of developing control systems for several unrelated devices that use a common numbering system.  The common numbering system allows the devices to communicate with and/or control other devices which use the same numbering system without the need for conversion.  The goal is to use the lease amount of memory and processing required to evaluate the most amount of data.  In URCP, the common value types used in robotics use a single byte of memory. 

Currently, there are 3 levels of URCP.

  1. Distance
  2. Heading
  3. Power

In each of these, the numbering system used was for the advantage of the robot's computational capabilities and in no way was biased towards working with any particular standard navigational system. 

Three Objects encapsulate the 3 URCP data types.
oDistanceManages a URCP Distance value.xxx
oHeadingManages a URCP Heading value.xxx
oPowerManages a URCP Power value.xxx

Back to top of pageHeading
 URCP Heading values deal with circles, trigonometry, angles and headings.  The common numbering system chosen for this is Binary-Radians (Brads) which divides a full circle (360 degrees) into 256 even parts.  256 brads per 360 degrees is used so that a single byte can represent a full circle.

Objects such as the oJoystick, oTracker, oServoX, etc. use URCP Heading values.  This allows one device such as the oTracker to read a heading from a line on the ground.  This value then can be copied to an oServoX Object to steer a robot in the direction needed to follow a line.  Similarly, the oJoystick can be used to provide the heading.

The oHeading Object manages a URCP Heading value.  It includes methods for manipulating and converting the heading value. 


Degrees vs. Brads.

In standard mathematics, it has long since been decreed that there should be 360 degrees of arc in a complete circle. This was because the corner of an equilateral triangle was divided into 60 degrees and 60 degrees was chosen because it could be divided by 2, 3, 4, 5 and 6 without remainder.  However, 360 does not work well in a binary system for the following reasons:

1. The very reason that 360 was chosen does not work well in binary.360 degrees
Division by non-binary numbers such as 3 and 5 are not binary friendly.  What makes this even worse is that 360 does not work well with decimal numbers when divided up multiple times. When dividing by 2 or 3, it can only be evenly divided 2 or 3 times before the divisions become fractional numbers. 
For example: 360/3=120, 120/3=40, 40/3=10.3333  and  360/2=180, 180/2=90, 90/2=45, 45/2=22.5
2. 360 does not fit evenly into a binary number.
While binary numbers are typically 8 or 16 bits, it takes 9 bits to represent 360.  In order to make it fit into a single 8-bit binary number, it must be divided in half (0 to 180).  However, when that is done, not only does it loose some precision, but it no longer fits the mathematical formulas.  If 16-bits are used to represent 360 then 7 bits are wasted. 
3. 360 does not wrap.
On a compass 300 degrees + 100 degrees equals 40 degrees which wraps properly on a compass, but in binary, 300+100 = 400 which does not wrap properly.

The solution to all these problems is to use Binary-Radians (Brads) which has 256 Brads of arc in a complete circle. 

1. A circle with 256 Brads can be evenly divided up all the way down to 1 brad.
(256/2=128, 128/2=64, 64/2=32, 32/2=16, 16/2=8, 8/2=4, 4/2=2, 2/2=1)
2. 256 fits evenly into a binary number because it is a binary number.
This takes the full advantage of every bit of precision that a byte will allow.  If more precision is needed, a 2nd byte can be tacked onto the lease significant side acting as a fractional part of Brad resulting in a circle being dived down to 65536 even parts.  This also can be evenly divided down to 1 part.
3. 256 wraps properly.
Any Brad added to any Brad will result in the correct resulting Brad.  Even with a second byte for precision, the formula still works properly. 
For example: 48 + 128 = 176  (128 is 1/2 of the circle and 48 and 176 are on opposite sides of the circle.)

Brads have more advantages:

1. The Most-Significant-Bit (MSB) can be used as sign bit.
If the Most-Significant-Bit (MSB) is used to denote a twos-complement-negative number, then the compass bearing becomes a heading.  From 0, a single Brad to one direction is +1 and a single Brad to the other direction is -1.  Straight ahead is a positive number and straight back is a negative number.  Using Brads in this way, they are still evenly divisible and wrap properly.
2. Flipping the direction is an easy formula. 
  • To flip from left to right, negate the number.  (+64 becomes -64) and (+16 becomes -16)
  • To flip from front to back, invert the MSB.  (112 becomes 16) and (-112 becomes -16)
Back to top of pageDistance
 URCP Distance values deal with Distances, Lengths, Proximities.  The common numbering system chosen for this is 64 steps per foot.  256 steps over a 4 foot range is used so that a single byte can represent a "Personal space" of 4 feet for a robot.  This gives a resolution down to better than one fifth of an inch or about one half of a centimeter.

Objects such as the oSonarDV and the oIRRange use URCP Distance values.

The oDistance Object manages a URCP Distance value.  It includes methods for manipulating and converting the distance value. 

Back to top of pagePower
 URCP Power values deal with the relative power of an object.  The common number system chosen for this +127 for full power, -128 for full reverse power and 0 for no power.  This range is used so that a single byte can represent the full range of power. 

Typically the URCP Power value is used to drive motors where the power value is translated directly to a speed value.  This allows a single byte to control the forward and reverse speed capabilities of a robots movement.

Objects such as the oDCMotor use URCP Distance values.

The oPower Object manages a URCP Power value.  It includes methods for manipulating and converting the power value. 


ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.