Newbie (mainly auton.) code troubles

I’m completely new to RobotC and I have a stupid question: can you use decimal point values in variables, like below:


	motor[one] = 63.5;	
	motor[two]= 63.5;
	motor[nine] = 63.5;
	motor[ten] = 63.5;

Also, I’m a bit confused in regards to where exactly you put your autonomous in the program. I have commented out an alternative one for scoring a mobile goal and stuff, but I’m just looking for why exactly these errors are popping up:


*Warning*:Meaningless statement -- no code generated
*Warning*:Missing ';' has been automatically inserted by compiler
**Error**:Internal Compiler: Unexpected use of proc 'wait1Msec' in an expression
**Error**:Procedure 'wait1Msec' is invalid syntax at this point
**Error**:LValue for ']' operator must be a pointer
*Warning*:Meaningless statement -- no code generated
*Warning*:';' expected before '}'. Automatically inserted by compiler

And here is the code:


void pre_auton()
{
	motor[claw] = 0; //makes sure it is all the way down if we are using MG auton
	motor[three] = 0; //same as above but for lift
	motor[four] = 0;
	motor[five] = 0;
	motor[six] = 0;
}

task autonomous //for scoring on stationary goal in front of robot
{
	motor[one] = 63.5;		// moves toward goal
	motor[two]= 63.5;
	motor[nine] = 63.5;
	motor[ten] = 63.5;
	wait1Msec[1000];		// duration of time for which it moves forward
	motor[claw] = 127		//keeps holding preload
	motor[three] = 127;		// lift lifts to top capacity
	motor[four] = 127;
	motor[five] = 127;
	motor[six] = 127;
	wait1Msec[5000]; // does everything above for 5 seconds
	motor[claw] = -127 // claw release
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//auton for turning right and scoring cone on mobile goal...using point turn vs. swing turn to be more precise //
/////////////////////////////////////////////////////////////////////////////////
//task autonomous //for scoring on stationary goal in front of robot
//{
//	motor[ten] = 67;		// turns to exact angle facing goal
//	motor[claw] = 100;	// keeps hold on preload
//	wait1Msec[1000];
//	motor[claw] = 100;	// keeps hold on preload
//	motor[one] = 127;		// moves toward goal
//	motor[two]= 127;
//	motor[nine] = 127;
//	motor[ten] = 127; 
//insert positioning here for turning of chassis motors
//	wait1Msec[2500];
//	motor[claw] = 100;	// keeps hold on preload
//	motor[three] = 67;
//	motor[four] = 67;
//	motor[five] = 67;
//	motor[six] = 67;
//	wait1Msec[2500];
//	motor[claw] = -100;
//}
///////////////////////////////////////

#pragma config(Motor,  port1,           one,           tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           two,           tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           three,         tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port4,           four,          tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           five,          tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port6,           six,           tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port7,           claw,          tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           nine,          tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port10,          ten,           tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
	while (true)
	{
		motor[port1] = vexRT(Ch3);
		motor[port2] = vexRT(Ch3);
		motor[port9]= vexRT(Ch2);
		motor[port10] = vexRT(Ch2);
		motor[port3] = vexRT(Btn6U)*127 - vexRT(Btn6D) *127;
		motor[port4] = vexRT(Btn6U) *127 - vexRT(Btn6D) *127;
		motor[port5] = vexRT(Btn6U) *127 - vexRT(Btn6D) *127;
		motor[port6] = vexRT(Btn6U) *127 - vexRT(Btn6D) *127;
		motor[port7] = vexRT(Btn5U) *127 - vexRT(Btn5D) *127;
	}
	
}
////////////////////////////////////////////////////////////////////////////////////////////////////////

It’s kind of a giant mess, and I’ve done my best to point out my intentions in parts of this with comments. If anyone has the slightest idea what’s going on with these errors or knows where to put each section of the code (which I suspect is causing some of them) that would be awesome. I’m pretty sure I screwed up with some of the commands and variables. Thanks!

@amrita2605
Okay so start in ROBOTC by opening a new file and click new - > competition template. This will explain all of your where to put code questions.

Other quick things

the line with the pragmas has to be at the very top, ROBOTC is very picking about that so always make sure your code is after that.
Also wait1Msec[1000] needs to be called with parenthesis as it is a function wait1Msec(1000)

And once you get it to compile, give those motors some meaningful names. The person reading the program tomorrow (i.e. You) will thank you.

Now, looking at your program, please notice that nothing happens because a wait finished - nothing will turn off the motors for you, you need to do that. Such as:


motor[one] = 63;		// moves toward goal
motor[two]= 63;
motor[nine] = 63;
motor[ten] = 63;
wait1Msec[1000];		// duration of time for which it moves forward
motor[one] = 0;		// stop moving
motor[two]= 0;
motor[nine] = 0;
motor[ten] = 0;

To your original question, motor control values are integer, so even though the RobotC compiler (which is quite lenient in this case) will let you use float (decimal value), it will round the value down behind the scenes. Not that it matters, there’s no practical difference between setting 63 and 64, certainly less than a typical variance between two new motors, not even taking into the account motor age and overall robot build quality.

And while we’re at motor differences, I don’t think you want to mix ports 1/10 with other ports on the drivebase, search this forum for the difference. Or read this blog post by Renegade Robotics (at least the short “In Practice” paragraph).

Oh…syntax errors are the absolute worst ones to catch, thanks for your help.

Okay, I looked at the competition template and redid mine accordingly. That helped in regards to format, so thank you. Also, thanks for catching that syntax error. They’re the absolute worst because they’re the most annoying…

I looked at the post, and wow. Definitely showing that to my team so we can change things up accordingly. Also, I added in the stopping motors. That’ll probably help so that the bot isn’t just on the field, all motors running atrociously…I just have two more questions:

What do I do to fix the two following errors:


*Warning*:Unreferenced function 'pre_auton'
*Warning*:Unreferenced task 'autonomous'

And does this look right to you? I’m sure there’s a silly mistake I haven’t caught that’s going to be bothersome later in here:


task autonomous //for scoring on stationary goal in front of robot w/preload
{
	motor[one] = 63;		// moves toward goal
	motor[two]= 63;			// moves toward goal
	motor[nine] = 63;		// moves toward goal
	motor[ten] = 63;		// moves toward goal
	wait1Msec(2000);	// duration of time for which it moves forward
	motor[one] = 0;		// stop moving
	motor[two]= 0;		// stop moving
	motor[nine] = 0;	// stop moving
	motor[ten] = 0;		// stop moving
	motor[claw] = 127;		// holding preload
	motor[three] = 127;		// lifts to top capacity
	motor[four] = 127;		// lifts to top capacity
	motor[five] = 127;		// lifts to top capacity
	motor[six] = 127;			// lifts to top capacity
	wait1Msec(5000); // does everything above for 5 seconds
	motor[three] = 0;	// stop lift
	motor[four]= 0;		// stop lift
	motor[five] = 0;	// stop lift
	motor[six] = 0;		// stop lift
	motor[claw] = -127; // claw release
	motor[claw] =  0;		//claw stops
}

//may add something to bring lift down if needed (after testing)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//auton for turning right and scoring cone on mobile goal...using point turn vs. swing turn to be more precise //
/////////////////////////////////////////////////////////////////////////////////
//task autonomous //for scoring on mobile goal to side of robot
//{
//	motor[ten] = 67;		// turns to exact angle facing goal
//	motor[claw] = 100;	// keeps hold on preload
//	wait1Msec(1000);
//	motor[ten] = 0;			//stop m10 temporarily
//	motor[claw] = 100;	// keeps hold on preload
//	motor[one] = 127;		// moves toward goal
//	motor[two]= 127;		// moves toward goal
//	motor[nine] = 127;	// moves toward goal
//	motor[ten] = 127; 	// moves toward goal
//insert positioning here for turning of chassis motors after testing
//	wait1Msec(2500);
//	motor[one] = 0;		// stops moving
//	motor[two]= 0;		// stops moving
//	motor[nine] = 0;	// stops moving
//	motor[ten] = 0; 	// stops moving
//	motor[claw] = 100;	// keeps hold on preload
//	motor[three] = 67;	//goes up
//	motor[four] = 67;		//goes up
//	motor[five] = 67;		//goes up
//	motor[six] = 67;		//goes up
//	wait1Msec(2500);
//	motor[claw] = -100;
//	motor[claw] = 0;
//}

Lastly, thanks so much for your help. I appreciate it.

So that error looks like you deleted important code from the competition template, post your entire program again. Open a new unmodified competition template program and read its comments carefully, the only things you can just delete are the parts it says you can delete.

Also reading the code 2 quick comments

  1. I doubt your intake needs full power to just hold the preload in place try 20 power and see if that works. Motors will overheat if you leave them at high power and they can’t spin.

  2. Looking at your 2 version of task autonomous make me think you would benefit from reading this.
    http://www.c4learn.com/c-programming/c-multi-line-comment/