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

Arm and Limit Switch Project Not Working Correctly
http://robotc.net/forums/viewtopic.php?f=11&t=4529
Page 1 of 1

Author:  Mike Man [ Sun May 13, 2012 6:39 pm ]
Post subject:  Arm and Limit Switch Project Not Working Correctly

The idea here is to have my arm lift to the top, hit the limit switch, and then swing down. Once it hits the bottom limit switch, it goes back up and repeats.

Can anyone tell what's wrong? It won't compile.

Here is my current program, and the error messages below it; any help would be appreciated.
Code:
task main()
{
   while(1 == 1)
   
{
  if (SensorValue[touchSensor1]==1) && (SensorValue[touchSensor2]==0) || (SensorValue[touchSensor1]==0) && (SensorValue[touchSensor2]==0);
  motor[Arm] = -20;

else if(SensorValue[touchSensor1] == 0) && (SensorValue[touchSensor2]==1) || (SensorValue[touchSensor1] == 0) && (SensorValue[touchSensor2] ==0);
  motor[Arm] = 20;
}

}


Here are the error messages I receive when attempting to compile. First 6 error messages are for the first if statement, and the rest are for the second.

File "ArmTrials5-13-12.c" compiled on May 13 2012 17:31:15
**Error**:Unexpected scanner token-> '&&'
**Error**:Unexpected scanner token-> '('
**Error**:Missing ';' before ')'
**Error**:Unexpected scanner token-> ')'
**Error**:Unexpected scanner token-> '||'
*Warning*:Meaningless statement. Did you mean '=' instead of '=='?
**Error**:Unexpected 'else'. Ignored.
**Error**:Unexpected scanner token-> 'if'
**Error**:Unexpected scanner token-> '('
**Error**:Missing ';' before ')'
**Error**:Unexpected scanner token-> ')'
**Error**:Unexpected scanner token-> '&&'
**Error**:Unexpected scanner token-> '||'
*Warning*:Meaningless statement. Did you mean '=' instead of '=='?

Author:  magicode [ Sun May 13, 2012 8:25 pm ]
Post subject:  Re: Arm and Limit Switch Project Not Working Correctly

The errors are occurring because your syntax is incorrect. Here is the syntax that will make those errors go away:
(P.S. next time you post code, please put it in "code" tags)

Code:
task main()
{
  while(1 == 1)   
  {
    if((SensorValue[touchSensor1]==1) && (SensorValue[touchSensor2]==0) || (SensorValue[touchSensor1]==0) && (SensorValue[touchSensor2]==0))
    {
      motor[Arm] = -20;
    }
    else if((SensorValue[touchSensor1] == 0) && (SensorValue[touchSensor2]==1) || (SensorValue[touchSensor1] == 0) && (SensorValue[touchSensor2] == 0))
    {
      motor[Arm] = 20;
    }
  }
}

You need parentheses around the condition in the if statement, and there can't be a semicolon at the end if you want it do actually do anything. You might want to look at some C syntax for the basics, and ROBOTC has some great tutorials here: http://www.robotc.net/education/curriculum/vex/
That takes care of making it compile, but whether it does what you want it to do is a different story.

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