Hey, I try to use oIRRange Object(sharp GP2D12) to achieve obstacle avoiden=
ce.But it fails to read value from the sensor. I follow the oIRRange Object=
instruction and connect sensor to board. The code is blow. Please help me =
out. Thank you very much !
=A0
oServo S1 =3D New oServo;=A0=A0 // Make a servo object.
oServo S2 =3D New oServo;=A0=A0 // Make a servo object.
oByte x =3D New oByte;=A0=A0=A0=A0=A0 // Make an 8-bit variable.
oIRRange I=3DNew oIRRange;
oDIO8 P=3DNew oDIO8;
Sub Void main(Void)
{
=A0=A0=A0=A0 S1 =3D 28;
=A0=A0=A0=A0 S2=3D28;
=A0=A0=A0=A0 x=3D1;
=A0=A0=A0=A0=20
=A0=A0=A0=A0 I.IOLine=3D3;
=A0=A0=A0=A0 I.Operate=3D1;
=A0=A0=A0=A0 I.Adjust=3D8;
=A0=A0=A0=A0 P.IOGroup=3D1;
=A0=A0=A0=A0 P.Direction=3DcvOutput;
=A0 Do
=A0 {
=A0=A0=A0=A0=A0
=A0=A0=A0=A0 S1 =3D 20;
=A0=A0=A0=A0 S2 =3D 20;
=A0=A0=A0=A0=A0
=A0=A0=A0=A0 ooPIC.Delay =3D 50;
=A0=A0=A0=A0 S1=3D 40;
=A0=A0=A0=A0 S2=3D40;
=A0=A0=A0=A0=A0=A0x++
=A0=A0=A0=A0=A0=20
=A0=A0=A0=A0 P.Value=3DI.Value;
=A0=A0=A0=A0=20
=A0=A0=A0=A0 If(P>=3D64)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 \\ I =
think there is something=A0wrong at this place.
=A0=A0=A0=A0 {x=3D11;}
=A0 } While (x<=3D10);=A0
=A0=A0=A0=A0=A0=A0=A0 x=3D1;
=A0=20
=A0 Do
=A0 {
=A0=A0=A0=A0 ooPIC.Delay =3D 50;
=A0=A0=A0=A0 S1 =3D 40;
=A0=A0=A0=A0 S2=3D40;
=A0=A0=A0 ooPIC.Delay =3D 50;
=A0=A0=A0=A0 S1 =3D 28;
=A0=A0=A0=A0 S2=3D28;
=A0=A0=A0=A0=A0=A0x++=A0=A0=A0=A0
=A0 } While (x<=3D5);
}
Sub Void Setup(Void)
{
=A0 //--Set up the first servo--
=A0 S1.IOLine =3D 31;=A0=A0=A0=A0=A0 //Set the servo to use I/O Line 31.
=A0 S1.Center =3D 28;=A0=A0=A0=A0=A0 //Set the servos center to 28. (see ma=
nual)=20
=A0 S1.Operate =3D cvTrue;=20
=A0 //--Set up the second servo--
=A0=20
=A0 S2.IOLine =3D 30;=A0=A0=A0=A0=A0 //Set the servo to use I/O Line 30.
=A0 S2.Center =3D 28;=A0=A0=A0=A0=A0 //Set the servos center to 28. (see ma=
nual)=20
=A0 S2.Operate =3D cvTrue;=A0=A0 //Last thing to do, Turn the Servo on.
=A0}
=20=20=20=20=20=20
[Non-text portions of this message have been removed]
------------------------------------

(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )
Hey,
=A0
First, thank you for answering my question. Because the code is too long, s=
o I did not copy completely. The code does work now. But I still have troub=
le in setting P.Value. Is P a binary result?=A0 I just want to use IF selec=
tion to select P.Value. When the distance is less than 40cm, it will execut=
e another part. Please help me to address this problem. Thank you very much=
!
#Code:
=A0
//--The robot will move forward. When it detects an obstacle, robot will mo=
ve backward.--
//-----------------------------------------------------------------
oServo S1 =3D New oServo;=A0=A0 // Make a servo object.
oServo S2 =3D New oServo;=A0=A0 // Make a servo object.
oServo S3 =3D New oServo;
oServo S4 =3D New oServo;
oServo S5 =3D New oServo;
oServo S6 =3D New oServo;
oServo S7 =3D New oServo;
oServo S8 =3D New oServo;
oByte x =3D New oByte;=A0=A0=A0=A0=A0 // Make an 8-bit variable.
oIRRange I=3DNew oIRRange;
oDIO8 P=3DNew oDIO8;
=A0
Sub Void main(Void)
{
=A0 //--Go set up the servo object properties--
=A0 Setup;
=A0=20
=A0=A0=A0=A0 S1 =3D 28;
=A0=A0=A0=A0 S3 =3D 28;
=A0=A0=A0=A0 S5 =3D 28;
=A0=A0=A0=A0 S7 =3D 28;
=A0=A0=A0=A0 S2 =3D 28;
=A0=A0=A0=A0 S4 =3D 28;
=A0=A0=A0=A0 S6 =3D 28;
=A0=A0=A0=A0 S8 =3D 28;
=A0=A0=A0=A0 x=3D1;
=A0=A0=A0=A0=20
=A0=A0=A0=A0 I.IOLine=3D3;
=A0=A0=A0=A0 I.Operate=3D1;
=A0=A0=A0=A0 I.Adjust=3D8;
=A0=A0=A0=A0 P.IOGroup=3D1;
=A0=A0=A0=A0 P.Direction=3DcvOutput;
=A0=A0=A0=A0=20
=A0=A0 //--forward--=A0=20
=A0=20
=A0 Do
=A0 {
=A0=A0=A0=A0 //--Set the servos to 0% and then wait a while--
=A0=A0=A0=A0 S1 =3D 28;
=A0=A0=A0=A0 S5 =3D 20;
=A0=A0=A0=A0 S3 =3D 36;
=A0=A0=A0=A0 S7 =3D 28;
=A0=A0=A0=20
=A0
=A0=A0=A0=A0 ooPIC.Delay =3D 50;
=A0=A0=A0=A0 S3 =3D 40;
=A0
=A0=A0=A0=A0 ooPIC.Delay =3D 50;=A0=20
=A0=A0=A0=A0 S5 =3D 28;
=A0=A0=A0=A0 ooPIC.Delay =3D 50;
=A0=A0=A0=A0 S1 =3D 16;
=A0=A0=A0=A0 S7 =3D 16;
=A0=A0=A0=20
=A0=A0=A0=A0 ooPIC.Delay =3D 50;=A0=20
=A0=A0=20
=A0=A0=A0=A0 S3 =3D 28;
=A0=A0=A0=A0=20
=A0=A0=A0=A0 ooPIC.Delay =3D 50;=A0=20
=A0=A0=A0=A0 S5 =3D 40;
=A0=A0=A0=A0 ooPIC.Delay =3D 50;=A0=20
=A0=A0=A0=A0 S1 =3D 28;
=A0=A0=A0=A0 S7 =3D 28;
=A0=A0=A0=20
=A0=A0=A0=20
=A0=A0=A0=20
=A0=A0=A0 ooPIC.Delay =3D 50;
=A0=A0=A0=A0 S3 =3D 16;
=A0
=A0=A0=A0=A0 ooPIC.Delay =3D 50;=A0=20
=A0=A0=A0=A0 S5 =3D 28;
=A0=A0=A0=A0 ooPIC.Delay =3D 50;
=A0=A0=A0=A0 S1 =3D 40;
=A0=A0=A0=A0 S7 =3D 40;
=A0=A0=A0=20
=A0=A0=A0=A0 ooPIC.Delay =3D 50;=A0=20
=A0=A0=20
=A0=A0=A0=A0 S3 =3D 28;
=A0=A0=A0=A0=20
=A0=A0=A0=A0 ooPIC.Delay =3D 50;=A0=20
=A0=A0=A0=A0 S5 =3D 16;
=A0=A0=A0=A0 ooPIC.Delay =3D 50;=A0=20
=A0=A0=A0=A0 S1 =3D 28;
=A0=A0=A0=A0 S3 =3D 20;
=A0=A0=A0=A0 S5 =3D 36;
=A0=A0=A0=A0 S7 =3D 28;
=A0=A0=A0=A0=A0 x++
=A0=A0=A0=A0=A0=20
=A0=A0=A0=A0 P.Value=3DI.Value;=A0=A0=A0=A0 //--read sensor's value
=A0=A0=A0=A0=20
=A0=A0=A0=A0 If(P>=3D120)
=A0=A0=A0=A0 {x=3D101;}
=A0 } While (x<=3D100);=20
=A0=20
=A0=20
=A0 ooPIC.Delay =3D 500;=20
=A0=A0=A0=A0 S1 =3D 28;
=A0=A0=A0=A0 S3 =3D 28;
=A0=A0=A0=A0 S5 =3D 28;
=A0=A0=A0=A0 S7 =3D 28;
=A0=A0=A0=A0 S2 =3D 28;
=A0=A0=A0=A0 S4 =3D 28;
=A0=A0=A0=A0 S6 =3D 28;
=A0=A0=A0=A0 S8 =3D 28;
=A0=A0=A0=A0=A0 x=3D1;
=A0=A0=A0=A0=A0=20
=A0=A0=A0=A0=A0=20
//--Backward--
=A0
=A0 Do
=A0 {
=A0=A0=A0=A0=20
=A0=A0=A0=A0 S1 =3D 28;
=A0=A0=A0=A0 S5 =3D 20;
=A0=A0=A0=A0 S3 =3D 36;
=A0=A0=A0=A0 S7 =3D 28;
=A0=A0=A0=20
=A0
=A0=A0=A0=A0 ooPIC.Delay =3D 50;
=A0=A0=A0=A0 S5 =3D 16;
=A0
=A0=A0=A0=A0 ooPIC.Delay =3D 50;=A0=20
=A0=A0=A0=A0 S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=A0=A0=A0 S4 =3D 28;
=A0=A0=A0=A0 S6 =3D 28;
=A0=A0=A0=A0 S8 =3D 28;
}
//-----------------------------------------------------------------
//=A0 A routine that sets up our servo properties
//-----------------------------------------------------------------
Sub Void Setup(Void)
{
=A0 //--Set up the first servo--
=A0 S1.IOLine =3D 31;=A0=A0=A0=A0=A0 //Set the servo to use I/O Line 31.
=A0 S1.Center =3D 28;=A0=A0=A0=A0=A0 //Set the servos center to 28.=20
=A0 S1.Operate =3D cvTrue;=20
=A0 //--Set up the second servo--
=A0=20
=A0 S2.IOLine =3D 30;=A0=A0=A0=A0=A0 //Set the servo to use I/O Line 30.
=A0 S2.Center =3D 28;=A0=A0=A0=A0=A0 //Set the servos center to 28.=A0=20
=A0 S2.Operate =3D cvTrue;=A0=A0 //Last thing to do, Turn the Servo on.
=A0 S3.IOLine =3D 29;=A0=A0=A0=A0=A0 //Set the servo to use I/O Line 29.
=A0 S3.Center =3D 28;=A0=A0=A0=A0=A0 //Set the servos center to 28.=20
=A0
=A0 S3.Operate =3D cvTrue; //Last thing to do, Turn the Servo on.
=A0 S4.IOLine =3D 28;=A0=A0=A0=A0=A0 //Set the servo to use I/O Line 28.
=A0 S4.Center =3D 28;=A0=A0=A0=A0=A0 //Set the servos center to 28.=20
=A0 S4.Operate =3D cvTrue; //Last thing to do, Turn the Servo on.
=A0 S5.IOLine =3D 15;=A0=A0=A0=A0=A0 //Set the servo to use I/O Line 15.
=A0 S5.Center =3D 28;=A0=A0=A0=A0=A0 //Set the servos center to 28.=20
=A0=A0=20
=A0 S5.Operate =3D cvTrue; //Last thing to do, Turn the Servo on.
=A0=20
=A0 S6.IOLine =3D 14;=A0=A0=A0=A0=A0 //Set the servo to use I/O Line 14.
=A0 S6.Center =3D 28;=A0=A0=A0=A0=A0 //Set the servos center to 28.=20
=A0 S6.Operate =3D cvTrue; //Last thing to do, Turn the Servo on.
=A0=20
=A0 S7.IOLine =3D 13;=A0=A0=A0=A0=A0 //Set the servo to use I/O Line 13.
=A0 S7.Center =3D 28;=A0=A0=A0=A0=A0 //Set the servos center to 28.=20
=A0=20
=A0 S7.Operate =3D cvTrue; //Last thing to do, Turn the Servo on.
=A0=20
=A0 S8.IOLine =3D 12;=A0=A0=A0=A0=A0 //Set the servo to use I/O Line 12.
=A0 S8.Center =3D 28;=A0=A0=A0=A0=A0 //Set the servos center to 28.=A0=20
=A0 S8.Operate =3D cvTrue; //Last thing to do, Turn the Servo on.
=A0 }
=20=20=20=20=20=20
[Non-text portions of this message have been removed]
------------------------------------

(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )