beautypg.com

Pioneer 2 User Manual

Page 41

background image

Pioneer Mobile Robots

35

For example, the first Saphira statement queries for the current analog port and its A/D value. The second
Saphira command changes the selected port which value gets reported through the last Saphira command in
the example:

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 Pioneer 2 User I/O connector are both reported in the P2OS SIP
(Digout value) and controllable with the P2OS commands DIGOUT and PTUPOS. Electrically, the ports
express a digital high (1) state as ~5 VDC (Vcc) 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);
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 bit pattern expressed in the second byte.

Accordingly, you might use Saphira to set digital output ports 1 and 3, reset port 4, and leave all the rest
alone (retain orginal state):

sfRobotComInt2Bytes(30, 0x19, 0x09);

The digital output ports OD0-4 may also be used for pulse-width-modulated 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);

BUMPSTALL

Because the robots are programmed to climb, it can take up to a second or more to to detect object

collisions with motor stalls. With P2OS version 1.5, we introduced a responsive way to stop the Pioneer 2
DX or AT within a few milliseconds upon collision with an obstacle: BUMPSTALL. With the robot
equipped with forward and/or rear bumpers, you can now program P2OS to immediately stop the robot and
notify the client of a stall if any one of the forward or rear bump sensors get triggered.

Send the BUMPSTALL command with a integer argument of 0 to disable the BUMPSTALL behavior

(default on startup). Use the argument value 1 to enable BUMPSTALL only when a forward bump sensor
gets triggered; 2 for rear-only BUMPSTALL; or 3 for both rear and forward bump ring-activated stalls.

For example, to enable BUMPSTALL when any one of the five contact sensors on a forward bump ring

gets triggered:

sfRobotComInt(44,1);

BUMPSTALL requires supporting bump ring accessory.