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

Odd Error: Parenthesis
http://robotc.net/forums/viewtopic.php?f=11&t=5309
Page 1 of 1

Author:  RoboDesigners [ Sat Dec 29, 2012 2:26 pm ]
Post subject:  Odd Error: Parenthesis

I was reviewing my code from last year's competition robot, and noticed that it is now throwing an error with this expression:
Code:
cumulativeError =  (cumulativeError * (1 / 6)) + error;

Quote:
**Error**:expression 'cumulativeError' is not constant


I was confused by this, as it was not throwing an error in April when I last opened the file.

I tried re-writing the line, and found that removing the parenthesis makes the error go away:
Code:
cumulativeError = cumulativeError * 1 / 6 + error;


Is this a bug in ROBOTC, or is it just something obvious I am overlooking?

Below is the task this line was contained in. I have also attached the entire file (lines 106 and 107 are where the issue is).
Code:
/**
  This task controls the arm up/down motion, listening for commands
*/
task armControl(){
  //Is the arm under computer control?
  bool compControl = true;
  int cumulativeError = 0;

  while(true){
    //Update arm target
     if (vexRT[Btn7U] == 1)
        armTargetLevel = 3;
      else if(vexRT[Btn7R] == 1)
        armTargetLevel = 2;
      else if(vexRT[Btn7L] == 1)
        armTargetLevel = 1;
      else if(vexRT[Btn7D] == 1)
        armTargetLevel = 0;

    //Power arm
    if (compControl){
      int error = ARM_POS[armTargetLevel] - SensorValue[armPot];
      cumulativeError = (cumulativeError * (1 / 6)) + error;
      int power = -(error * 0.09 + cumulativeError * 0.052);
     
      if (abs(power) > ARM_MAX_POW)
        power = ARM_MAX_POW * abs(power) / power;

      driveArm(power);
    }
    else{
      driveArm(vexRT[Ch3]); //Human control
      cumulativeError = 0;
    }

    //Ch3 joystick stops auto-arm control, pressing a button re-initiates it
         if(vexRT[Ch3] > 10 || vexRT[Ch3] < -10)
           compControl = false;
         if((vexRT[Btn7D] == 1) || (vexRT[Btn7U] == 1) || (vexRT[Btn7R] == 1) || (vexRT[Btn7L] == 1))
           compControl = true;


    wait1Msec(10); //Multi-threading wait
  }
}


See line 106 and 107 in the attached file.

Attachments:
File comment: Drive Program
MainDrive.c [10.12 KiB]
Downloaded 369 times

Author:  JohnWatson [ Wed Jan 02, 2013 11:33 am ]
Post subject:  Re: Odd Error: Parenthesis

This is a minor bug in ROBOTC that will be fixed release. The reason this error is popping up is because you are multiplying an integer (cumulativeError) by a decimal/fraction (1/6, or 0.1667). Before the multiplication occurs the decimal number is rounded off to an integer number, in this case 0. Since you are multiplying by 0, the expression then becomes

Code:
cumulativeError =  (cumulativeError * (0)) + error;

or more simply

cumulativeError =  error;


This code will compile and run correctly; the error message will be fixed in the next beta release which should be out soon.

Author:  RoboDesigners [ Wed Jan 02, 2013 11:59 am ]
Post subject:  Re: Odd Error: Parenthesis

Huh. That's interesting to note. It makes me now wonder why my code worked so well during the competition... :lol:

Thank you very much.

//Andrew

P.S. I like your signature... ;)

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