1
$\begingroup$

I want to switch from usercontrol to autonomous. When I have the program running for 120 seconds, how come it wont automatically switch in autonomous mode? Thanks!

#pragma config(Motor,  port1,           driveBR,       tmotorVex393, openLoop)
#pragma config(Motor,  port2,           driveFR,       tmotorVex393, openLoop)
#pragma config(Motor,  port3,           driveFL,       tmotorVex393, openLoop)
#pragma config(Motor,  port4,           flyRight,      tmotorVex393, openLoop)
#pragma config(Motor,  port5,           driveBL,       tmotorVex393, openLoop)
#pragma config(Motor,  port6,           flyLeft,       tmotorVex393, openLoop)
#pragma config(Motor,  port10,          Belt,          tmotorVex393, openLoop)

//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma platform(VEX)
#pragma competitionControl(Competition)
#pragma autonomousDuration(15)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c"

//Main competition background code...do not modify!

void pre_auton() {
}

task autonomous() {
    while(true == true) {
        motor[flyLeft] = -127;
        motor[flyRight] = 127;
        wait1Msec(500);
        motor[Belt] = -127;
    }
}

task usercontrol() {
    while (true == true) {
        motor[driveFR] = -vexRT[Ch2];
        motor[driveFL] = vexRT[Ch3];
        motor[driveBR] = vexRT[Ch2];
        motor[driveBL] = vexRT[Ch3];

        if(vexRT[Btn6D] == 1) {
            motor[flyRight] = -127;
            motor[flyLeft] = -127;
        }
        if(vexRT[Btn6D] == 0) {
            motor[flyRight] = 0;
            motor[flyLeft] = 0;
        }
        if(vexRT[Btn5D] == 1) {
            motor[Belt] = -127;
        }
        if(vexRT[Btn5D] == 0) {
            motor[Belt] = 0;
        }
    }
}
$\endgroup$
  • 1
    $\begingroup$ Why would it ever switch into autonomous control? It looks like it just loops forever (while (true == true)) in one mode or the other. Do you have some code somewhere else not shown that calls autonomous and usercontrol? I don't see where the autonomousDuration or userControlDuration get used anywhere in that code section. $\endgroup$ – Chuck Feb 1 '16 at 21:00
  • $\begingroup$ @Chuck this seems to be correct as per the competition instructions, if that's what this is for. $\endgroup$ – Ian Feb 3 '16 at 5:57
1
$\begingroup$

It has been a while since worked with VEX, but if memory serves, it was always more picky about syntax than plain C# usually is. Try swapping lines from:

#pragma autonomousDuration(15)
#pragma userControlDuration(120)

To:

#pragma userControlDuration(120)
#pragma autonomousDuration(15)

If you are trying to swap into autonomous from user control, you usually have them in that order inside of the code itself. If only to help someone else to understand what your code is doing, and in what order it is doing it.

On top of that, it is possible that you are telling the program to run user control for 120 milliseconds, and autonomous to run for 15 milliseconds. I remember most VEX programming tended to use milliseconds for timing, instead of 'plain' seconds, so unless that has changed, your software system is doing exactly what you told it to do - but you've told it to do it for such a short period of time, that the mechanical system doesn't even have time to response in any noticeable way before the loop times-out. Try increasing the time values to 120,000 and 15,000 respectively, and see if that helps.

Again, it has been a while since I've worked with VEX, and a lot has probably changed since then, but I hope this is answer you are looking for.

$\endgroup$
  • $\begingroup$ 1. in this instance its actually seconds 2. changing the order didnt enable autonomous mode to run after 120 seconds. Any ideas? Do i need like a field controller? someone was telling me about it. $\endgroup$ – Zachary Gruber Feb 1 '16 at 20:38
  • $\begingroup$ @Zachary_Gruber, If you have a new question, please open a new thread. $\endgroup$ – Ben Feb 1 '16 at 20:59
  • $\begingroup$ Welcome to robotics @ZacharyGruber. On Stack exchange answers need to answer the question. If you have a related question, it should be asked as a new question (ideally referencing this one). Note that we prefer practical, answerable questions based on actual problems that you face. Please take a look at How to Ask and tour for more information on how stack exchange works. $\endgroup$ – Mark Booth Feb 2 '16 at 1:29
  • $\begingroup$ Also @ZacharyGruber, it looks you and Zach may be the same person. If so, then please follow the instructions at I accidentally created two accounts; how do I merge them? as Stack Exchange only allows an individual to actively use one account. Any and all duplicate accounts should be merged into your main account. $\endgroup$ – Mark Booth Feb 2 '16 at 1:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.