ROBOTC.net forums
http://www.robotc.net/forums/

IR + Sonar Bug
http://www.robotc.net/forums/viewtopic.php?f=63&t=8292
Page 1 of 1

Author:  Hephaestus59 [ Fri Mar 21, 2014 8:27 am ]
Post subject:  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;
}
}
}

Author:  CARBOT [ Fri Mar 28, 2014 12:11 pm ]
Post subject:  Re: IR + Sonar Bug

You have no braces following
if(SensorValue[derp] > 10)

Author:  Coder A [ Fri Mar 28, 2014 12:27 pm ]
Post subject:  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

Author:  Yoda6969 [ Tue Nov 17, 2015 8:46 am ]
Post subject:  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

Author:  JohnWatson [ Tue Nov 17, 2015 10:31 am ]
Post subject:  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!

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/