View unanswered posts | View active topics It is currently Fri Aug 29, 2014 1:18 pm






Reply to topic  [ 2 posts ] 
VEX operation vs NXT operation 
Author Message
Rookie

Joined: Wed Jun 26, 2013 2:22 pm
Posts: 11
Post VEX operation vs NXT operation
I have the NXT Mindstorm 2.0. With it, I can download many programs and then select which program to execute. Can I download many programs to the VEX 2.0 and select which one to execute by selecting the buttons on the LCD Display unit.

Thanks


Thu Jul 04, 2013 9:46 am
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post Re: VEX operation vs NXT operation
Hi ronald,
You can't have multiple programs loaded on the Cortex at the same time, but you can combine multiple programs into one large program and add a selector UI to choose between them. We have a blog post from a year ago showing an example of this. The code formatting got messed up, so I've included a reformatted version of it below. If you're looking for some more explanation, check out this blog post at RoboDesigners by Andrew Norton.

Code:
#pragma config(UART_Usage, UART2, uartVEXLCD, baudRate19200, IOPins, None, None)
#pragma config(Motor,  port2,  rightMotor,  tmotorNormal, openLoop, reversed)
#pragma config(Motor,  port3,  leftMotor,  tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard                                                         !!*//

/*
Code Chooser
ROBOTC on VEX 2.0 Cortex

This program uses the Display functions of ROBOTC on the VEX 2.0 Cortex platform.
It allows the user to choose from 4 different pieces of code using the left and right buttons
on the VEX LCD. Once the center button is pressed, the code corresponding with the choice is run.
This code can be adapted for competition based settings - just place the code for the first
switch case in the pre_auton function, and the code for the second switch in the autonomous task.
Replace the basic movement behaviors in the second switch with your own autonomous routines.

ROBOT CONFIGURATION
MOTORS & SENSORS:
[I/O Port]                                    [Name]                                                [Type]                              [Description]
UART Port 2                                    none                                                 VEX LCD                             VEX LCD Screen
Motor Port 2                                rightMotor                                        VEX 3-wire module                        Right side motor
Motor Port 3                                leftMotor                                         VEX 3-wire module                        Left side motor
*/

const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;

//Wait for Press--------------------------------------------------
void waitForPress()
{
    while(nLCDButtons == 0){}
    wait1Msec(5);
}
//----------------------------------------------------------------

//Wait for Release------------------------------------------------
void waitForRelease()
{
    while(nLCDButtons != 0){}
    wait1Msec(5);
}
//----------------------------------------------------------------

task main()
{
    //Declare count variable to keep track of our choice
    int count = 0;

    //------------- Beginning of User Interface Code ---------------
    //Clear LCD
    clearLCDLine(0);
    clearLCDLine(1);
    //Loop while center button is not pressed
    while(nLCDButtons != centerButton)
    {
        //Switch case that allows the user to choose from 4 different options
        switch(count){
        case 0:
            //Display first choice
            displayLCDCenteredString(0, "Autonomous 1");
            displayLCDCenteredString(1, "<                 Enter                >");
            waitForPress();
            //Increment or decrement "count" based on button press
            if(nLCDButtons == leftButton)
            {
                waitForRelease();
                count = 3;
            }
            else if(nLCDButtons == rightButton)
            {
                waitForRelease();
                count++;
            }
            break;
        case 1:
            //Display second choice
            displayLCDCenteredString(0, "Autonomous 2");
            displayLCDCenteredString(1, "<                 Enter                >");
            waitForPress();
            //Increment or decrement "count" based on button press
            if(nLCDButtons == leftButton)
            {
                waitForRelease();
                count--;
            }
            else if(nLCDButtons == rightButton)
            {
                waitForRelease();
                count++;
            }
            break;
        case 2:
            //Display third choice
            displayLCDCenteredString(0, "Autonomous 3");
            displayLCDCenteredString(1, "<                 Enter                >");
            waitForPress();
            //Increment or decrement "count" based on button press
            if(nLCDButtons == leftButton)
            {
                waitForRelease();
                count--;
            }
            else if(nLCDButtons == rightButton)
            {
                waitForRelease();
                count++;
            }
            break;
        case 3:
            //Display fourth choice
            displayLCDCenteredString(0, "Autonomous 4");
            displayLCDCenteredString(1, "<                 Enter                >");
            waitForPress();
            //Increment or decrement "count" based on button press
            if(nLCDButtons == leftButton)
            {
                waitForRelease();
                count--;
            }
            else if(nLCDButtons == rightButton)
            {
                waitForRelease();
                count = 0;
            }
            break;
        default:
            count = 0;
            break;
        }
    }
    //------------- End of User Interface Code ---------------------

    //------------- Beginning of Robot Movement Code ---------------
    //Clear LCD
    clearLCDLine(0);
    clearLCDLine(1);
    //Switch Case that actually runs the user choice
    switch(count){
    case 0:
        //If count = 0, run the code correspoinding with choice 1
        displayLCDCenteredString(0, "Autonomous 1");
        displayLCDCenteredString(1, "is running!");
        wait1Msec(2000);                                               // Robot waits for 2000 milliseconds

        // Move forward at full power for 3 seconds
        motor[rightMotor] = 127;                                       // Motor on port2 is run at full (127) power forward
        motor[leftMotor]  = 127;                                       // Motor on port3 is run at full (127) power forward
        wait1Msec(3000);                                               // Robot runs previous code for 3000 milliseconds before moving on
        break;
    case 1:
        //If count = 1, run the code correspoinding with choice 2
        displayLCDCenteredString(0, "Autonomous 2");
        displayLCDCenteredString(1, "is running!");
        wait1Msec(2000);                                               // Robot waits for 2000 milliseconds

        // Move reverse at full power for 3 seconds
        motor[rightMotor] = -127;                                      // Motor on port2 is run at full (-127) power reverse
        motor[leftMotor]  = -127;                                      // Motor on port3 is run at full (-127) power reverse
        wait1Msec(3000);                                               // Robot runs previous code for 3000 milliseconds before moving on
        break;
    case 2:
        //If count = 2, run the code correspoinding with choice 3
        displayLCDCenteredString(0, "Autonomous 3");
        displayLCDCenteredString(1, "is running!");
        wait1Msec(2000);                                               // Robot waits for 2000 milliseconds

        //Turn right for 3seconds
        motor[rightMotor] = -63;                                       // Motor on port2 is run at half power reverse
        motor[leftMotor]  = 63;                                        // Motor on port3 is run at half power forward
        wait1Msec(3000);                                               // Robot runs previous code for 3000 milliseconds before moving on
        break;
    case 3:
        //If count = 3, run the code correspoinding with choice 4
        displayLCDCenteredString(0, "Autonomous 4");
        displayLCDCenteredString(1, "is running!");
        wait1Msec(2000);                                               // Robot waits for 2000 milliseconds

        //Turn left for 3 seconds
        motor[rightMotor] = 63;                                        // Motor on port2 is run at half power forward
        motor[leftMotor]  = -63;                                       // Motor on port3 is run at half power reverse
        wait1Msec(3000);                                               // Robot runs previous code for 3000 milliseconds before moving on
        break;
    default:
        displayLCDCenteredString(0, "No valid choice");
        displayLCDCenteredString(1, "was made!");
        break;
    }
    //------------- End of Robot Movement Code -----------------------
}


Cheers,
--Ryan

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Fri Jul 05, 2013 10:58 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 0 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.