Multi Autonomous using Jumpers

I am using digital ports 1-4 for 4 different routines in autonomous (1 for each starting tile, I haven’t actually coded much in that). I get errors when I try to compile the code, and I haven’t been able to figure out why the errors are coming up. When I go to insert the if/else statements, I get errors (posted below) even when I manually drag the if statements in from the left sidebar.

The code is 119 lines, so I went ahead and posted it to pastebin.

http://pastebin.com/RfUpMyzP

**Error**:Unexpected 'else'. Ignored.
**Error**:Unexpected 'if' during parsing
*Warning*:Missing ';' has been automatically inserted by compiler
**Error**:Unexpected 'else'. Ignored.
**Error**:Unexpected 'if' during parsing
*Warning*:Missing ';' has been automatically inserted by compiler
*Warning*:Null statement found on existing line. Is this intentional?
**Error**:Unexpected 'else'. Ignored.
**Error**:Unexpected 'statement' during parsing
*Warning*:Missing ';' has been automatically inserted by compiler
**Error**:Unexpected 'else'. Ignored.
**Error**:Unexpected 'if' during parsing

You are forgetting curly brackets and you need to use the call SensorValue[mySensor] or SensorBoolean[mySensor] to get the values of the jumper clips. I also noticed you had some duplicate code, I commented it out so you can make sure it is indeed duplicate. Gist linky. I think I squashed all of the syntax errors, but I’ve currently loaned my last ROBOTC license to a team member, so can’t compile and double check to make sure I’m not missing anything.


#pragma config(Sensor, dgtl1,  redmiddle,      sensorDigitalIn)
#pragma config(Sensor, dgtl2,  bluemiddle,     sensorDigitalIn)
#pragma config(Sensor, dgtl3,  redhang,        sensorDigitalIn)
#pragma config(Sensor, dgtl4,  bluehang,       sensorDigitalIn)
#pragma config(Motor,  port1,           armMotor,      tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           leftfront,     tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           leftmidfront,  tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           leftmidback,   tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           leftback,      tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port6,           rightfront,    tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port7,           rightmidfront, tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port8,           rightmidback,  tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           rightback,     tmotorVex393_MC29, openLoop, reversed)
task autonomous()
{
	int redmiddle;
	int bluemiddle;
	int redhang;
	int bluehang;
 
	if (SensorBoolean[redmiddle] /* = true */) // jumper port is plugged in
	{
		// Autonomous code below to run if in the Middle Zone, red alliance
 
		motor[armMotor] = 127;
		wait1Msec(100);
 
		motor[leftfront] = 127;
		motor[leftmidfront] = 127;
		motor[leftmidback] = 127;
		motor[leftback] =127;
		motor[rightfront] =127;
		motor[rightmidfront] = 127;
		motor[rightmidback] = 127;
		motor[rightback] = 127;
	}
	else if (SensorBoolean[bluemiddle])
	{
		// Autonomous code below to run if in the Middle Zone, blue alliance
		motor[leftfront] = 127;
		motor[leftmidfront] = 127;
		motor[leftmidback] = 127;
		motor[leftback] =127;
		motor[rightfront] =127;
		motor[rightmidfront] = 127;
		motor[rightmidback] = 127;
		motor[rightback] = 127;
	}
	else if (SensorBoolean[redhang])
	{
		// Autonomous code below to run if in the Hanging Zone, red alliance
		motor[leftfront] = 127;
		motor[leftmidfront] = 127;
		motor[leftmidback] = 127;
		motor[leftback] =127;
		motor[rightfront] =127;
		motor[rightmidfront] = 127;
		motor[rightmidback] = 127;
		motor[rightback] = 127;
	}
	/* Is this code duplicate?
	else if (SensorBoolean[redhang])
	{
		motor[leftfront] = 127;
		motor[leftmidfront] = 127;
		motor[leftmidback] = 127;
		motor[leftback] =127;
		motor[rightfront] =127;
		motor[rightmidfront] = 127;
		motor[rightmidback] = 127;
		motor[rightback] = 127;
	}
	*/
	else if (SensorBoolean[bluehang])
	{
		// Autonomous code below to run if in the Hanging Zone, blue alliance
		motor[leftfront] = 127;
		motor[leftmidfront] = 127;
		motor[leftmidback] = 127;
		motor[leftback] = 127;
		motor[rightfront] = 127;
		motor[rightmidfront] = 127;
		motor[rightmidback] = 127;
		motor[rightback] = 127;
	}
}

Thanks Elliot! I already knew about the curly brackets but not about using (SensorBoolean)…

You could still use SensorValue, but I think booleans make more sense for switches (bumpers, limits, jumpers).

Shouldn’t you be using bool instead of int when declaring your variables?

My apologies if i’m missing something, my background in C is kind of lacking beyond using it in robotics ^.^

Oh, completely missed those declarations. Those should be completely removed from the code. Having those in there will give you compiler errors.

Get rid of the int myVariable; right after the autonomous task starts.

Well in “real” c there is no bool type. When you include the boolean libraries, it basically just redefines bool as int lol. You just use 0 as false and any other number (typically 1) as true. In RobotC, bool actually is a type but you can still use int as a bool the same way as in standard C.

So often in C you’ll see bool and int used interchangeably. At the end of the day, it’s basically up to personal preference, but using bool certainly makes it clearer what the purpose of the variable is.

Ah, thanks for the explanation. That makes a lot of sense, especially when looking at it from a logic or on off perspective.

Here is the code without duplicate code and extra variables:
http://pastebin.com/e6S7jeJF
You should probably take a look at edjubuh’s code also.

#pragma config(Sensor, dgtl1,  redmiddle,      sensorDigitalIn)
#pragma config(Sensor, dgtl2,  bluemiddle,     sensorDigitalIn)
#pragma config(Sensor, dgtl3,  redhang,        sensorDigitalIn)
#pragma config(Sensor, dgtl4,  bluehang,       sensorDigitalIn)
#pragma config(Motor,  port1,           armMotor,      tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           leftfront,     tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           leftmidfront,  tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           leftmidback,   tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           leftback,      tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port6,           rightfront,    tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port7,           rightmidfront, tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port8,           rightmidback,  tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           rightback,     tmotorVex393_MC29, openLoop, reversed)
 
task autonomous()
{
        if (SensorBoolean[redmiddle]) // jumper port is plugged in
        {       // Autonomous code below to run if in the Middle Zone, red alliance
 
                motor[armMotor] = 127;
                wait1Msec(100);
 
                motor[leftfront] = 127;
                motor[leftmidfront] = 127;
                motor[leftmidback] = 127;
                motor[leftback] =127;
                motor[rightfront] =127;
                motor[rightmidfront] = 127;
                motor[rightmidback] = 127;
                motor[rightback] = 127;
        }
        else if (SensorBoolean[bluemiddle])
        {       // Autonomous code below to run if in the Middle Zone, blue alliance
                motor[leftfront] = 127;
                motor[leftmidfront] = 127;
                motor[leftmidback] = 127;
                motor[leftback] =127;
                motor[rightfront] =127;
                motor[rightmidfront] = 127;
                motor[rightmidback] = 127;
                motor[rightback] = 127;
        }
        else if (SensorBoolean[redhang])
        {       // Autonomous code below to run if in the Hanging Zone, red alliance
                motor[leftfront] = 127;
                motor[leftmidfront] = 127;
                motor[leftmidback] = 127;
                motor[leftback] =127;
                motor[rightfront] =127;
                motor[rightmidfront] = 127;
                motor[rightmidback] = 127;
                motor[rightback] = 127;
        }
        else if (SensorBoolean[bluehang])
        {       // Autonomous code below to run if in the Hanging Zone, blue alliance
                motor[leftfront] = 127;
                motor[leftmidfront] = 127;
                motor[leftmidback] = 127;
                motor[leftback] = 127;
                motor[rightfront] = 127;
                motor[rightmidfront] = 127;
                motor[rightmidback] = 127;
                motor[rightback] = 127;
        }
}

You can also have one autonomous already be pre-selected without a jumper being put into a port. Instead of an else if, just do an else.

#pragma config(Sensor, dgtl1,  redmiddle,      sensorDigitalIn)
#pragma config(Sensor, dgtl2,  bluemiddle,     sensorDigitalIn)
#pragma config(Sensor, dgtl3,  redhang,        sensorDigitalIn)
#pragma config(Sensor, dgtl4,  bluehang,       sensorDigitalIn)
#pragma config(Motor,  port1,           armMotor,      tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           leftfront,     tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           leftmidfront,  tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           leftmidback,   tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           leftback,      tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port6,           rightfront,    tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port7,           rightmidfront, tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port8,           rightmidback,  tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           rightback,     tmotorVex393_MC29, openLoop, reversed)
 
task autonomous()
{
        if (SensorBoolean[redmiddle]) // jumper port is plugged in
        {       // Autonomous code below to run if in the Middle Zone, red alliance
 
                motor[armMotor] = 127;
                wait1Msec(100);
 
                motor[leftfront] = 127;
                motor[leftmidfront] = 127;
                motor[leftmidback] = 127;
                motor[leftback] =127;
                motor[rightfront] =127;
                motor[rightmidfront] = 127;
                motor[rightmidback] = 127;
                motor[rightback] = 127;
        }
        else if (SensorBoolean[bluemiddle])
        {       // Autonomous code below to run if in the Middle Zone, blue alliance
                motor[leftfront] = 127;
                motor[leftmidfront] = 127;
                motor[leftmidback] = 127;
                motor[leftback] =127;
                motor[rightfront] =127;
                motor[rightmidfront] = 127;
                motor[rightmidback] = 127;
                motor[rightback] = 127;
        }
        else if (SensorBoolean[redhang])
        {       // Autonomous code below to run if in the Hanging Zone, red alliance
                motor[leftfront] = 127;
                motor[leftmidfront] = 127;
                motor[leftmidback] = 127;
                motor[leftback] =127;
                motor[rightfront] =127;
                motor[rightmidfront] = 127;
                motor[rightmidback] = 127;
                motor[rightback] = 127;
        }
        else (SensorBoolean[bluehang])
        {       // Autonomous code below to run if in the Hanging Zone, blue alliance
                motor[leftfront] = 127;
                motor[leftmidfront] = 127;
                motor[leftmidback] = 127;
                motor[leftback] = 127;
                motor[rightfront] = 127;
                motor[rightmidfront] = 127;
                motor[rightmidback] = 127;
                motor[rightback] = 127;
        }
}

So basically with that, Blue Hang autonomous is always going to run unless a jumper is put into a port. This is what we are doing this year.

I didn’t realize that I didn’t have to redeclare the variables (Tested PROS, and you have to declare them above the autonomous code). I’ll change the else if to an else for the blue hanging zone autonomous. Thanks to y’all for helping me as this is my first real shot at ROBOTC.

Here’s some old Gateway code but you can get the idea. Use zone test and red blue test global variables in the autonomous. Name the zones what you need to.

Using LED’s help in two ways - you can create a tight space between the LED’s to put the jumpers in and not get them in the wrong ports. The LED’s also give feedback on whether it worked.

You will have to call it from pre_auton or auton and you can even call it from inside driver control if you want.

#define BLUE_TEAM 0
#define RED_TEAM  1
#define INTERACTION_ZONE_START  1
#define ISOLATION_ZONE_START 0

int red_blue_test = BLUE_TEAM;
int zone_test = INTERACTION_ZONE_START;

void initJumpers()
{

  if(SensorValue[red_blue_jumper]==1)
  {
    SensorValue[LED_RED] = 1;
    red_blue_test = BLUE_TEAM;
  }
  else
  {
    SensorValue[LED_RED] = 0;
    red_blue_test = RED_TEAM;
  }

  if(SensorValue[zone_jumper] ==1)
  {
    SensorValue[LED_GREEN] = 1;
    zone_test = ISOLATION_ZONE_START;
  }
  else
  {
    SensorValue[LED_GREEN] = 0;
    zone_test = INTERACTION_ZONE_START;
  }
}

How you program it to the jumper? :confused:

The digital sensors have a few ports defined for the LED_RED and LED_GREEN and red_blue_jumper and zone_jumper. Just choose some ports for where you stick them in.

When you stick a jumper in that port, it will evaluate to 1. It then lights the LED to the appropriate value. (red turns on for the red zone)

Do you use EasyC or RobotC? :confused:

Based on the code they posted, it appears that they are using ROBOTC.

Using jumpers is actually not that difficult, comparatively. In ROBOTC, declare a “digital in” type (like a touch sensor) with the port where the jumper will be placed.

Then, read that port with SensorValue]–it behaves pretty much exactly like a touch sensor.

//Andrew

How would I do it in EasyC versus doing it in ROBOTC? :confused:

Search is your friend . :wink:

Here’s a thread I dug up… I suggest re-reading it in its entirety before attempting it yourself: https://vexforum.com/t/help-programming-multiple-auto-selected-by-lcd/24469/1&highlight=easyC+autonomous+select*
(I used search keywords “easyC autonomous select*”–the “select*” matches anything that starts with select, like “selection”, “selector”, or just “select”)

//Andrew

I know this is a dumb question. but how/ where do you put the “#pragma config(Sensor…” Im new (obviously) please help. Thanks

RObot C you go into the motor ans sensor dialog. Digital port set up for a jumper, analog for a potentiometer. Scroll down to see the exact screens here…

http://www.robotc.net/support/cortex/WebHelpCortex/index.htm#page=robotc_interface/motor_sensor_setup/Motors%20and%20Sensors%20Setup.htm