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

Beginner Program issues! Urgent advice still needed
http://robotc.net/forums/viewtopic.php?f=11&t=5596
Page 1 of 1

Author:  SuperBeginner [ Fri Mar 08, 2013 4:24 pm ]
Post subject:  Beginner Program issues! Urgent advice still needed

We have built an elevator for a project and our builder has used one motor, 3 line followers, 2 bump switches, a limit switch, and a chain and sprockret.

For our program, we used multiple if statements and as of now the elevator won't stop, or go down.
My job is to try and figure out what our programmer did wrong, but I can't seem to see why the computer doesn't go on to the next line of code.

This is the copy & pasted program, with the line followers being labeled as light and their respective floor numbers:
Code:
task main()
{

int up;
up = -15;
int down;
down = 15;

while (1==1)

{
    if(SensorValue (bump2) == 1 && SensorValue(light1) < 1500)        //first go to second
    {
    turnLEDoff(led1);
    wait(1);
    startMotor(port2,  up);
    if (SensorValue (light2) < 1500)
        {
        stopMotor(port2);
        wait(1);
        turnLEDon(led2);
        }
    }

    if(SensorValue (limit) == 1 && SensorValue(light1) < 1500)        //first go to third
    {
    turnLEDoff(led1);
    wait(1);
    startMotor(port2,  up);
    if (SensorValue (light3) < 1500)
        {
        stopMotor(port2);
        wait(1);
        turnLEDon(led3);
        }
    }

    if(SensorValue (limit) == 1 && SensorValue(light 2) < 1500)        //second go to third
    {
        turnLEDoff(led2);
        wait(1);
        startMotor(port2, up);
        if(SensorValue (light3) < 1500)
            {
            stopMotor (port2);
            wait(1);
            turnLEDon(led3);
            }
    }

    if (SensorValue (bump1) == 1 && SensorValue(light 2) < 1500)        //second go to first
    {
        turnLEDoff(led2);
        wait(1);
        startMotor(port2, down);
        if (SensorValue (light1) < 1500)
            {
            stopMotor(port2);
            wait(1);
            turnLEDon(led1);
            }


    if (SensorValue (bump1) == 1 && SensorValue(light3) < 1500)        //third goto first
    {
        turnLEDoff(led3);
        wait(1);
        startMotor(port2, down);
        if (SensorValue (light1) < 1500)
            {
            stopMotor(port2);
            wait(1);
            turnLEDon(led1);
            }   
    }

    if (SensorValue (bump2) == 1 && SensorValue(light3) < 1500)         //third down to second
    {
        turnLEDoff(led3);
        wait(1);
        startMotor(port2, down);
        if(SensorValue (light2) < 1500)
            {
            stopMotor(port2);
            wait(1);
            turnLEDon(led2);
            }
    }
}
}




The computer doesn't continue passed the first startMotor(port2, up), and I have until tomorrow to figure out what the issue is. If someone can suggest a better way to code this it would be very appreciated.

Author:  JohnWatson [ Fri Mar 08, 2013 5:25 pm ]
Post subject:  Re: Beginner Program issues! Urgent advice needed

Code:
[b]int up;[/b]
up = -15;
int down;
down = 15;

while (1==1)

{
    if(SensorValue (bump2) == 1 && SensorValue(light1) < 1500)        //first go to second
    {
    turnLEDoff(led1);
    wait(1);
    [b]startMotor(port2,  up);[/b]
    if (SensorValue (light2) < 1500)
        {
        stopMotor(port2);
        wait(1);
        turnLEDon(led2);
        }
    }


One potential problem I am seeing is that you have created a variable 'up', but you did not initialize it with a value. ROBOTC initializes variables to zero by default, so this will turn the motor on with a power of 0 (it will turn them off).

Code:
if (SensorValue (bump1) == 1 && SensorValue(light 2) < 1500) 


It appears you have given a sensor the alias of 'light 2', which is not a valid alias; sensor names cannot contain spaces in them, and as such this will also throw an error. You will need to change this to 'light2' or something similar.

Code:
 if (SensorValue (bump1) == 1 && SensorValue(light 2) < 1500)        //second go to first
    {
        turnLEDoff(led2);
        wait(1);
        startMotor(port2, down);
        if (SensorValue (light1) < 1500)
            {
            stopMotor(port2);
            wait(1);
            turnLEDon(led1);
            }
    [b]}[/b]


Your fourth 'major' if statement starts correctly with an opening brace { , but does not end with a closing brace }. This will not only generate an error but will encapsulate all of the code beneath it until it reaches the ending brace }.

Try making these changes for now, rerun the code, and let us know what you run into.

Author:  SuperBeginner [ Fri Mar 08, 2013 6:51 pm ]
Post subject:  Re: Beginner Program issues! Urgent advice needed

Okay, I'm sorry about that. It turns out that the code my programmer sent me was the one she put in before fixing the things which wouldn't even let the program run.

The actual code reads:

Code:
task main()
{

int up;
up = 15;

int down;
down = -15;

while (1==1)

{
    if(SensorValue (bump2) == 1 && SensorValue(light1) < 1500)        //first go to second
    {
    turnLEDoff(led1);
    wait(1);
    startMotor(port2,  up);
    if (SensorValue (light2) < 1500)
        {
        stopMotor(port2);
        wait(1);
        turnLEDon(led2);
        }
    }

    if(SensorValue (limit) == 1 && SensorValue(light1) < 1500)        //first go to third
    {
    turnLEDoff(led1);
    wait(1);
    startMotor(port2,  up);
    if (SensorValue (light3) < 1500)
        {
        stopMotor(port2);
        wait(1);
        turnLEDon(led3);
        }
    }

    if(SensorValue (limit) == 1 && SensorValue(light2) < 1500)        //second go to third
    {
        turnLEDoff(led2);
        wait(1);
        startMotor(port2, up);
        if(SensorValue (light3) < 1500)
            {
            stopMotor (port2);
            wait(1);
            turnLEDon(led3);
            }
    }

    if (SensorValue (bump1) == 1 && SensorValue(light2) < 1500)        //second go to first
    {
        turnLEDoff(led2);
        wait(1);
        startMotor(port2, down);
        if (SensorValue (light1) < 1500)
            {
            stopMotor(port2);
            wait(1);
            turnLEDon(led1);
            }


    if (SensorValue (bump1) == 1 && SensorValue(light3) < 1500)        //third goto first
    {
        turnLEDoff(led3);
        wait(1);
        startMotor(port2, down);
        if (SensorValue (light1) < 1500)
            {
            stopMotor(port2);
            wait(1);
            turnLEDon(led1);
            }   
    }

    if (SensorValue (bump2) == 1 && SensorValue(light3) < 1500)         //third down to second
    {
        turnLEDoff(led3);
        wait(1);
        startMotor(port2, down);
        if(SensorValue (light2) < 1500)
            {
            stopMotor(port2);
            wait(1);
            turnLEDon(led2);
             }
       }
}   
}
}



The up variable does have a value, "light 2" is now "light2" and the final 'major' if statement has the closing brace it needs. RobotC doesn't find anything wrong with the syntax of our program.
The problems I described before are still the same where the elevator doesn't stop, even when our line follower gets a very good reading, and the elevator has an issue going downward (we have a program that just goes up and down, and it works fine there).
Is there any reason why the computer wouldn't read passed the initial startMotor command? And is there anything we can do in order to fix this problem, while still using our line followers?

Author:  SuperBeginner [ Fri Mar 08, 2013 11:34 pm ]
Post subject:  Re: Beginner Program issues! Urgent advice still needed

Would a untilDark command work for this?

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