Digout and psupos, Iopac and iorequest – Pioneer 2 / PeopleBot User Manual

Page 50

Advertising
background image

Pioneer 2 Operating System

sfSMessage("Port# % reads %i",sfRobot.timer, sfRobot.analog);
Port# 5 reads 33
sfRobotComInt(35,2);
sfSMessage("Port# % reads %i",sfRobot.timer, sfRobot.analog);
Port# 2 reads 224

DIGOUT and PSUPOS

The eight digital output ports on the P2OS controller’s User I/O connector are both
reported in the standard SIP (digout) and controllable with the P2OS commands DIGOUT
and PTUPOS. Electrically, the ports are digital high (1) at ~5 VDC (V

cc

) and low (0) at ~0

VDC (GND).

For example, to read the state of the digital output ports with Saphira:

sfSMessage("Digout is %i",sfRobot.digout);
Digout is 240

Use the P2OS DIGOUT command to select and change the state of one or more of the
output ports at a time. DIGOUT takes a 2 byte (unsigned integer) argument. The first
byte is a mask whose bit pattern selects (1) or ignores (0) the state of the corresponding
bit in the second byte to set (1) or unset (0) the digital output port.

For example, you might use Saphira to set digital output ports 1 and 3, reset port 4, and

leave all the rest alone (retain original state):

sfRobotComInt2Bytes(30, 0x19, 0x09);

The digital output ports OD0-4 may also be used for pulse-width-modulated (PWM)
control of accessories, such as DC motor speed or RC-servo motor position control. Use
the PTUPOS command to select a port (msbyte) and specify its pulse-width (lsbyte) in 10
µsecond units.

For example, to have a repeating one millisecond pulse appear on PWM port #1 (pin 1
on the User I/O connector):

sfRobotCom2Bytes(41,1,100);

You've got to disable a running PWM port to use it as a digital output port:

sfRobotCom2Bytes(41,1,0);

In P2OS versions 1.J and later, the duty cycle is 20ms, with a 0-2.55ms pulse corresponding

to common RC-servo applications.

IOpac and IOREQUEST

P2OS 1.E introduced a new server information packet in which your P2OS-based robot

controller reports all of its I/O-connected sensor input and output values in a single cycle.

Your client software must explicitly request IO packets; they normally are disabled. Use
the P2OS IOREQUEST command #40 with an argument value of 0, 1, or 2. The
argument 1 requests a single packet to be sent within the next cycle. The request

argument value 2 tells P2OS to send IO packets continuously, at approximately one per
cycle, depending on serial port speed and other pending SIPs. Use the IOREQUEST
argument value 0 to stop continuous packets.

The common IOpac contains three digital input bytes, User I/O digin and two bumper
state bytes, front followed by rear; one digital output byte (digout); and five analog-to-
digital values corresponding to the ports AN1-5. Unlike the standard SIP, which contains

44

Advertising