View unanswered posts | View active topics It is currently Thu Oct 23, 2014 11:11 am






Reply to topic  [ 3 posts ] 
IR + Sonar Bug 
Author Message
Rookie

Joined: Mon Feb 03, 2014 3:28 am
Posts: 4
Post IR + Sonar Bug
ERROR
my code is suppose to have my robot drive up to the IR becon ( soccer ball ) and stop 10CM using the Sonar sensor but no matter how close it gets it will shake back and forth even with direct contact it still will do a chiken dance also even if i pint at the room it still does

Names:

Sonar = derp
IR = MURICH

Code:

task main ()
{
while (1 == 1)
{
if(SensorValue[derp] > 10)

if(SensorValue[MURICH] ==5)
{
motor[motorD] = 20;
motor[motorE] = 20;
}
if(SensorValue[MURICH] < 5)
{
motor[motorE] = 20;
motor[motorD] = -20;
}
if(SensorValue[MURICH] > 5)
{
motor[motorE] = -20;
motor[motorD] = 20;
}
else
{
motor[motorD] = 0;
motor[motorE] = 0;
}
}
}


Fri Mar 21, 2014 8:27 am
Profile
Rookie

Joined: Thu Dec 01, 2011 12:07 am
Posts: 40
Post Re: IR + Sonar Bug
You have no braces following
if(SensorValue[derp] > 10)


Fri Mar 28, 2014 12:11 pm
Profile
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: IR + Sonar Bug
Good spot, carbot. Try to use code tags when you post your code, like this:

Code:

Code:

task main ()
{
    while (1 == 1)
    {
        if(SensorValue[derp] > 10)
            if(SensorValue[MURICH] ==5)
            {
                motor[motorD] = 20;
                motor[motorE] = 20;
            }
        if(SensorValue[MURICH] < 5)
        {
            motor[motorE] = 20;
            motor[motorD] = -20;
        }
        if(SensorValue[MURICH] > 5)
        {
            motor[motorE] = -20;
            motor[motorD] = 20;
        }
        else
        {
            motor[motorD] = 0;
            motor[motorE] = 0;
        }
    }
}



It makes bugs like yours easier to spot. Also, as good practice, use "true" instead of "1 == 1".

-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


Fri Mar 28, 2014 12:27 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.