ROBOTC.net forums
http://robotc.net/forums/

Help with my program please.
http://robotc.net/forums/viewtopic.php?f=15&t=4615
Page 1 of 1

Author:  Mike Man [ Sun Jun 10, 2012 5:58 pm ]
Post subject:  Help with my program please.

This is turning into the longest program I've written by myself, as a beginner programmer I'm having some difficulties with the syntax and compiling the program. If anyone could suggest ways to fix my program please let me know. Below is the program I have right now.

Code:
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, dgtl1,  limitswitch,    sensorTouch)
#pragma config(Sensor, dgtl2,  sonarSensor,    sensorSONAR_cm)
#pragma config(Sensor, I2C_1,  rightEncoder,   sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_2,  leftEncoder,    sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Motor,  port2,           rightMotor,    tmotorVex393, openLoop)
#pragma config(Motor,  port3,           leftMotor,     tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port8,           armMotor,      tmotorVex393, openLoop)
#pragma config(Motor,  port9,           clawMotor,     tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

void moveStraight()
{
  if(SensorValue[leftEncoder] > SensorValue[rightEncoder]
  {
    motor[rightMotor] = 63;
    motor[leftMotor] = 50;
  }
  if(SensorValue[rightEncoder] > SensorValue[leftEncoder])
  {
    motor[rightMotor] = 50;
    motor[leftMotor] = 63;
 
  if(SensorValue[leftEncoder] == SensorValue[rightEncoder])
  {
    motor[rightMotor] = 63;
    motor[leftMotor] = 63:
  }


void grab()
{
  if (limitswitch == 1)
  {
    motor[clawMotor] = 27;
    wait1Msec(500);
  }
     while(SensorValue(sonarSensor) > 20  || SensorValue(sonarSensor) == -1)
      motor[rightMotor] = 63;
      motor[leftMotor]  = 63;
   }


void drop()
{
  motor[armMotor] = 127;
  wait1Msec(5000);
     while(SensorValue(sonarSensor) > 10  || SensorValue(sonarSensor) == -1)
  {
    motor[rightMotor] = 63;
      motor[leftMotor]  = 63;
   }
   motor[clawMotor] = -127;
   wait1Msec(500)
}

task main()
{

SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder] = 0;

  while( limitswitch == 0 )
  {
    moveStraight();
  }
 
else
  clawMotor = 127;
}


Here are error messages I'm receiving.

File "RobotMaze6-5-12.c" compiled on Jun 10 2012 16:43:38
15: *Warning*:expecting '[' and found '{'. Typing error assumed and '[' used.
16: *Warning*:Assignment '=' embedded in expression
16: **Error**:Missing ']' before ';'
20: **Error**:Ummatched left brace '{'
27: *Warning*:':' found instead of ';'. Typing error?
31: **Error**:Functions must be defined at main scope level
31: *Warning*:Unreferenced function 'grab'
33: *Warning*:Mismatched typedefs. Converting typedef 'short' to typedef 'tSensors', value 'in2'
44: **Error**:Functions must be defined at main scope level
44: *Warning*:Unreferenced function 'drop'
54: *Warning*:';' expected before '}'. Automatically inserted by compiler
57: **Error**:Task 'main' is not defined at global scope level
57: **Error**:Tasks must be defined at main scope level
63: *Warning*:Mismatched typedefs. Converting typedef 'short' to typedef 'tSensors', value 'in1'
68: **Error**:Unexpected 'else'. Ignored.
69: **Error**:Unexpected scanner token-> 'clawMotor'
69: **Error**:Unexpected scanner token-> '='
69: **Error**:Unexpected scanner token-> '127'
70: **Error**:Expected->'}'. Found 'EOF'
70: **Error**:Executable statements not valid in 'main' declaration block

Thanks again to anyone who is willing to help!

Author:  Spiked3 [ Sun Jun 10, 2012 7:21 pm ]
Post subject:  Re: Help with my program please.

Just a quick note;

you should select all your code (ctrl-a)
then apply formatting to it (ctrl-alt-F)

this will help you see where your braces might not line up. When I did this with your code,
I immediately noticed that the first function, moveStraight, probably did not close as you expected it to.

That will help get you started.

Author:  Coder A [ Thu Jan 03, 2013 5:17 pm ]
Post subject:  Re: Help with my program please.

//Copy and paste this into your robotc interface. I don't have the vex system, so I could'nt
//help with that, but it fixes all the other errors. Mainly, you just left out end braces.
//Also, try to keep your code aligned by using the tab key or smart indexing.
//Other than that, you understand the basics of the language very well.

#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, dgtl1, limitswitch, sensorTouch)
#pragma config(Sensor, dgtl2, sonarSensor, sensorSONAR_cm)
#pragma config(Sensor, I2C_1, rightEncoder, sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_2, leftEncoder, sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port2, rightMotor, tmotorVex393, openLoop)
#pragma config(Motor, port3, leftMotor, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port8, armMotor, tmotorVex393, openLoop)
#pragma config(Motor, port9, clawMotor, tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

void moveStraight()
{
if(SensorValue[leftEncoder] > SensorValue[rightEncoder])
{
motor[rightMotor] = 63;
motor[leftMotor] = 50;
}
if(SensorValue[rightEncoder] > SensorValue[leftEncoder])
{
motor[rightMotor] = 50;
motor[leftMotor] = 63;
}
if(SensorValue[leftEncoder] == SensorValue[rightEncoder])
{
motor[rightMotor] = 63;
motor[leftMotor] = 63;
}
}


void grab()
{
if (limitswitch == 1)
{
motor[clawMotor] = 27;
wait1Msec(500);
}
while(SensorValue(sonarSensor) > 20 || SensorValue(sonarSensor) == -1)
{
motor[rightMotor] = 63;
motor[leftMotor] = 63;
}
}


void drop()
{
motor[armMotor] = 127;
wait1Msec(5000);
while(SensorValue(sonarSensor) > 10 || SensorValue(sonarSensor) == -1)
{
motor[rightMotor] = 63;
motor[leftMotor] = 63;
}
motor[clawMotor] = -127;
wait1Msec(500);
}

task main()
{
SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder] = 0;

while( limitswitch == 0 )
{
moveStraight();
}[color=#BF0040][color=#BF0040][color=#BF0040]
[/color][/color]
//else
//clawMotor = 127; // I don't know why you put this here. Else statements must follow if statements.
}



// I hope this helps! //[/color]

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/