View unanswered posts | View active topics It is currently Sun Dec 21, 2014 5:18 am






Reply to topic  [ 4 posts ] 
Beginner Program issues! Urgent advice still needed 
Author Message
Rookie

Joined: Fri Mar 08, 2013 1:56 pm
Posts: 3
Post 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.


Last edited by SuperBeginner on Fri Mar 08, 2013 9:00 pm, edited 2 times in total.



Fri Mar 08, 2013 4:24 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 619
Post 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.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Fri Mar 08, 2013 5:25 pm
Profile
Rookie

Joined: Fri Mar 08, 2013 1:56 pm
Posts: 3
Post 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?


Fri Mar 08, 2013 6:51 pm
Profile
Rookie

Joined: Fri Mar 08, 2013 1:56 pm
Posts: 3
Post Re: Beginner Program issues! Urgent advice still needed
Would a untilDark command work for this?


Fri Mar 08, 2013 11:34 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.