Response to: Combining 4 motor commands into 1 command

The community can’t answer questions in the official Tech support.

This is always my go to lesson when teaching programming to new teams. You have already realized that there are more efficient ways in programming. I encourage my students to use functions.

Here is an example of a function to drive your chassis.

//Runs the chassis wheels at a specific speed
void drive(int left, int right)
{
		motor[leftF]  =  left;
		motor[leftR]  =  left;
		motor[rightF] =  right;
		motor[rightR] =  right;
}

I also like to add a


driveFor

function that adds a duration. If you look at the


autonomous

task you will see that you can navigate the robot with one line of code for each move.

#pragma config(Motor,  port1,           leftF,         tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           leftR,         tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           rightR,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port10,          rightF,        tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//Runs the chassis wheels at a specific speed
void drive(int left, int right)
{
		motor[leftF]  =  left;
		motor[leftR]  =  left;
		motor[rightF] =  right;
		motor[rightR] =  right;
}

//Runs the chassis wheels for a specific duration.
void driveFor(int left, int right, int duration)
{
	drive(left,right);
	wait1Msec(duration);
	drive(0,0);
}

task autonomous()
{
	driveFor(60,60,1500); 		//drive forward
	driveFor(-60,60, 750);		//rotate left
	driveFor(60,60,2300);		//drive forward
	driveFor(-60,60, 750);		//rotate right
}

Deep thinking time…
Lets say that the rest of your programming uses the


drive

function whenever you want the chassis to move. Now you have an advantage. Should you ever change the design of your chassis (ie: x-drive, chain drive, 6 motor) then you will only need to change the code in the


drive

function. The rest of the programming will continue to work because the responsibility of running the chassis motors is solely dependent on the drive function.

Hope that helps.

The function suggestion is excellent, and your program would be far superior using functions.
A more simplistic and direct answer to your question is this:


motor[port1] = motor[port2] = motor[port3] = motor[port4] = 100;