View unanswered posts | View active topics It is currently Wed Dec 07, 2016 6:39 am






Reply to topic  [ 5 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
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 146
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: 207
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
Rookie

Joined: Tue Nov 10, 2015 11:12 pm
Posts: 2
Post Re: IR + Sonar Bug
Your code should work fine however you are missing an '{' after you sonar if statement (below).

if(SensorValue[derp] > 10)

besides that your code should work however you may have some issues when you take it to the real world. Even with this fix you may still get the "chicken dance" result because it seems to be running all your if statements mean there may be an issue with the IR sensor input. If you would like to post the rest of your code so I can see how you have set it up I might be able to improve your position. :D


Tue Nov 17, 2015 8:46 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: IR + Sonar Bug
Yoda6969 wrote:
Your code should work fine however you are missing an '{' after you sonar if statement (below).

if(SensorValue[derp] > 10)

besides that your code should work however you may have some issues when you take it to the real world. Even with this fix you may still get the "chicken dance" result because it seems to be running all your if statements mean there may be an issue with the IR sensor input. If you would like to post the rest of your code so I can see how you have set it up I might be able to improve your position. :D



Please note that the last post in this thread has been from over a year and a half ago (March 2014); please check the dates of prior posts before creating a new response in the future, to avoid 'necroing' a thread that has been dormant.

Thank you!

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Tue Nov 17, 2015 10:31 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.