pros comp template

so i uploaded my program to the cortex earlier and its just the basic code that robot c has on their website for the Mecanum wheels

heres the code:



void operatorControl() {
	int leftStickUp = joystickGetAnalog(1, 3);
	int leftStickLeft = joystickGetAnalog(1, 4);
	int rightStickLeft = joystickGetAnalog(1, 1);


	//Create "deadzone" variables. Adjust threshold value to increase/decrease deadzone
	int X2 = 0;
	int Y1 = 0;
	int X1 = 0;
	int threshold = 7;

	//Loop Forever
	while(1)
	{
	//Create "deadzone" for Y1/Ch3
	if(abs(leftStickUp) > threshold){
	Y1 = leftStickUp;
	}else{
	Y1 = 0;
	}
	//Create "deadzone" for X1/Ch4
	if(abs(leftStickLeft) > threshold)
	X1 = leftStickLeft;
	else
	X1 = 0;
	//Create "deadzone" for X2/Ch1
	if(abs(rightStickLeft) > threshold)
	X2 = rightStickLeft;
	else
	X2 = 0;

	//Remote Control Commands
	motorSet(3, Y1 + X2 - X1);
	motorSet(9, Y1 + X2 + X1);
	motorSet(2, Y1 - X2 + X1);
	motorSet(8, Y1 - X2 - X1);
	}

}

now idk if im missing something but when i had the competion swith set to driver mode it didnt work. i just too the code from robot c and adapted it to work with pros but it dosent seem like its working… any help on what i did wrong kind of a new language for me because we didnt use some of these commands in robo c.

PROS is not RobotC, you’d have to change the code to work with PROS.
I can try to help when I get home later…

i have taken the code and switched it to work for pros. i think. super huge i think from what i seen online i just dont know if i need extra code for the competition switch and for the joysticks i guess i declared them wrong because i enabled driver and nothing happend when i moved either joystick

I’m not really the most qualified person to help you, but I think you need to update the variables leftStickUp, leftStickLeft, & rightStickLeft inside the while loop. Otherwise if I’m correct, they will just be stuck at whatever the joystick was at when Operator started and they won’t get changed.

You are correct.

Also the while loop need some delay at the end, this is the template that is provided for a new project. It’s important to keep the delay otherwise other tasks (if you create any later) will be starved of cpu time.

void operatorControl() {
	while (1) {
		delay(20);
	}
}

All PROS projects by default are competition templates. Due to the structure of the Vex robotics competition we decided to follow this methodology instead of providing a traditional template with main().

For more information on the PROS project structure please reference the documentation here.

ok so i got it to move this morning now its just a matter of finding the values for the joysticks, but i have been changing them and its like its not taking any effect on what im doing? ive taken

	int leftStickUp = -joystickGetAnalog(1, 3);

and ive changed the three to a 1 and to a 2 and a 4 and its taking no effect

still the same code as above just moved all the int for the joysticks inside the while and then added a delay(); to the end? any help on like a map of how the ve joysticks send their information and how to call the code for them?

okay so I’ve come to the conclusion that any change i make is no longer taking effect. i took the getjoystick values and commented them out and then took that int and set it to 0 and i rebuilt and then uploaded and nothing changed i enable driver and it works like it was before i can still move and it has all the incorrect movements now … I’m confused on what i did wrong…

Post the revised code and lets have a look. There’s also a small chance that it’s not your code and is a PROS problem, there were some compatibility issues (apparently, didn’t see them first hand) at worlds with PROS and the latest master firmware.

Edit:
Just tried this code on a cortex with V4.25, I don’t see any problems.

void operatorControl() {
    int X2 = 0;
    int Y1 = 0;
    int X1 = 0;
    int threshold = 7; // deadzone
    int debugCtr = 0;

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

        //Create "deadzone" for Y1/Ch3
        if(abs(leftStickUp) > threshold)
            Y1 = leftStickUp;
        else
            Y1 = 0;

        //Create "deadzone" for X1/Ch4
        if(abs(leftStickLeft) > threshold)
            X1 = leftStickLeft;
        else
            X1 = 0;

        //Create "deadzone" for X2/Ch1
        if(abs(rightStickLeft) > threshold)
            X2 = rightStickLeft;
        else
            X2 = 0;

        //Remote Control Commands
        motorSet(3, Y1 + X2 - X1);
        motorSet(9, Y1 + X2 + X1);
        motorSet(2, Y1 - X2 + X1);
        motorSet(8, Y1 - X2 - X1);

        delay(20);

        if( debugCtr++ == 5 )
            {
            debugCtr = 0;
            printf("drive vals %d %d %d\r\n", Y1, X1, X2 );
            }

        }
}

heres the revised code

/** @file opcontrol.c
 * @brief File for operator control code
 *
 * This file should contain the user operatorControl() 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"

/*
 * Runs the user operator control code. This function will be started in its own task with the
 * default priority and stack size whenever the robot is enabled via the Field Management System
 * or the VEX Competition Switch in the operator control mode. If the robot is disabled or
 * communications is lost, the operator control task will be stopped by the kernel. Re-enabling
 * the robot will restart the task, not resume it from where it left off.
 *
 * If no VEX Competition Switch or Field Management system is plugged in, the VEX Cortex will
 * run the operator control task. Be warned that this will also occur if the VEX Cortex is
 * tethered directly to a computer via the USB A to A cable without any VEX Joystick attached.
 *
 * Code running in this task can take almost any action, as the VEX Joystick is available and
 * the scheduler is operational. However, proper use of delay() or taskDelayUntil() is highly
 * recommended to give other tasks (including system tasks such as updating LCDs) time to run.
 *
 * This task should never exit; it should end with some kind of infinite loop, even if empty.
 */
void operatorControl() {
/*
	//Create "deadzone" variables. Adjust threshold value to increase/decrease deadzone
	int X2 = 0, Y1 = 0, X1 = 0, threshold = 7;

	//Loop Forever
	while(1)
	{
	int rightStickLeft =  -joystickGetAnalog(1, 3)0;
	int leftStickUp = -joystickGetAnalog(1, 3)0;
	int leftStickLeft = joystickGetAnalog(1, 4)0;
	int frontright = 3;
	int backright = 9;
	int frontleft = 2;
	int backleft = 8;

	//Create "deadzone" for Y1/Ch3
	if(abs(leftStickLeft) > threshold){
	Y1 = leftStickLeft;
	}else{
	Y1 = 0;
	}
	//Create "deadzone" for X1/Ch4
	if(abs(leftStickUp) > threshold){
	X1 = leftStickUp;
	}else{
	X1 = 0;
	}
	//Create "deadzone" for X2/Ch1
	if(abs(rightStickLeft) > threshold){
	X2 = rightStickLeft;
	}else{
	X2 = 0;
	}
	//Remote Control Commands
	motorSet(frontright, Y1 + X2 - X1);
	motorSet(backright, Y1 + X2 + X1);
	motorSet(frontleft, Y1 - X2 + X1);
	motorSet(backleft, Y1 - X2 - X1);
	delay(1);
	}
*/
}

basicly im using both joysticks the one on the right is for rotation the bot the one on the left is to move left right forward and backward. but now that i switched to pros ive got a conflict on the movement the leftjoystick i guess it trying to move left and right but it is conflictiong with wheel movements and then the op on the same stick is rotation and then left and right on the right joystick is for moving forward and backward…

I don’t have time to try this right now, obviously all the code is commented out so will do nothing as is.

These lines needs fixing.

int rightStickLeft =  -joystickGetAnalog(1, 3)0;
	int leftStickUp = -joystickGetAnalog(1, 3)0;
	int leftStickLeft = joystickGetAnalog(1, 4)0;

remove those trailing "0"s, it will not compile like that. rightStickLeft and leftStickUp use the same joystick axis so change those (both axis 3). Increase that delay at the end of the code to 20.

the - joystickGetAnalog was commented out and when i went to comment out the whole block of the code i had to remove the comments to get it to work like i wanted it to but then again it didnt work either

ok so i got it working now thanks for the help with the command to print the values to the terminal helped me look at it the values it was printing and then helped me run through and change the logic around completely to get it to move in the directions. so now its time to move onto atonomous … i hate doing this…:mad::mad::mad::mad:

        {
        motorSet(frontright, 127);
        motorSet(backright, 127);
        motorSet(frontleft, - 127);
        motorSet(backleft, - 127);

        //Remote Control Commands
    	//move(0, 127, 0, 0.5);

        delay(1);

        if( debugCtr++ == 5 )
            {
            debugCtr = 0;
            printf("drive vals %d %d %d\r\n", Y1, X1, X2 );
            }

        }

now it just sits there and does nothing fml

any pointers?