View unanswered posts | View active topics It is currently Thu Nov 27, 2014 12:09 pm






Reply to topic  [ 3 posts ] 
Can anyone give me some help on my project? please~ 
Author Message
Rookie

Joined: Mon Nov 28, 2011 7:29 am
Posts: 1
Post Can anyone give me some help on my project? please~
The aim of my project is to collect all the green circles around the cardboard field(92cm*122cm), and without leave the filed. I was tried to using if else() to assist me to reach the aim, but the code I coded was totally doesn't work... the program will just finsih immediately...I need some help....><

and here is my draft code

Quote:
#pragma config(Sensor, S3, senLight, sensorLightActive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
ClearTimer(T1);
while (time1(T1)==2000)
if (SensorValue(senLight)>44)
{
motor[motorB]=65;
motor[motorC]=30;


}

{

if (SensorValue(senLight)<54)
{

motor[motorC]=25;
motor[motorB]=-25;
wait1Msec(1500);

motor[motorC]=50;
motor[motorB]=50;

wait1Msec(5000);

}
else
{
motor[motorC]=50;
motor[motorB]=50;
wait1Msec(1500);




}



}
}





I want to using light sesor to dectecting the green points and to avoiding the robot leave the field. out side the caredboard is the black carpet, so I set the threshold between black and whit(cardboard), and white(cardboard) and green. And the method Iwant to using is spining out from the center of the field(cardboard), than if detecting the green point the robot will have a beep sound, after the robot spinning to the black carpet, it will turn around and back to the field and move forward and keep finding the green points, and while the action for 20mins. Above is my draft code, but totally doesn't work... i hope some one can give me some sugguest and help me to finish my project~><please~

Thank alot.


Mon Nov 28, 2011 9:12 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Can anyone give me some help on my project? please~
The code was ending because you didn't actually define a body for the while() loop. Here it is fixed:
Code:
#pragma config(Sensor, S3, senLight, sensorLightActive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
  ClearTimer(T1);
  while (time1(T1)==2000)
  {
    if (SensorValue(senLight)>44)
    {
      motor[motorB]=65;
      motor[motorC]=30;
    }

    if (SensorValue(senLight)<54)
    {
      motor[motorC]=25;
      motor[motorB]=-25;
      wait1Msec(1500);

      motor[motorC]=50;
      motor[motorB]=50;

      wait1Msec(5000);
    }
    else
    {
      motor[motorC]=50;
      motor[motorB]=50;
      wait1Msec(1500);
    }
  }
}
You might want to add sensor calibration for each threshold in case the lighting changes. You could probably get more help if you added more info about the field.

BTW, next time use the "Code" tags for a program to preserve the spacing.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Mon Nov 28, 2011 9:36 pm
Profile WWW
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Can anyone give me some help on my project? please~
Also, the program is set to only run for 2000 milleseconds. You should change this to minutes by uxing the nclockminutes variable. Next, you should change the '==' inside the while to '<', or the code will exit the while immediately anyway. Finally, you can still not declare a body to a control structure and it will just make the very next command block its body. If, else, while, for, and so on are not statements, so your first block under the first if was the loop's block.

I hope this helps!

-Coder A

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Thu Jan 03, 2013 7:06 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.