I2C Port Motor and Sensor Setup Bug

I’m currently using the Integrated Motor Encoder for the VEX 393 two-wire motor. I’m working with the menu level set to ‘super user’. I’ve experienced a bug where anytime my program is opened in the IDE or the motor and sensor setup is opened, the program loses the sensor configuration for the I2C ports. This happens whether I manually change the serial ports configuration or not. The bug is not only annoying, it has the potential to cause major problems during a match, should this step be forgotten when making a minor adjustment (say, moving something from a bad port to a good port) before a match. How do I go about preventing this lose of information in the program from happening?

The following is my code. It isn’t overly pretty and doesn’t have pseudo code, but it should be relatively straight forward.

#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, dgtl1,  armEncoderR,    sensorQuadEncoder)
#pragma config(Sensor, dgtl3,  armEncoderL,    sensorQuadEncoder)
#pragma config(Sensor, dgtl5,  pincerEncoderR, sensorQuadEncoder)
#pragma config(Sensor, dgtl7,  pincerEncoderL, sensorNone)
#pragma config(Sensor, dgtl12, turn,           sensorTouch)
#pragma config(Sensor, I2C_1,  left_enc,       sensorQuadEncoderOnI2CPort,    , AutoAssign )
#pragma config(Sensor, I2C_2,  right_enc,      sensorQuadEncoderOnI2CPort,    , AutoAssign )
#pragma config(Motor,  port1,           backLeftMotor, tmotorVex393TurboSpeed_HBridge, openLoop)
#pragma config(Motor,  port2,           midLeftMotor,  tmotorVex393TurboSpeed_MC29, openLoop)
#pragma config(Motor,  port3,           frontLeftMotor, tmotorVex393TurboSpeed_MC29, openLoop)
#pragma config(Motor,  port4,           armL,          tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor,  port5,           armL_3,        tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor,  port6,           armR,          tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor,  port7,           armR_3,        tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor,  port8,           backRightMotor, tmotorVex393TurboSpeed_MC29, openLoop, reversed)
#pragma config(Motor,  port9,           midRightMotor, tmotorVex393TurboSpeed_MC29, openLoop, reversed)
#pragma config(Motor,  port10,          frontRightMotor, tmotorVex393TurboSpeed_HBridge, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*
Project Title: 9457A REBOOT TELE-OP CONTROL
Team Members: Tessa, Samuel, Zach, Kenzie, Tonya, Nick, Paul, Alex
Date: 12/08/16


Task Description:
1. Go forward
2. Lift the arm half way
3. Turn 135 degrees
4. Back up to fence
5. Raise lift all the way.


Pseudocode:

*/

int on_right = 1;

void armControlL(int speed)
{
	motor[armL] = (speed);
	motor[armL_3] = (speed);
}

void armControlR(int speed)
{
	motor[armR] = (speed);
	motor[armR_3] = (speed);
}

void right_speed(int speed)
{
	motor[backRightMotor] = speed;
	motor[midRightMotor] = speed;
	motor[frontRightMotor] = speed;
}

void left_speed(int speed)
{
	motor[backLeftMotor] = speed;
	motor[midLeftMotor] = speed;
	motor[frontLeftMotor] = speed;
}

void pre()
{
	SensorValue(armEncoderR) = 0;
	SensorValue(left_enc) = 0;
	SensorValue(right_enc) = 0;

	if(SensorValue(turn) == 1)
	{
		on_right = 1;
	}
	else
	{
		on_right = -1;
	}
}

task main()
{
	pre();

	while(SensorValue(left_enc) < 400)
	{
		left_speed(107);
		right_speed(107);
	}

	left_speed(0);
	right_speed(0);

	wait1Msec(750);

	SensorValue(left_enc) = 0;
	SensorValue(right_enc) = 0;

	while(abs(SensorValue(left_enc)) < 200) //First Turn
	{
		left_speed((87 * on_right));
		right_speed((-87 * on_right));
	}

	left_speed(0);
	right_speed(0);

	wait1Msec(750);

	SensorValue(left_enc) = 0;
	SensorValue(right_enc) = 0;

	while(SensorValue(left_enc) < 550)
	{
		left_speed(107);
		right_speed(107);
	}

	left_speed(0);
	right_speed(0);

	wait1Msec(750);

	SensorValue(left_enc) = 0;
	SensorValue(right_enc) = 0;

	while(SensorValue(armEncoderR) < 30)
	{
		armControlL(87);
		armControlR(87);
	}

	armControlL(15);
	armControlR(15);

	wait1Msec(750);

	while(abs(SensorValue(left_enc)) < 200) //Second Turn
	{
		left_speed((47 * on_right));
		right_speed((-47 * on_right));
	}

	left_speed(0);
	right_speed(0);

	wait1Msec(750);

	SensorValue(left_enc) = 0;
	SensorValue(right_enc) = 0;

	while(SensorValue(left_enc) > -300)
	{
		left_speed(-127);
		right_speed(-127);
	}

	left_speed(0);
	right_speed(0);

	SensorValue(left_enc) = 0;
	SensorValue(right_enc) = 0;

	left_speed(-127);
	right_speed(-127);

	wait1Msec(1000);

	left_speed(0);
	right_speed(0);

	SensorValue(left_enc) = 0;
	SensorValue(right_enc) = 0;

	while(SensorValue(armEncoderR) < 100)
	{
		armControlR(107);
		armControlL(107);
	}

	armControlR(15);
	armControlL(15);

	wait1Msec(500);

	while(SensorValue(armEncoderR) > 10)
	{
		armControlR(-15);
		armControlL(-15);
	}

	armControlR(15);
	armControlL(15);
}

IMEs need to be assigned to motors in the motors tab of the M&S dialog. The assignment there will update the sensor type in the I2C sensors tab.

If a motor type is changed (say from high speed to turbo), you need to reset the reverse flag and IME assigned to it.