[Programming] 4 autonomous in buttons
Author |
Message |
Phoenix
Rookie
Joined: Mon Sep 02, 2013 12:54 pm Posts: 12
|
 [Programming] 4 autonomous in buttons
Hello everybody!  i'm having trouble with the programming Im want to put 4 autonomous in my robot with the buttons of the joystick but i dont know how. I request help how i can programming the 4 autonomous in the control? Sorry bad english, Im mexican an the school stinks to teach english Im using this cortex  Thanks for your time
_________________Team 7472-C CoBaCu
|
Fri Jan 10, 2014 7:55 pm |
|
 |
rcahoon
Site Admin
Joined: Tue Oct 09, 2012 10:34 am Posts: 192
|
 Re: [Programming] 4 autonomous in buttons
Hi Phoenix, I'm not sure if you're asking how to select between several different autonomous modes using the buttons of the joystick, or if you're asking about triggering automated behaviors during remote control operation, so here's the answer to both: Selecting an Autonomous ModeUnfortunately, joystick input is not available in the pre-autonomous phase during VEX competitions, so using the joystick to select between autonomous modes is probably not a good solution. See the Code Chooser.c sample code in File>>Open Sample Program>>LCD for how to use the VEX LCD to select between multiple autonomous routines (also this article). If you don't have an LCD, you can use touch sensors on the robot: Assuming you're using the VEX Competition Template that comes with ROBOTC. Near the top of your program file (after the #pragma statements, and outside of any functions or tasks), declare an int variable: In the pre_auton() function: Then make the autonomous task like this: Triggering Automated BehaviorsYou can launch a task to perform an automated behavior whenever a joystick button is pushed. Example: Using a task is an easy way to allow the behavior to run simultaneously with any other remote control code you might be using.
_________________ Ryan Cahoon CMU Robotics Academy RVW Software Developer
Robot Potato Head; Virtual NXT
Last edited by rcahoon on Tue Jan 21, 2014 2:45 pm, edited 1 time in total.
|
Fri Jan 17, 2014 4:19 pm |
|
 |
Phoenix
Rookie
Joined: Mon Sep 02, 2013 12:54 pm Posts: 12
|
 Re: [Programming] 4 autonomous in buttons
Thank you very much.  i try to make this for my cortex with sensor thanks for reply!  Edit: how to select between several different autonomous modes using the buttons of the joystick <<<<< This is i wanna do
_________________Team 7472-C CoBaCu
|
Fri Jan 17, 2014 10:24 pm |
|
 |
Phoenix
Rookie
Joined: Mon Sep 02, 2013 12:54 pm Posts: 12
|
 Re: [Programming] 4 autonomous in buttons
i have a question, i run this program: but i can't run in autonomous mode only in user control mode why?
_________________Team 7472-C CoBaCu
|
Mon Jan 20, 2014 4:36 pm |
|
 |
rcahoon
Site Admin
Joined: Tue Oct 09, 2012 10:34 am Posts: 192
|
 Re: [Programming] 4 autonomous in buttons
Hi Phoenix, See this document for how to add code for autonomous mode in ROBOTC. Cheers, --Ryan
_________________ Ryan Cahoon CMU Robotics Academy RVW Software Developer
Robot Potato Head; Virtual NXT
|
Tue Jan 21, 2014 12:35 pm |
|
 |
Phoenix
Rookie
Joined: Mon Sep 02, 2013 12:54 pm Posts: 12
|
 Re: [Programming] 4 autonomous in buttons
When i put my code in the autnomous mode robotc say **Error**:Task 'main' is not defined at global scope level another question: is possibly this program only with buttons?
_________________Team 7472-C CoBaCu
|
Tue Jan 21, 2014 12:55 pm |
|
 |
rcahoon
Site Admin
Joined: Tue Oct 09, 2012 10:34 am Posts: 192
|
 Re: [Programming] 4 autonomous in buttons
Make sure you include at the top of your program. This is done automatically if you select File>>New>>Competition Template. That looks correct.
_________________ Ryan Cahoon CMU Robotics Academy RVW Software Developer
Robot Potato Head; Virtual NXT
|
Tue Jan 21, 2014 1:26 pm |
|
 |
Phoenix
Rookie
Joined: Mon Sep 02, 2013 12:54 pm Posts: 12
|
 Re: [Programming] 4 autonomous in buttons
Thanks for all help but i can't understand this? //If button 5U is pressed...????? 
_________________Team 7472-C CoBaCu
|
Tue Jan 21, 2014 2:03 pm |
|
 |
JohnWatson
Site Admin
Joined: Thu May 24, 2012 12:15 pm Posts: 722
|
 Re: [Programming] 4 autonomous in buttons
The 5U button is referring to button 5 Up on the VEXNet Joystick. You can find more information on the VEXNet Joystick Controller here: http://www.robotc.net/wiki/VEX2_Functio ... l_-_VEXnetEdit: D'oh. The Field Hardware Management software disables all joystick commands before and during the autonomous period of VEX competitions (which makes sense; it's the only way to ensure that teams don't gain an unfair advantage by using their VEXNet Joystick Controllers during the autonomous period. The original quote (below) is therefore false; I apologize for any confusion.
_________________Check out our Blog! And our Facebook page! Need help? Take a look at our updated help documentation and the ROBOTC Forums.
|
Tue Jan 21, 2014 2:41 pm |
|
 |
rcahoon
Site Admin
Joined: Tue Oct 09, 2012 10:34 am Posts: 192
|
 Re: [Programming] 4 autonomous in buttons
Sorry I copied the code from somewhere else (John is correct that the comment originally referred to a joystick button) and modified it, but forgot to change the comment. It should read I've updated my original post as well --Ryan
_________________ Ryan Cahoon CMU Robotics Academy RVW Software Developer
Robot Potato Head; Virtual NXT
Last edited by rcahoon on Tue Jan 21, 2014 2:55 pm, edited 2 times in total.
|
Tue Jan 21, 2014 2:48 pm |
|
 |
rcahoon
Site Admin
Joined: Tue Oct 09, 2012 10:34 am Posts: 192
|
 Re: [Programming] 4 autonomous in buttons
John, Per Jesse's answer here, the joystick can't be used to select an autonomous program during a competition. Best, --Ryan
_________________ Ryan Cahoon CMU Robotics Academy RVW Software Developer
Robot Potato Head; Virtual NXT
|
Tue Jan 21, 2014 2:53 pm |
|
 |
Phoenix
Rookie
Joined: Mon Sep 02, 2013 12:54 pm Posts: 12
|
 Re: [Programming] 4 autonomous in buttons
Thanks a lot for your help but when i change the autonomous mode to user control mode my control don't respond i need to push a sensor touch and that dont look good. here my code, and thanks again for your help  |  |  |  | Code: #pragma config(Sensor, dgtl1, automata1, sensorTouch) #pragma config(Sensor, dgtl2, automata2, sensorTouch) #pragma config(Sensor, dgtl3, automata3, sensorTouch) #pragma config(Sensor, dgtl4, automata4, sensorTouch) #pragma config(Motor, port1, ruedaizquierda, tmotorVex393, openLoop) #pragma config(Motor, port2, linealizquierdo, tmotorVex393, openLoop) #pragma config(Motor, port3, torreizquierda, tmotorVex393, openLoop) #pragma config(Motor, port4, torrederecha, tmotorVex393, openLoop) #pragma config(Motor, port5, ruedafrented, tmotorVex393, openLoop) #pragma config(Motor, port6, dedos, tmotorVex393, openLoop) #pragma config(Motor, port7, brazo, tmotorVex393, openLoop) #pragma config(Motor, port8, ruedafrentei, tmotorVex393, openLoop) #pragma config(Motor, port9, linealderecho, tmotorVex393, openLoop) #pragma config(Motor, port10, ruedaderecha, tmotorVex393, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
//Competition Control and Duration Settings #pragma competitionControl(Competition) #pragma autonomousDuration(20) #pragma userControlDuration(120)
#include "Vex_Competition_Includes.c" //Main competition background code...do not modify! int selectedAutonomous =0; ///////////////////////////////////////////////////////////////////////////////////////// // // Pre-Autonomous Functions // // You may want to perform some actions before the competition starts. Do them in the // following function. // /////////////////////////////////////////////////////////////////////////////////////////
void pre_auton() { selectedAutonomous = 0;
while(selectedAutonomous == 0)
{ if(SensorValue[automata1]) //azul_dentro... { selectedAutonomous = 1; // select autonomous mode 1 } if(SensorValue[automata2]) //azul_fuera... { selectedAutonomous = 2; // select autonomous mode 1 } if(SensorValue[automata3]) //rojo_dentro... { selectedAutonomous = 3; // select autonomous mode 1 } if(SensorValue[automata4]) //rojo_fuera... { selectedAutonomous = 4; // select autonomous mode 1 }
// add more if statements if you want to add more autonomous modes } }
///////////////////////////////////////////////////////////////////////////////////////// // // Autonomous Task // // This task is used to control your robot during the autonomous phase of a VEX Competition. // You must modify the code to add your own robot specific commands here. // /////////////////////////////////////////////////////////////////////////////////////////
task autonomous() { //AZUL_DENTRO if (selectedAutonomous == 1) { motor[ruedaizquierda]=127; motor[ruedaderecha]=127; motor[ruedafrented]=127; motor[ruedafrentei]=127; wait1Msec(1000);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0;
motor[ruedaizquierda]=127; motor[ruedaderecha]=-127; motor[ruedafrented]=-127; motor[ruedafrentei]=127; wait1Msec(400); motor[ruedaizquierda]=-127; motor[ruedaderecha]=-127; motor[ruedafrented]=-127; motor[ruedafrentei]=-127; wait1Msec(1300); motor[ruedaizquierda]=127; motor[ruedaderecha]=-127; motor[ruedafrented]=-127; motor[ruedafrentei]=127; wait1Msec(700); motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0;
motor[dedos]=127; wait1Msec(1300);
motor[dedos]=0; wait1Msec(100); motor[ruedaizquierda]=-127; motor[ruedaderecha]=-127; motor[ruedafrented]=-127; motor[ruedafrentei]=-127; wait1Msec(2100); motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0; motor[ruedaizquierda]=127; motor[ruedaderecha]=127; motor[ruedafrented]=127; motor[ruedafrentei]=127; wait1Msec(100); motor[ruedaizquierda]=127; motor[ruedaderecha]=-127; motor[ruedafrented]=-127; motor[ruedafrentei]=127; wait1Msec(700); motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0; motor[ruedaizquierda]=-127; motor[ruedaderecha]=-127; motor[ruedafrented]=-127; motor[ruedafrentei]=-127; wait1Msec(1800); motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0; }
//AZUL_FUERA
else if (selectedAutonomous == 2) { motor[ruedaizquierda]=127; motor[ruedaderecha]=127; motor[ruedafrented]=127; motor[ruedafrentei]=127; wait1Msec(390);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0;
motor[torrederecha]=127/2; motor[torreizquierda]=127/2; wait1Msec(1500);
motor[torrederecha]=0; motor[torreizquierda]=0;
motor[ruedaizquierda]=127/2; motor[ruedaderecha]=127/2; motor[ruedafrented]=127/2; motor[ruedafrentei]=127/2; wait1Msec(900);
motor[ruedaizquierda]=-127/2; motor[ruedaderecha]=-127/2; motor[ruedafrented]=-127/2; motor[ruedafrentei]=-127/2; wait1Msec(600);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0;
motor[dedos]=127; wait1Msec(1800);
motor[dedos]=0; wait1Msec(100);
motor[ruedaizquierda]=127; motor[ruedaderecha]=-127; motor[ruedafrentei]=127; motor[ruedafrented]=-127; wait1Msec(400);
motor[ruedaizquierda]=127; motor[ruedaderecha]=127; motor[ruedafrentei]=127; motor[ruedafrented]=127; wait1Msec(550);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrentei]=0; motor[ruedafrented]=0;
motor[torrederecha]=127/2; motor[torreizquierda]=127/2; wait1Msec(1000);
motor[torrederecha]=0; motor[torreizquierda]=0;
motor[ruedaizquierda]=-127; motor[ruedaderecha]=127; motor[ruedafrentei]=-127; motor[ruedafrented]=127; wait1Msec(250);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrentei]=0; motor[ruedafrented]=0;
motor[ruedaizquierda]=127; motor[ruedaderecha]=127; motor[ruedafrentei]=127; motor[ruedafrented]=127; wait1Msec(200);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrentei]=0; motor[ruedafrented]=0; }
//ROJO_DENTRO else if (selectedAutonomous == 3) { motor[ruedaizquierda]=127; motor[ruedaderecha]=127; motor[ruedafrented]=127; motor[ruedafrentei]=127; wait1Msec(700);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0;
motor[torrederecha]=127/2; motor[torreizquierda]=127/2; wait1Msec(600);
motor[torrederecha]=0; motor[torreizquierda]=0;
motor[ruedaizquierda]=127; motor[ruedaderecha]=-127; motor[ruedafrented]=-127; motor[ruedafrentei]=127; wait1Msec(350);
motor[ruedaizquierda]=127; motor[ruedaderecha]=127; motor[ruedafrented]=127; motor[ruedafrentei]=127; wait1Msec(150);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0;
motor[dedos]=127; wait1Msec(1200);
motor[dedos]=0; wait1Msec(100); }
//ROJO_FUERA else if (selectedAutonomous == 4) { motor[ruedaizquierda]=127; motor[ruedaderecha]=127; motor[ruedafrented]=127; motor[ruedafrentei]=127; wait1Msec(390);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0;
motor[torrederecha]=127/2; motor[torreizquierda]=127/2; wait1Msec(1500);
motor[torrederecha]=0; motor[torreizquierda]=0;
motor[ruedaizquierda]=127/2; motor[ruedaderecha]=127/2; motor[ruedafrented]=127/2; motor[ruedafrentei]=127/2; wait1Msec(500);
motor[ruedaizquierda]=-127/2; motor[ruedaderecha]=-127/2; motor[ruedafrented]=-127/2; motor[ruedafrentei]=-127/2; wait1Msec(200);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrented]=0; motor[ruedafrentei]=0;
motor[ruedaizquierda]=-127; motor[ruedaderecha]=127; motor[ruedafrentei]=-127; motor[ruedafrented]=127; wait1Msec(300);
motor[ruedaizquierda]=127; motor[ruedaderecha]=127; motor[ruedafrentei]=127; motor[ruedafrented]=127; wait1Msec(700);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrentei]=0; motor[ruedafrented]=0;
motor[ruedaizquierda]=127; motor[ruedaderecha]=-127; motor[ruedafrentei]=127; motor[ruedafrented]=-127; wait1Msec(500);
motor[ruedaizquierda]=0; motor[ruedaderecha]=0; motor[ruedafrentei]=0; motor[ruedafrented]=0; wait1Msec(500);
motor[dedos]=127; wait1Msec(1800);
motor[dedos]=0; wait1Msec(100); } }
///////////////////////////////////////////////////////////////////////////////////////// // // User Control Task // // This task is used to control your robot during the user control phase of a VEX Competition. // You must modify the code to add your own robot specific commands here. // /////////////////////////////////////////////////////////////////////////////////////////
task usercontrol() { // User control code here, inside the loop
while (1==1) { // ruedas motor[ruedaizquierda]=+vexRT[Ch3]+vexRT[Ch1]; motor[ruedaderecha]=+vexRT[Ch3]-vexRT[Ch1]; motor[ruedafrentei]=+vexRT[Ch3]+vexRT[Ch1]; motor[ruedafrented]=+vexRT[Ch3]-vexRT[Ch1];
// torres if(vexRT[Btn6U]==1) { motor[torreizquierda]=127; motor[torrederecha]=127; }
else if(vexRT[Btn6D]==1) { motor[torreizquierda]=-127; motor[torrederecha]=-127; } else { motor[torrederecha]=0; motor[torreizquierda]=0; } // dedos if(vexRT[Btn5U]==1) { motor[dedos]=127; }
else if(vexRT[Btn5D]==1) { motor[dedos]=-127; }
else { motor[dedos]=0; } //LINEARES
if(vexRT[Btn8U]==1) { motor[linealderecho]=127; motor[linealizquierdo]=127; } else if(vexRT[Btn8D]==1) { motor[linealderecho]=-127; motor[linealizquierdo]=-127; } else { motor[linealderecho]=0; motor[linealizquierdo]=0; }
//BRAZO
if(vexRT[Btn8L]==1) { motor[brazo]=-127; } else if(vexRT[Btn8R]==1) { motor[brazo]=127; } else { motor[brazo]=0; } } } |  |  |  |  |
_________________Team 7472-C CoBaCu
|
Tue Jan 21, 2014 3:44 pm |
|
 |
rcahoon
Site Admin
Joined: Tue Oct 09, 2012 10:34 am Posts: 192
|
 Re: [Programming] 4 autonomous in buttons
_________________ Ryan Cahoon CMU Robotics Academy RVW Software Developer
Robot Potato Head; Virtual NXT
|
Tue Jan 21, 2014 4:00 pm |
|
 |
Phoenix
Rookie
Joined: Mon Sep 02, 2013 12:54 pm Posts: 12
|
 Re: [Programming] 4 autonomous in buttons
it work's... but now dont run the autonomous when i push a sensor touch only in that line change the code? 
_________________Team 7472-C CoBaCu
|
Tue Jan 21, 2014 4:30 pm |
|
 |
rcahoon
Site Admin
Joined: Tue Oct 09, 2012 10:34 am Posts: 192
|
 Re: [Programming] 4 autonomous in buttons
It's probably because you aren't running the full field control system. Try
_________________ Ryan Cahoon CMU Robotics Academy RVW Software Developer
Robot Potato Head; Virtual NXT
|
Tue Jan 21, 2014 4:34 pm |
|
|
Who is online |
Users browsing this forum: No registered users and 2 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
|
|