Examples | Shop
 
Siteplayer™ Wireless Serial Communication with
TR2 Rover (Using the SitePlayer Development Kit)




 
This example demonstrates the ease in which serial data can be transmitted from a Web Page and SitePlayer™ module wirelessly. In this example, the Local DS-WCM is connected directly to the serial port of the Siteplayer Development board. The remote DS-WCM is connected to a TR2 Rover. The TR2 Rover uses the Net TR2 Rover OOPic code to move while searching for obstacles. If an obstacle is confronted, it will decide which way is clear to go and then continue on its journey.

By using the TR2 Net Rover Website and SitePlayer™, an override command can be sent to the rover allowing manual control from the website.

This example consists of fourteen separate documents that will interact with each other to create the application, these can be extracted from a zip file that can be downloaded HER
E.

SitePlayer™
TR2.SPD is a file used by Sitelinker™ for the initial variables. Here the IP Address, Sitefile, Sitepath and Includes, amongst others, are stated.

The setting of the Sitefile and Sitepath in TR2.SPD determines the SitePlayer Binary file (SPB) and the path and file allocations for the documents in this application respectively.
If the current settings are used from TR2.SPD, the files will be in the following allocations.

Sitefile “C:\Program Files\SitePlayer\TR2.spb”
Sitepath “C:\Program Files\SitePlayer\TR2”

The file TR2 contains the files:
“TR2Rover.htm”
“TR2RoverSlow.htm”
“TR2.SPI"
“TR2Slow.SPI”
“SitePlayer_Logo.Gif”
“round_lighted_red_on.Gif”
“spinner_down.Gif”
“spinner_left.Gif”,
“spinner_right.Gif”
“spinner_up.Gif”

The .HTM files are the HTML web pages. By changing settings in here, the websites appearance can be altered.

The .GIF files are called up by the Web pages. These are images used on the site.

The .SPI (Serial Peripheral Interface) files are pointers for any external device link events that occur. In this application, when baud rate or any command is selected, the same web page is loaded.

The files “TR2.SPD”, “UDPsend_def.INC” and “pcadef_TR2.INC” are, in this application, allocated in “C:\Program Files\SitePlayer”.

The .INC files are used by the .SPD file to set up UDP and file allocations within SitePlayer itself. In the file “pcadef_TR2.INC”, Com is the serial port output, and baud is the baud rate for serial communication. These are used within the web page.

DS-WCM Connection to Siteplayer
The Local DS-WCM has a serial port that can be connected directly to the SitePlayers DB-9 connector. By using a DS-W232CAB RS232 interface cable and a gender changer, the two units can be simply and neatly connected together.

DS-WCM Connection to OOPicII (TR2 Rover)
The Remote DS-WCM can be connected directly to the OOPicII via a DS-WI2CCAB I2C interface cable. Connection should be made from the DS-WCM’s I2C Input to pins 1-4 of the OOPicII. Using the WI2CCAB interface cable allows easy connection.

SiteLinker™
Sitelinker is used to download the web files to the SitePlayer TM. When using Sitelinker, ensure that the local and remote DS-WCM and TR2 Rover units are powered down so no serial communication will occur while the Sitelinker is downloading to SitePlayer.

In SiteLinker, Open “TR2.SPD”. Now select “Download” then “Make and Download”.

The Sitelinker creates an .SPB file, which is downloaded to the SitePlayer.

Select Browser and load http://192.168.1.250/TR2Rover.htm. Power up the Local DS-WCM and Remote WCM and TR2 Rover. Press reset on the OOPic, set the baud rate and when you want to, send an override command from the website to the TR2 Rover.

SitePlayer is a Registered Trademark of Netmedia Inc.


 

'****************************************************************
'****************************************************************
'** Description: TR2 Rover with wireless Net Manual overide.
'** This program utilises the TR2 Servo sweep routine which
'** improves the obstacle avoidance capabilities of the TR1 Rover.
'** If the rover gets stuck. A manual overide command can
'** be sent from the Siteplayer allowing complete user control
'** from your website of the rovers movements.
'**
'**
'** Compiler Version: 4.0.0
'** Created: 30/10/02 Revision: 1.00
'** Written by: Total Robots (Jamie Finnan)
'** Adapted from TR2 Rover with Wireless Control Module
'**
'** TR-014
'**
'****************************************************************
'****************************************************************
Dim SR as new oWord 'the sonar reading
Dim Right_Servo As New oServo 'Right Servo Wheel
Dim Left_Servo As New oServo 'Left Servo Wheel
Dim Sweep_Servo As New oServo 'Ultra Sound Sweep Servo
Dim Left_Test As New oBit 'Test Bit
Dim Right_Test As New oBit 'Test Bit
Dim echoTimer as new oTimer 'Echo Timer for Ultra Sound
Dim tmrControl as new oGate (1) 'Timer Control for Echo
Dim TRIGGER as new oDio1 'Trigger Pulse Input
Dim ECHO as new oDio1 'Echo Pulse Output
const cLeftForward = 10 'Constant
const cLeftForwardSlow = 27 'Constant
const cLeftBackward = 50 'Constant
const cLeftBackwardSlow = 30 'Constant
const cRightForward = 50 'Constant
const cRightForwardSlow = 25 'Constant
const cRightBackward = 10 'Constant
const cRightBackwardSlow = 22 'Constant
Dim WCM As New oi2c 'WCM I2C output
Dim WriteVal As New oByte 'Value to write to remote node
Dim LocNode As New oByte 'Local node address
Dim RemNode As New oByte 'Remote node address to write to
Dim ReadVal As New oByte 'Value read from remote node
Dim StoreVal As New oByte
Dim ReadAdr As New oByte 'Node address of remote node value came from
Dim Error As New oBit
Dim OError As New oBit
Dim ReadOK As New oBit
Dim Done As New oBit'****************************************************************
'****************************************************************
Sub Main()
Call Initialise 'Setup
LocNode = 2 'Define local node address (0-255)
RemNode = 0 'Define remote node address (0-255)
Const WriteTOut = 2 'Define write timeout in seconds (0-15)
Const WCMAdr = &h60 'WCM A0 & A1 jumpers ON (Range &h60-&h63)
Call SetUpWCM 'Setup WCM ready for communication
do
call ReadWCM 'Wait for data from remote node
If StoreVal = 90 then
Call Manual
End if
Call Sweep
Loop
End Sub
'****************************************************************
Sub SetUpWCM()
'Set the DS-WCM I2C address shifted right by 1 bit
WCM.Node = WCMAdr 'Setup I2C address for WCM

'Setup I2C addressing to WCM
WCM.Width = cv8bit 'Control Info is 1-byte
WCM.Mode = cv10bit 'I2C mode is 10-Bit Addressing
WCM.NoInc = cvFalse 'Increment on every read/write
WCM.Location = 0 'Specifiy local node address location
WCM.Value = LocNode 'and write local node address
End Sub
'****************************************************************
'Read data from the Remote WCM.
Sub ReadWCM()

WCM.Location = 2 'Start at read status flag (R2)
If WCM.Value = 255 then'Has data been received (R2) ?
If WCM.Value = 0 then 'If so has overflow error 'occured (R3) ?
ReadAdr = WCM.Value 'If not then store WCM address 'data came from
ReadVal = WCM.Value 'and store data
OError = cvFalse 'Indicate no overflow error
ReadOK = cvTrue
StoreVal=ReadVal 'Store the data from siteplayer
else
OError = cvTrue 'Indicate overflow error has 'occured
ReadOK = cvTrue 'Indicate data has been 'read
ReadAdr = WCM.Value 'Store WCM address data 'came from
ReadVal = WCM.Value 'and store data

end if
else

OError = cvFalse 'If no data read then no error
ReadOK = cvFalse 'and no data
end if


End Sub
'****************************************************************
'Manual mode when the correct data has been sent. This routine
'checks the byte of data sent to the Rover against its known byte 'list.
Sub Manual()

Call Servo_Stop
Do
Call ReadWCM
If StoreVal = 25 then
Call Servo_MoveLeft 'This will turn the rover 'right.
StoreVal = 0 'Clear Read Value
elseif StoreVal = 50 then
Call Servo_MoveRight 'This will move the rover left.
StoreVal = 0 'Clear Read Value
elseif StoreVal = 75 then
Call Servo_MoveForward 'This moves the rover forward.
StoreVal = 0 'Clear Read Value.
elseif StoreVal = 85 then
Call Servo_SmallMoveLeft 'Moves rover slightly left
StoreVal = 0
elseif StoreVal = 95 then
Call Servo_SmallMoveRight 'Moves rover slightly right
StoreVal = 0
elseif StoreVal = 100 then
Call Servo_MoveBackward 'This moves the rover 'backwards.
StoreVal = 0 'Clear Read Value.
elseif StoreVal = 125 then
Call Servo_Stop 'This stops any servo 'movement.
StoreVal = 0 'Clear Read Value.
elseif StoreVal = 130 then
Call Slow_Servo 'Go to slow rover options
StoreVal = 0
elseif StoreVal = 150 then
StoreVal = 0 'Clear Read Value.
Exit Sub 'Exit the subroutine and set
End if 'rover back into autonomous 'mode.
Loop
End Sub
'****************************************************************
Sub Slow_Servo()
Do
Call ReadWCM
If StoreVal = 125 then
Call Servo_Stop 'This stops any servo 'movement.
StoreVal = 0 'Clear Read Value.
elseif StoreVal = 160 then
Call Servo_MoveForwardSlow 'Move rover forward 'slowly
StoreVal = 0
elseif StoreVal = 170 then
Call Servo_MoveBackwardSlow 'Move rover 'backwards slowly
StoreVal = 0
elseif StoreVal = 180 then
Call Servo_MoveRightSlow 'Move rover right 'slowly
StoreVal = 0
elseif StoreVal = 190 then
Call Servo_MoveLeftSlow 'Move rover left 'slowly
StoreVal = 0
elseif StoreVal = 110 then
StoreVal = 0 'Clear Read Value.
Exit Sub 'Goto fast controls
End if
Loop
End Sub
'****************************************************************
Sub Sweep()
Call Servo_MoveForward 'Move Rover Forward
Sweep_Servo.Value = 10 'Start Position of Sweep Servo
Do
Sweep_Servo.Value = (Sweep_Servo.Value + 5) 'Increment sweep
call readSonar
if (SR<40) then 'If Sonar detects anything within 40cm
Call Evade 'Then evade the object.
end if
If Sweep_Servo.Value > 50 Then 'Is Servo at end of Sweep?
Call Sweep_Back
End If
Call ReadWCM
If StoreVal = 90 then
Call Manual
End if
Call Servo_MoveForward 'Move rover forward
Loop
End Sub
'****************************************************************Sub Sweep_Back()
Do
Sweep_Servo.Value = (Sweep_Servo.Value - 5) 'Decrement sweep
call readSonar
if (SR<50) then 'If sonar detects anything within 50cm
Call Evade 'Then evade object
end if
If Sweep_Servo.Value < 10 Then 'Servo returned to start position when <10
Exit Sub
End If
Loop
End Sub
'****************************************************************
sub readSonar ()
echoTimer.value=0 'Set up Echo timer
TRIGGER.value=1 'Send Trigger pulse to SRF04
TRIGGER.value=0
oopic.delay=1
while (ECHO.value=1)
wend
SR=echoTimer.value/36 'this converts the sonar
'reading to a distance
'in cm
oopic.delay=1
end sub
'****************************************************************
Sub Initialise()
OOPic.Delay = 200
Call Servo_Setup 'Servo setup
Call Sonarsetup 'Sonar setup
End Sub
'****************************************************************
Sub Servo_Setup()
Right_Servo.IOLine = 10 'Right Servo on SV6
Right_Servo.Center = 32 'Center position for Servo
Right_Servo.Operate = CVTrue 'Set Right Servo
Left_Servo.IOLine = 5 'Left Servo onSV5
Left_Servo.Center = 32 'Center position for servo
Left_Servo.Operate = CVTrue 'Set Left Servo
Sweep_Servo.IOLine = 12 'Sweep Servo on SV8
Sweep_Servo.Center = 22 'Center Sweep Servo
Sweep_Servo.Operate = CVTrue 'Set Sweep Servo
Call Servo_Stop 'Stop Right and Left Servo's
End Sub
'Note that center positions can vary on different servo motors.
'****************************************************************
sub Sonarsetup ()
echoTimer.ExtClock=cvOff
echoTimer.PreScale=3
TRIGGER.IOLine=4 'connect Trigger Pulse Input
'on SRF04 to SV4
TRIGGER.Direction=cvOutput
TRIGGER.value=0
ECHO.IOLine=3 'connect Echo Pulse Output
'to SV3
ECHO.Direction=cvInput
tmrControl.Input1.Link(ECHO.value)
tmrControl.Output.Link(echoTimer.Operate)
tmrControl.Operate=cvTrue
End Sub
'****************************************************************
Sub Servo_Stop()
Left_Servo.Operate = cvFalse 'Stop Left Servo
Right_Servo.Operate = cvFalse 'Stop Right Servo
End Sub
'****************************************************************
Sub Evade()
Call Servo_Stop
If Sweep_Servo < 12 Then 'Check for obstacles on the left
Call Servo_SmallMoveRight 'If obstacle, move right
else
If Sweep_Servo > 48 Then 'Check for obstacles on the right
Call Servo_SmallMoveLeft 'If obstacle, move left
else
Call Decide 'Otherwise obstacle in front
End If
End If
Call Servo_MoveForward
End Sub
'****************************************************************
Sub Decide()
Again:
Call Servo_MoveBackward 'Move rover backwards
OOPic.Delay =150
Call Servo_Stop
Call Search_Left 'Scan Left for obstacles
Call Search_Right 'Scan Right for obstacles
If Right_Test.Value = 0 Then 'Move to the right if clear
Call Servo_MoveLeft
OOPic.delay=100
Call Servo_stop
else
If Left_Test.Value = 0 Then 'Move to the left if clear
Call Servo_MoveRight
OOPic.delay=100
Call Servo_stop
Else
Goto Again 'If both sides blocked, redo routine
End If
End If
End Sub
'****************************************************************
Sub Search_Left()
Call Set_Left 'Set Left start position
OOPic.Delay = 50
Left_Test.Value = 0 'Clear Left_Test bit
Call Sweep_Left
End Sub
'****************************************************************
Sub Sweep_Left()
Do
Sweep_Servo.Value = (Sweep_Servo.Value + 1) 'Increment Sweep
call readSonar 'Read sonar for any barriers
if (SR<40) then 'If barrier within 40cm then
Left_Test.Value = 1 'Set LeftTest bit if yes.
end if
If Sweep_Servo.Value = 29 Then 'If sweep is at 29 then finish
Exit Sub
End If
Loop
End Sub
'****************************************************************
Sub Set_Left()
Sweep_Servo.Value = 4 'Start point for sweep
End Sub
'****************************************************************
Sub Search_Right()
Call Set_Right
OOPic.Delay = 50
Right_Test.Value = 0 'Clear Right Test Bit
Call Sweep_Right
End Sub
'****************************************************************
Sub Sweep_Right()
Do
Sweep_Servo.Value = (Sweep_Servo.Value - 1) 'Decrement file
call readSonar
if (SR<40) then 'Any barriers within 40cm?
Right_Test.Value = 1 'Set Right_Test bit if yes.
end if
If Sweep_Servo.Value = 34 Then '34 is end of sweep
Exit Sub
End If
Loop
End Sub
'****************************************************************
Sub Set_Right()
Sweep_Servo.Value = 55 'Start point for right sweep
End Sub
'****************************************************************
Sub Servo_MoveForward() 'Routine to move rover forward
Call Servo_Stop
Left_Servo.Value = cLeftForward
Right_Servo.Value = cRightForward
Left_Servo.Operate = cvTrue
Right_Servo.Operate = cvTrue
End Sub
'****************************************************************
Sub Servo_MoveLeft() 'Routine to move rover Right
Call Servo_Stop
Right_Servo.Value = cRightBackward
Left_Servo.Value = cLeftForward
Right_Servo.Operate = cvTrue
Left_Servo.Operate = cvTrue
End Sub
'****************************************************************
Sub Servo_MoveBackward() 'Routine to move rover backward
Call Servo_Stop
Left_Servo.Value = cLeftBackward
Right_Servo.Value = cRightBackward
Left_Servo.Operate = cvTrue
Right_Servo.Operate = cvTrue
End Sub
'****************************************************************
Sub Servo_MoveRight() 'Routine to move rover Left
Call Servo_Stop
Left_Servo.Value = cLeftBackward
Right_Servo.Value = cRightForward
Left_Servo.Operate = cvTrue
Right_Servo.Operate = cvTrue
End Sub
'****************************************************************
Sub Servo_SmallMoveLeft() 'Routine to move rover a little left
Call Servo_Stop
Right_Servo.Value = cRightForward
Right_Servo.Operate = cvTrue
OOPic.delay = 50 'Move for 0.5 secs
Call Servo_Stop 'Stop rover
Call Servo_MoveForward 'Move rover forward
End Sub
'****************************************************************
Sub Servo_SmallMoveRight() 'Routine to move rover a little right
Call Servo_Stop
Left_Servo.Value = cLeftForward
Left_Servo.Operate = cvTrue
OOPic.delay = 50 'Move for 0.5 secs
Call Servo_Stop 'Stop Rover
Call Servo_MoveForward 'Move rover forward
End Sub
'****************************************************************
Sub Servo_MoveForwardSlow() 'Routine to move rover forward slowly
Call Servo_Stop
Left_Servo.Value = cLeftForwardSlow
Right_Servo.Value = cRightForwardSlow
Left_Servo.Operate = cvTrue
Right_Servo.Operate = cvTrue
End Sub
'****************************************************************
Sub Servo_MoveLeftSlow() 'Routine to move rover Right slowly
Call Servo_Stop
Right_Servo.Value = cRightBackwardSlow
Left_Servo.Value = cLeftForwardSlow
Right_Servo.Operate = cvTrue
Left_Servo.Operate = cvTrue
End Sub
'****************************************************************
Sub Servo_MoveBackwardSlow() 'Routine to move rover backward slowly
Call Servo_Stop
Left_Servo.Value = cLeftBackwardSlow
Right_Servo.Value = cRightBackwardSlow
Left_Servo.Operate = cvTrue
Right_Servo.Operate = cvTrue
End Sub
'****************************************************************
Sub Servo_MoveRightSlow() 'Routine to move rover Left slowly
Call Servo_Stop
Left_Servo.Value = cLeftBackwardSlow
Right_Servo.Value = cRightForwardSlow
Left_Servo.Operate = cvTrue
Right_Servo.Operate = cvTrue
End Sub
'****************************************************************
'****************************************************************

Examples | Shop