Examples | Shop
 
OOPic-C X4
 
This simple example application shows the simplicity in driving an X4 rover with an OOPic-C. This example is almost identical (pin configuration is different) to the OOPic-R version supplied with the X4 Rover MKI. This is due to both the OOPic-R and OOPic-C having the same firmware version (B.2.x+).

The OOPic-C fits neatly onto the RCBV2 board (stand-off adapter required and can be supplied), as it is pin for pin compatible with the BX24 and BS2 microcontrollers.

In this example, an X4 rover with SRF04 ultrasonic range finder is used. The X4 rover moves forwards looking for any obstacles that may impede its progress. If such obstacle is found, the X4 will reverse, spin right searching for a clear gap and when a gap is found, continue its journey into that space.
Connections between the X4 and RCBV2 are as follows:
     
X4   RCBV2
Left Servo Connector - SV1
Right Servo Connector - SV2
SRF04 (using SRF04 cable) - RCBV2
Echo and +5V - SV3
Trigger and Gnd - SV4
     
This program can be developed to include a servo sweep option, which will widen the obstacle detection range.

A Wireless Handheld Controller and Wireless Control Module could also be used allowing a manual override program to take effect.

Download the code here.

 

'**************************************************************************
'**************************************************************************
'Description: X4 Rugged Terrain Rover with RCBV2 and OOPic-C.
'This code enables the X4 to drive autonomously while looking for obstacles.
'On encountering any blockages, the rover will reverse, then spin right to check for
'open spaces to drive 'into.
'
'Created: 19/05/03 Revision 1.00
'Written By:Total Robots
'TR-X4RCBV2C
'
'**************************************************************************
'**************************************************************************
Dim right as new oServoSP1 'Right Servo's
Dim left as new oServoSP1 'Left Servo's
Dim Sonar as new oSonarDV 'SRF04
Dim SR as new oWord 'Word file for SRF04
'**************************************************************************
Sub main()
Sonar.IOLineE = 10 'Echo Line on SV3
Sonar.IOLinep = 11 'Pulse line on SV4
Sonar.Operate = 1 'Sonar on
right.Ioline = 9 'Right Servos SV2
left.Ioline = 8 'Left Servos SV1
right.operate = cvTrue 'Right on
left.operate = cvTrue 'Left on
oopic.delay = 200
Call Forward 'Move rover forward
Call Read_Sonar 'Take sonar readings
End Sub
'**************************************************************************
Sub Forward()
right = 127 'Right servos value
left = -127 'Left servos value
End Sub
'**************************************************************************
Sub Stop()
right = 0 'Right servos value
left = 0 'Left servos value
End Sub
'**************************************************************************
Sub Spin_right()
right = -97 'Right servo value
left = -97 'Left servo value
End Sub
'**************************************************************************
Sub Spin_left()
right = 97 'Right servo value
left = 97 'Left servo value
End Sub
'**************************************************************************
Sub Backward()
right = -127 'Right servos value
left = 127 'Left servos value
End Sub
'**************************************************************************
Sub Read_Sonar()
Do
SR = 0 'Sonar reading file
Sonar.Operate = 1 'Sonar on
Sonar.Operate = 0 'Sonar off
OOPic.Delay = 25 '0.25 Second delay
SR = (Sonar.Value) 'move read sonar value to SR
SR = (SR / 36) 'Divide SR by 36 to get cm (64 for inches)
If (SR < 2) then 'If SR is less than 2 then
Call Evade 'call evade sequence
end if
loop
End Sub
'**************************************************************************
Sub Evade()
Sonar.Operate = 0 'Sonar off
Call Stop 'Stop the servos
oopic.delay = 30 '0.3 second delay
Call Backward 'Move X4 backwards
OOPic.delay = 100 '1 second delay
Call Stop 'Stop servos
Do
Call Spin_right 'Spin the X4 right to look for a gap
SR = 0
Sonar.Operate = 1 'Sonar on
Sonar.Operate = 0 'Sonar off
OOPic.Delay = 25 '0.25 second delay
SR = (Sonar.Value)
SR = (SR/36)
If (SR > 5) then 'If a reading of greater than 4 is taken
Call Stop 'stop the servos
Call Forward 'move X4 forwards again.
Exit Sub
End If
Loop
End Sub
'**************************************************************************
'**************************************************************************


Examples | Shop