View unanswered posts | View active topics It is currently Thu Apr 26, 2018 3:27 am

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Beginner Program issues! Urgent advice still needed
Author Message
Rookie

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

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
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 updated help documentation and the ROBOTC Forums.

Fri Mar 08, 2013 5:25 pm
Rookie

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

 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
Rookie

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

Fri Mar 08, 2013 11:34 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning