View unanswered posts | View active topics It is currently Fri Mar 06, 2015 10:07 am

Reply to topic  [ 3 posts ] 
Odd Error: Parenthesis 
Author Message
User avatar

Joined: Sat Jul 10, 2010 3:06 pm
Posts: 86
Location: Roanoke, VA
Post 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:
cumulativeError =  (cumulativeError * (1 / 6)) + error;

**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:
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).
  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;

    //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(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.

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

Check out my website!

VRC Team 2190

Twitter: @RoboDesigners
Sat Dec 29, 2012 2:26 pm
Profile WWW
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 663
Post 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

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.

Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody

Wed Jan 02, 2013 11:33 am
User avatar

Joined: Sat Jul 10, 2010 3:06 pm
Posts: 86
Location: Roanoke, VA
Post 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.


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

Check out my website!

VRC Team 2190

Twitter: @RoboDesigners

Wed Jan 02, 2013 11:59 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 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.