Can someone give an example of their teleop.c code. I have read the posts and unable to get a pwm to control a motor. When I add the code to the function it will not compile. Would someone adopt us and walk us through it? We are a rookie team and learning to use MPlab 8.0 and MCC18 3.10. Also how do we verify MCC18 version?
Your question is too generic. We’ll need to see your code to help. Does the project build before you insert your changes? Where are your motors hooked up? And on and on and on… ;o)
If you call the Default_Routine function from Teleop function, your robot will run the FIRST default code.
HTH
Not sure what your setup is, but just open up teleop.c and go to the teleop function. If your speed controller is connected to pwm01, just put this one line of code in:
pwm01 = p1_y;
This assumes that you have a joystick connected to port 1 on the operator inferface.
The project did build but as soon as I added pwm01 = p1_y; It would not build as shown below.
void Teleop(void)
{
pwm01 = p1_y;
// example code to test your gyro and encoder(s)
long Encoder_Count;
static unsigned int i = 0;
static unsigned int j = 0;
int temp_gyro_rate;
long temp_gyro_angle;
int temp_gyro_bias;
i++;
j++; // this will rollover every ~1000 seconds
// enable this block of code to test your gyro
if(j == 10)
{
printf("
Calculating Gyro Bias…
");
}
if(j == 38) // let the gyro stablize for a second before starting a calibration
{
// start a gyro bias calculation
Start_Gyro_Bias_Calc();
}
if(j == 191) // allow calibration routine to run for four seconds
{
// terminate the gyro bias calculation
Stop_Gyro_Bias_Calc();
// reset the gyro heading angle
Reset_Gyro_Angle();
temp_gyro_bias = Get_Gyro_Bias();
printf("Gyro Bias=%d
“, temp_gyro_bias);
}
if(i == 35 && j >= 191)
{
temp_gyro_rate = Get_Gyro_Rate();
temp_gyro_angle = Get_Gyro_Angle();
printf(” Gyro Rate=%d
", temp_gyro_rate);
printf("Gyro Angle=%d
", (int)temp_gyro_angle);
}
/*
// enable this block of code to test your encoder(s)
if(i == 37 && j >= 191)
{
Encoder_Count = Get_Encoder_1_Count();
printf("E1=%d
",(int)Encoder_Count);
Encoder_Count = Get_Encoder_2_Count();
printf("E2=%d
",(int)Encoder_Count);
Encoder_Count = Get_Encoder_3_Count();
printf("E3=%d
",(int)Encoder_Count);
Encoder_Count = Get_Encoder_4_Count();
printf("E4=%d
",(int)Encoder_Count);
Encoder_Count = Get_Encoder_5_Count();
printf("E5=%d
",(int)Encoder_Count);
Encoder_Count = Get_Encoder_6_Count();
printf("E6=%d
",(int)Encoder_Count);
}
*/
// reset the loop counter
if(i >= 38)
{
i = 0;
}
// enable this to use IFI's default robot code
// Default_Routine(); // located in ifi_code.c
// update the state of the LEDs on the operator interface
Update_OI_LEDs(); // located in ifi_code.c
}
You need to put it AFTER your declarations. Put it after this line:
int temp_gyro_bias;
In C, you have to put your code after all variable declarations. If you move pwm01 = p1_y; to the end of this block, it will compile.
Thanks for the help we’ll try that please check back as I’m sure we’ll have more questions