View unanswered posts | View active topics It is currently Sat Jan 20, 2018 7:20 pm






Reply to topic  [ 2 posts ] 
Programming help 
Author Message
Rookie

Joined: Mon Feb 01, 2016 11:45 am
Posts: 1
Post Programming help
I am pretty new to robotc and vex and our team is having a problem please help it would be appreciated.
#pragma config(Sensor, dgtl1, leftencoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, rightencoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl5, sonarsensor, sensorSONAR_inch)
#pragma config(Motor, port1, BackIntake, tmotorVex393_HBridge, openLoop, driveRight)
#pragma config(Motor, port2, Drive1, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port3, Drive2, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port4, Drive3, tmotorVex393_MC29, openLoop, reversed, driveRight)
#pragma config(Motor, port5, Drive4, tmotorVex393_MC29, openLoop, reversed, driveRight)
#pragma config(Motor, port6, launchleft, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port7, launchright, tmotorVex393_MC29, openLoop, reversed, driveLeft)
#pragma config(Motor, port8, gate, tmotorServoStandard, openLoop)
#pragma config(Motor, port9, leftintake, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port10, rightintake, tmotorVex393_HBridge, openLoop)
#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!
/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////
void waitForPress()
{
while(nLCDButtons == 0){}
wait1Msec(5);
}
void waitForRelease()
{
while(nLCDButtons != 0){}
wait1Msec(5);
}
void pre_auton()
{
const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;
//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;
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// 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()
{
bStopTasksBetweenModes = true;
//Clear LCD
clearLCDLine(0);
clearLCDLine(1);
//Switch Case that actually runs the user choice
int count = 0;
switch(count){
//===============
case 1:
//If count = 1, run the code correspoinding with choice 2
displayLCDCenteredString(0, "Autonomous 1");
displayLCDCenteredString(1, "is running!");
motor[port10] = 100;
motor[port9] = 100;
motor[port1] = -127;
wait(.1);
SensorValue[rightencoder] = 0; //Set the encoder so that it starts counting at 0
while(SensorValue(rightencoder) < 2800) //While rightEncoder has counted less than 1800 counts
{
//drive backward
motor[Drive1] = -127;
motor[Drive2] = -127;
motor[Drive3] = -127;
motor[Drive4] = -127;
wait(.1);
}
//Set the encoder so that it starts counting at 0
SensorValue[rightencoder] = 0;
while(SensorValue(rightencoder) < -600) //While leftEncoder has counted less than 1800 counts
{
//Turn Right
pointTurn(right,127);
wait(1);

//motor[Drive1] = -127;
// motor[Drive2] = -127;
//motor[Drive3] = 127;
// motor[Drive4] = 127;
}
while(SensorValue(sonarsensor) > 5 || SensorValue(sonarsensor) == -1) // Loop while robot's Ultrasonic sensor is further than 20 inches away from an object
// || (or) it is '-1'. (-1 is the value returned when nothing is in it's visable range)
{
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = 127;
motor[Drive4] = 127;
break;
//===============
switch(2){
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 forward at full power for 3 seconds
motor[port6] = 65.5;
motor[port7] = 65.5;
motor[port10] = 100;
motor[port9] = 100;
motor[port1] = -127;
wait(30); //Robot waits for 2000 milliseconds before executing program

SensorValue[rightencoder] = 0; //Set the encoder so that it starts counting at 0

while(SensorValue(rightencoder) < 1800) //While rightEncoder has counted less than 1800 counts
{
//Turn Left
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = -127;
motor[Drive4] = -127;
}

SensorValue[leftencoder] = 0; //Set the encoder so that it starts counting at 0

while(SensorValue(leftencoder) < 1800) //While leftEncoder has counted less than 1800 counts
{
//Turn Right
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = -127;
motor[Drive4] = -127;
}


while(SensorValue(sonarsensor) > 20 || SensorValue(sonarsensor) == -1) // Loop while robot's Ultrasonic sensor is further than 20 inches away from an object
{ // || (or) it is '-1'. (-1 is the value returned when nothing is in it's visable range)
motor[Drive1] = 127;
motor[Drive2] = 127;
motor[Drive3] = 127;
motor[Drive4] = 127;
wait(60); // Robot runs previous code for 60 seconds before moving on
break;
switch(3){
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[Drive2] = -63; // Motor on port2 is run at half power reverse
motor[Drive4] = 63; // Motor on port3 is run at half power forward
wait1Msec(3000); // Robot runs previous code for 3000 milliseconds before moving on
break;
switch(4){
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
motor[Drive2] = -63; // Motor on port2 is run at half power reverse
motor[Drive4] = 63; // Motor on port3 is run at half power forward
wait1Msec(2000);
break;
default:
displayLCDCenteredString(0, "No valid choice");
displayLCDCenteredString(1, "was made!");
break;
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// 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()
{
while (1==1)
{
motor[Drive1] = (vexRT[Ch2]);
motor[Drive2] = (vexRT[Ch2]);
motor[Drive3] = (vexRT[Ch3]);
motor[Drive4] = (vexRT[Ch3]);
}
if(vexRT[Btn5UXmtr2] == 1)
{
motor[port6] = 88; //65.5
motor[port7] = 88;
}
else
{
motor[port6] = 0;
motor[port7] = 0;
}

if(vexRT[Btn6UXmtr2] == 1)
{
motor[port10] = 90;
motor[port9] = 90;
motor[port1] = -127;
}
else if(vexRT[Btn6DXmtr2] == 1)
{
motor[port10] = -127;
motor[port9] = -127;
motor[port1] = 127;
}
else
{
motor[port10] = 0;
motor[port9] = 0;
motor[port1] = 0;
}

if(vexRT[Btn6U] == 1)
{
setServo(port8, -5);
}
else
{
setServo(port8, 105);
}
}
}
}
}


Mon Feb 01, 2016 11:52 am
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post Re: Programming help
So you are going to have to be more specific about what the problem is. I read through the user control code and it seems to work properly. Also in the future click the code button above the text your entering and put the code between the code tags.


Wed Feb 03, 2016 5:04 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.