aton code not working with competition switch.

ok so im using pros and the competition switch and it works fine and dosent use the code i put in for the aton program when its in driver like it should but when i switch to aton it dosent do anything.
driver code:


#include "main.h"
void operatorControl() {

	// Declare inital values.

		//Intial Movement Values.
		int Z1 = 0;
		int Y1 = 0;
		int X1 = 0;
		int threshold = 7; //Declare Deadzone Limit to zero out all motors if not above.

		// Inital Debugging Values.
		int debugCtr = 0;

		// Motor Port Values.
		int frontright = 3;
		int backright =  9;
		int frontleft = 2;
		int backleft = 8;

    while(1){/*Loop Forever*/
    	//Declare Joysticks.
        int leftStickUp = joystickGetAnalog(1, 4);
        int leftStickLeft = joystickGetAnalog(1, 3);
        int rightStickLeft = joystickGetAnalog(1, 1);

        //Create "deadzone" for Y1/Ch3, Left Joystick Up and Down.
        if(abs(leftStickUp) > threshold){
            Y1 = leftStickUp; // If leftStickUp is above +/- 7 then Y1 = Joystick leftStickUp (position)
        }else{
            Y1 = 0;//If Joystick leftStickUp is below +/- 7 then Y1 = 0
        }
        //Create "deadzone" for X1/Ch4, Left Joystik Left and Right.
        if(abs(leftStickLeft) > threshold){
            X1 = leftStickLeft; //If Joystick leftstickLeft is above +/- 7 then X1 = Joystick leftStickLeft (position)
        }else{
            X1 = 0;//If Joystick leftStickLeft is below +/- 7 then X1 = 0
        }
        //Create "deadzone" for Z1/Ch1, Right Joystick Left and Right.
        if(abs(rightStickLeft) > threshold){
            Z1 = rightStickLeft;//If Joystick rightStickLeft is above +/- 7 then Z1 = Joystick rightStickLeft (position)
        }else{
            Z1 = 0;//If Joystick rightStickLeft is below +/- 7 then Z1 = 0
        }
        //Math Logic for each Motor.
        motorSet(frontright, -Y1 + Z1 + X1);
        motorSet(backright, Y1 + Z1 + X1);
        motorSet(frontleft, -Y1 + Z1 - X1);
        motorSet(backleft, Y1 + Z1 - X1);

        delay(20);//Required for any working program at the end of the program in milliseconds?

        //Debugging Command.

       if( debugCtr++ == 5 ) //Display Y1, X1, Z1 Values in PROS Terminal for debugging.
            {
            debugCtr = 0;
            printf("Joystick Drive Values for: %d %d %d\r\n", Y1, X1, Z1 );
            }

        }
}

aton code:

/** @file auto.c
 * @brief File for autonomous code
 *
 * This file should contain the user autonomous() function and any functions related to it.
 *
 * Copyright (c) 2011-2014, Purdue University ACM SIG BOTS.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Purdue University ACM SIG BOTS nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL PURDUE UNIVERSITY ACM SIG BOTS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Purdue Robotics OS contains FreeRTOS (http://www.freertos.org) whose source code may be
 * obtained from http://sourceforge.net/projects/freertos/files/ or on request.
 */

#include "main.h"

// Motor Port Values.
	int frontright = 3;
	int backright =  9;
	int frontleft = 2;
	int backleft = 8;

	// Create selectSquareCount number to zero on startup
	int selectSquareCount = 0;

	//Movement fuction.
	void move(int Y1, int X1, int Z1,int timeDelay){
		//Math Logic for each Motor.
		motorSet(frontright, -Y1 + Z1 + X1);
		motorSet(backright, Y1 + Z1 + X1);
		motorSet(frontleft, -Y1 + Z1 - X1);
		motorSet(backleft, Y1 + Z1 - X1);
		delay(timeDelay);
	}

void autonomous() {
		int bumpSquareSelect =  13;
		while(true){
		// Add one to selectSquareCount
		if(digitalRead(bumpSquareSelect) == 1){
			selectSquareCount = selectSquareCount + 1;
			delay(20);
		}
		//If selectSquareCount = 0 then set the LED on slot 1-4 (digital) to flash.
		if(selectSquareCount == 0){
				pinMode(9, 50);
				pinMode(10, 50);
				pinMode(11, 50);
				pinMode(12, 50);
				delay(250);
				pinMode(9, 0);
				pinMode(10, 0);
				pinMode(11, 0);
				pinMode(12, 0);

			}
		}
		//If selectSquareCount = 1 then set the LED on slot 1 (digital) to on.
		if(selectSquareCount == 1){
			pinMode(9, 1);
			pinMode(10, 0);
			pinMode(11, 0);
			pinMode(12, 0);
		}
		//If selectSquareCount = 2 then set the LED on slot 2 (digital) to on.
		if(selectSquareCount == 2){
			pinMode(9, 0);
			pinMode(10, 1);
			pinMode(11, 0);
			pinMode(12, 0);
		}
		//If selectSquareCount = 3 then set the LED on slot 3 (digital) to on.
		if(selectSquareCount == 3){
			pinMode(9, 0);
			pinMode(10, 0);
			pinMode(11, 1);
			pinMode(12, 0);
		}
		//If selectSquareCount = 4 then set the LED on slot 4 (digital) to on.
		if(selectSquareCount == 4){
			pinMode(9, 0);
			pinMode(10, 0);
			pinMode(11, 0);
			pinMode(12, 1);
		}

		// Look at the selectSquareCount Variable if its over five reset it back to zero.
		if(selectSquareCount >= 5){
			selectSquareCount = 0;
			delay(20);
		}

		//Group Command for starting square one.
		if(selectSquareCount == 1){
			//Movement Program.
			move(127, 0, 0, 325);
			move(0, 0, -127, 250);
			move(127, 0, 0, 750);
			move(-127, -50, 0, 500);
			move(127, 0, 0, 500);
			move(127, 127, 0, 250);
			move(-127, 0, 0, 750);
			move(0, 0, -127, 250);
			move(127, 0, 0, 250);
			delay(20);
			//Flash Square one LED to show the end of the program.
			pinMode(9, 0);
			pinMode(9, 1);
			pinMode(9, 0);
			pinMode(9, 1);
			pinMode(9, 0);
			pinMode(9, 1);
			pinMode(9, 0);
			pinMode(9, 1);
			pinMode(9, 0);
			pinMode(9, 1);
			pinMode(9, 0);
			delay(20);
			//Reset the selectSquareCount back to zero to choose the next starting square.
			selectSquareCount = 0;
			delay(20);
		}
		//Group command for starting in square two.
		if(selectSquareCount == 2){
			//Movement Program.
			move(127, 0, 0, 325);
			move(0, 0, 127, 250);
			move(127, 0, 0, 750);
			move(-127, -50, 0, 500);
			move(127, 0, 0, 500);
			move(127, 127, 0, 250);
			move(-127, 0, 0, 1000);
			move(0, 0, -127, 250);
			move(127, 0, 0, 250);
			delay(20);
			//Flash Square two LED to show the end of the program.
			pinMode(10, 0);
			pinMode(10, 1);
			pinMode(10, 0);
			pinMode(10, 1);
			pinMode(10, 0);
			pinMode(10, 1);
			pinMode(10, 0);
			pinMode(10, 1);
			pinMode(10, 0);
			pinMode(10, 1);
			pinMode(10, 0);
			delay(20);
			//Reset the selectSquareCount back to zero to choose the next starting square.
			selectSquareCount = 0;
			delay(20);
		}
		//Group command for starting in square three.
		if(selectSquareCount == 3){
			move(0, 127, 0, 325);
			move(0, 0, 127, 250);
			move(0, 127, 0, 1000);
			move(50, 127, 0, 500);
			move(0, -127, 0, 500);
			move(127, 127, 0, 250);
			move(0, -127, 0, 0);
			move(0, 0, -127, 250);
			move(-127, 0, 0, 250);
			delay(20);
			//Flash Square two LED to show the end of the program.
			pinMode(11, 0);
			pinMode(11, 1);
			pinMode(11, 0);
			pinMode(11, 1);
			pinMode(11, 0);
			pinMode(11, 1);
			pinMode(11, 0);
			pinMode(11, 1);
			pinMode(11, 0);
			pinMode(11, 1);
			pinMode(11, 0);
			delay(20);
			//Reset the selectSquareCount back to zero to choose the next starting square.
			selectSquareCount = 0;
			delay(20);
		}
		//Group command for starting in square four.
		if(selectSquareCount == 4){
			move(0, 127, 0, 325);
			move(0, 0, -127, 250);
			move(0, 127, 0, 1000);
			move(50, 127, 0, 500);
			move(0, -127, 0, 500);
			move(127, 127, 0, 250);
			move(0, -127, 0, 0);
			move(0, 0, -127, 250);
			move(-127, 0, 0, 250);
			delay(20);
			selectSquareCount = 0;
		}

		}



can some one tell me what im doing wrong…thanks …

Is is because your led selection is in your autonomous task? In the past, I would initialize the led selection in pre_auton. Perhaps the reason why your auton isn’t running is simply because the robot never registered the fact that a program had been selected.

I was able to get a code from online that only runs motors… so I may have to figure that out but I can’t seem to get an LED to light up to, am I doing it right to make an led light up because it seems like I’m not… but if I do a motor inside the aton it works like it should so maybe I’m doing something wrong

Could it be that you are setting the pins to 50 inside of your select square count==0 IF statement? That should be 0 or 1, right? Also, you have two closing brackets after that same IF statement. The first closes the IF statement and the second closes your while loop. Since the loop is set to true, it never has a chance to end and get to the rest of your code.
Get rid of that second closing bracket and fix the pin set commands and retry.

I don’t know if this matters, but there seems to be just a bit of inconsistency in your pin functions. At the very start of your program when you tell the LED’s to flash on for a split second, you use this code:


pinMode(9,50)

Later in the program at the end of your autonomous mode, you use this code to flash the LED’s:


pinMode(9, 1)

Not sure if this is problem, but thought I’d point it out.

EDIT: Nevermind, capow beat me to it.

So inside the pin mode to make an led light up it has to be a 1 would be on 0 would be off correct? Because I tried to make it send a signal to the led to light it up and it didn’t do anything. I’ll try something to see what I can get to work

So I’ve been moving the led to different ports to see if any are lighting up and nothing is passing voltage idk what is up but not sure what pin goes to single ports… any help please.

Did you change the setMode to 1 instead of 50? Also did you get rid of that second bracket like I said? Post your most current auton code so we can see exactly what changes ypubhave made.

this is the code im using just to try and get an led to light up the motor is just so i know its running through the while loop

void autonomous() {
	while(true){
		pinMode(1, 50);
		pinMode(2, 50);
		pinMode(3, 50);
		pinMode(4, 50);
		pinMode(5, 50);
		pinMode(6, 50);
		pinMode(7, 50);
		pinMode(8, 50);
		pinMode(9, 50);
		pinMode(10, 50);
		pinMode(11, 50);
		pinMode(12, 50);
		pinMode(13, 50);
		pinMode(14, 50);
		pinMode(15, 50);
		pinMode(16, 50);
		pinMode(17, 50);
		pinMode(18, 50);
		pinMode(19, 50);
		pinMode(20, 50);
		pinMode(21, 50);
		pinMode(22, 50);
		pinMode(23, 50);
		pinMode(24, 50);
		pinMode(25, 50);
		pinMode(26, 50);
		motorSet(9, 50);
	}

i activated all the pins and nothing happens to any of the digital ports but i can get a super slight light on the analog ports but thats kind of expected to be used for the sensors that need power… idk what im doing wrong am i using the wrong command to get it to switch on an LED? or am i just using the wrong arguments, i changed the 50 to 1 and then tried using OUTPUT instead of 1 and nothing has happend so idk what im doing wrong.

So I pulled up the PROS api here
http://purdueros.sourceforge.net/doc/a00002.htm#a1875409d12eee562555bda94cad7f973

So it should be
pinMode(5,OUTPUT); to set the pin to being an output

Then you still need to actually update the value of that pin.

So you need to say
digiticalWrite(5,true);
digiticalWrite(5,false);
to flash the LED.

Edit
Remember setting the pin mode just sets that digital port to be in the correct mode (input or output).

OK so that clears up a lot but now how do you know the pins from each other because pinmode is 1-26 well there’s 30 Ports not including the uart and ic2 ports?

Just try it as some of the digital ports as they are the most likely ports to do what you want. I am not sure where 26 comes from myself but plugging an LED into a bunch of ports until it turns on shouldn’t be too difficult.

ok cool thanks

been sitting on the code for a week and its being stupid and wouldnt react think today was the day i made the most progress with just a driving program… lol pretty bad. but this PROS is new to us so not bad for what we are doing…
thanks man for the help.