View unanswered posts | View active topics It is currently Sat Aug 23, 2014 11:21 am






Reply to topic  [ 3 posts ] 
Help with my program please. 
Author Message
Rookie
User avatar

Joined: Tue May 01, 2012 9:55 pm
Posts: 3
Post 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!


Sun Jun 10, 2012 5:58 pm
Profile
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post 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.

_________________
Mike aka Spiked3
http://www.spiked3.com


Sun Jun 10, 2012 7:21 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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]

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Thu Jan 03, 2013 5:17 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.