Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
ME 597/739- Lecture 2Autonomous Mobile Robots
Instructor: Chris ClarkTerm: Fall 2005
Programming the Mark III
1. Introduction
2. OOPic Programming3. MATLAB Example
Introduction
� demonstration of concepts covered in the course
� robot systems and modeling, control structures, sensors, estimation, localization and mapping, motion planning, and multi-robot systems
Programming the Mark III
1. Introduction
2. OOPic Programming3. MATLAB Example
OOPic Programming
1. Introduction to the Interface
2. Objects3. Virtual Circuits
4. Event Driven Programming5. Selected Objects
6. Math Functions
OOPic Introduction
� OOPic – Object-Oriented Programmable Integrate Circuit
� Allows programmer to write applications using objects to interact with the hardware
� Over 130 objects are available in the OOPic library
� Basic*, C, or Java syntax can be used in the script
� Virtual circuit capability to free up process time
OOPic Hardware Interface
� OOPic has 31 physical I/O lines� 11 classes of hardware objects are built into the OOPic:
– 1-Bit, 4-Bit, 8-Bit, 16 Bit digital I/O, i.e.. Line sensors– 16-Bit multiplexed digital I/O– A/D converter, i.e.. Sharp sensors– Pulse width modulator– Serial TX/RX– High speed timer– Matrix keypad decoder– RC servo controller, i.e.. Servo Motors
� Info on specific property related to each object can be found in the manual (OOPic’s objects)
OOPic MicroProcessorhttp://www.junun.org/MarkIII/datasheets/Controller_SCH.pdf
OOPic Sensors and Servoshttp://www.junun.org/MarkIII/datasheets/Controller_SCH.pdf
OOPic Pin-out (J1) and RS-232 (J7)http://www.junun.org/MarkIII/datasheets/Controller_SCH.pdf
OOPic Programming
1. Introduction to the Interface
2. Objects3. Virtual Circuits
4. Event Driven Programming5. Selected Objects
6. Math Functions
Objects in OOPic
� Objects are combinations of code and data that are treated as a single unit. Each Object has a unique name and all references to that object are done by that name.
� In OOPic, all the hardware I/O, variables, and virtual circuits are done by using Objects.
� Types of objects available in OOPic languages:– Hardware e.g. o2AD, oDIO1, oServo, oTimer– Processing e.g. oEvent, oGate– Variable e.g. oBit, oByte, oWord, oBuffer– System e.g.OOPic
Creating Objects in OOPic (Basic)
� Object declaration must occur at the beginning of the program before any other statements
� Object names: begin with a letter, not case sensitive
Dim <Object Name> As New <Object Type>
Dim eyeL As New oA2D;Dim Counter(3) As New oByte ‘oByte array of size 3Dim CCW As New oEventDim vCircuit1 As New oGate(2) ‘logic gate that has 2 inputsDim storage As New oBuffer(8) ‘buffer that has 8 bytes of storage
Creating Objects in OOPic (C/C++)
� Object declaration must occur at the beginning of the program before any other statements
� Object names: begin with a letter, not case sensitive
<Object Type> <Object Name> = New <Object Type>;
oA2D eyeL = New oA2D;oByte Counter[3] = New oByte; // oByte array of size 3oEvent CCW = New oEvent;oGate vCircuit1 = New oGate(2); // logic gate that has 2 inputsoBuffer storage = New oBuffer(8); // buffer that has 8 bytes of storage
Objects’ Properties
� Setting Property Values: <Object Name>.<Property> = <Expression>;
oServo servoL = New oServo;
servoL.IOLine = 10;
servoL.Operate = cvTrue;servoL.Value=36;
� Getting Property Values: <Variable> = <Object Name>.<Property>;
doubleSpeedL.Value=servoL.Value*2;
doubleSpeedL=servoL*2; // using default properties
NOTE: variable and hardware type Objects will always use value as thedefault property.
Example using Objects
/* This program will turn the LED on and off once every second */
oDio1 LED = New oDio1;Sub void Main(void){
LED.IOLine=31;LED.Direction=cvOutput;do{
LED.Value=OOPic.Hz1; // OOPic.Hz1, a system object that cycles } // every sec.while (1); // Continuous loop
}Other looping structures:For (<init>; <test>; <inc>) { <statements> [break;] <statements> }
OOPic Programming
1. Introduction to the Interface
2. Objects3. Virtual Circuits
4. Event Driven Programming5. Selected Objects
6. Math Functions
Virtual Circuits
� A virtual circuit is a circuit in an OOPic that appears to be a physical discrete electronic circuit, but is actually the OOPic operating system emulating the functionality of the circuit.
� Virtual circuits are used to perform functions that provide continuous processes.
� A virtual circuit can contain any kind of Objects, but at least one has to be a Processing Object (e.g. oCompare, oGate, oEvent, oMath)
� Objects are linked together in a virtual circuit using pointer property
� Syntax: <baseobject>.<property>.Link(<linkobject>.<property>);– NOTE: The link method is only available on properties that are
designated as a Pointer Property
Virtual Circuits – Pointer Properties
� Two types of Pointer Properties exist1. A Pointer to the target Object’s Default property (Object-Pointer)2. A Pointer to one the target Object’s Flag property (Flag-Pointer)
� Object Pointer example:oMath a = New oMath; // Create a processing object oMath name ‘a’oByte b = New oByte; // Create a variable object oByte name ‘b’
oDio8 c = New oDio8; // Create a hardware object oDio8 name ‘c’
Sub void Main(void)
{a.Input1.Link(b.Value); // Link 1st oMath input to the oByte object
a.Input2.Link(c.Value); // Link 2nd oMath input to the I/O port
}
Virtual Circuits – Pointer Properties
� Flag Pointer example:oGate a = New oGate; // Create a processing object oGate name ‘a’
oByte b = New oByte; // Create a variable object oByte name ‘b’oDio1 c = New oDio1; // Create a hardware object oDio1 name ‘c’
Sub void Main(void)
{a.Input1.Link(b.NonZero); // Link oGates’ 1st Input to oBytes’ NonZero property
a.Output.Link(c.Value); // Link oGates’ only Output to oDios’ Value property
}
� When Linking Pointer Properties to Objects properties, the Pointer Property’s type and the Object property’s type must always match
Virtual Circuits Example
/* This program will turn the LED on and off once every second using a virtual circuit */
oGate WIRE = New oGate;oDio1 LED = New oDio1;Sub void Main(void){
LED.IOLine=31;LED.Direction=cvOutput;WIRE.Input1.Link(OOPic.Hz1);WIRE.Output.Link(LED.Value);WIRE.Operate=cvTrue;
}
OOPic Programming
1. Introduction to the Interface
2. Objects3. Virtual Circuits
4. Event Driven Programming5. Selected Objects
6. Math Functions
Event Driven Program
� An Event Driven Program is a program where any change in state can cause a sub-procedure to be executed even when the program flow was not expecting to do so.
� OOPic’s Processing Object: oEvent� Steps involved in creating an application for the OOPic:
1. Create an OOPic application
2. Identify functions applicable to events3. Add the Event Object to the application
4. Create the Event Object’s sub-procedure: <ObjectName>_CODE
Event Driven Program Example
Sub void BLINK_CODE(void){
LED.Value=1;
LED.Value=0;
LED.Value=1;
LED.Value=0;
LED.Value=1;
LED.Value=0;
}
oEvent BLINK = New oEvent;oGate WIRE = New oGate;
oDio1 LED = New oDio1;
Sub void Main(void)
{
LED.IOLine = 31;
LED.Direction = cvOutput;WIRE.Input1.Link(OOPic.Hz1);
WIRE.Output.Link(BLINK.Operate);
WIRE.Operate = cvTrue;}
Sub-Procedure Example
Sub void BLINK (void){
LED.Value=1;
LED.Value=0;
LED.Value=1;
LED.Value=0;
LED.Value=1;
LED.Value=0;
}
oDio1 LED = New oDio1;
Sub void Main(void)
{
LED.IOLine=31;
LED.Direction=cvOutput;
If (OOPic.Hz1==1)
{
BLINK();
}
}
OOPic Programming
1. Introduction to the Interface
2. Objects3. Virtual Circuits
4. Event Driven Programming5. Selected Objects
6. Math Functions
Selected Objects
� OOPic System ObjectsOOPic.delay = xx; // Delay the next instruction for xx/100th of a sec.
OOPic.ExtVRef = cvOff; // Use 5 volt range for A/D converterOOPic.Hz1; // 1-bit value that cycles every second
OOPic.Hz60; // 1-bit value that cycles every 60Hz
� OOPic Processing Objects – oGate:– A Processing Object that can be configured to do multi-input logic gate
operations like AND, NAND, OR, NOR, XOR, XNOR, NOT, LATCH, Etc…
– Default: logical OR gate, up to 8 inputs.
– Alter logic gate through the use of negate input/output: InvertIn1=cvTrue InvertOut=cvTrue
OOPic Programming
1. Introduction to the Interface
2. Objects3. Virtual Circuits
4. Event Driven Programming5. Selected Objects
6. Math Functions
Math Functions
� Precedence of Operators1. Operators in parenthesis
2. Negation (-)3. Multiplication (*), Division(/) and Modulus(%)
4. Addition (+) and Subtraction (-)
5. Relational expressions (==,<>,<,>,<=,>=)6. Logical AND (&)
7. Logical OR (|)
8. Logical XOR (^)9. Logical NOT (~)
Math Functions
� Trigonometry functions:– the input argument for trigonometry functions like Sin and Cos is in
binary radian(Brads), which divides a full circle (360 degrees) into 256 even parts.
– 256 steps per 360 degrees is used so that a single byte can represent a full circle.
E.g. X=Cos(A):360 degrees CONVENTION BINARY RADIAN
0<A<360 0<A<255-1<X<1 -127<X<127
OOPic Caveats and Limitations
� 4K RAM Limit
� No support for floating point operations� Coarse servo value step increments
� Virtual Circuits can adversely affect sampling rates
Programming the Mark III
1. Introduction
2. OOPic Programming3. MATLAB Example
MATLAB Example
% create x/y data for 100 times steps% (10 seconds)for i=1:100
% increment timetime = i*deltat;
% find new x/y positionx(i+1) = x(i) + vx*deltat;y(i+1) = y(i) + vy*deltat;
end
% plot the path of the MarkIIIplot(x,y);
% ME597/739 MATLAB Example Program
% declare starting position for MarkIIIx = 0;y = 0;
% time increment (0.1 seconds)deltat=0.1;
% declare the rates of travel in the x/y% directionsvx=0.5;vy=0.2;
MATLAB Resources
� http://www.mathworks.com/access/helpdesk/help/helpdesk.shtml