View unanswered posts | View active topics It is currently Sat May 18, 2013 9:39 pm






Reply to topic  [ 2 posts ] 
ROBOTC programming error warning 
Author Message
Rookie

Joined: Sun Oct 30, 2011 7:06 pm
Posts: 1
Post ROBOTC programming error warning
I'm writing a program for my last school assignment that is essentially a simple plotter (only doing letters at the moment), however when trying to compile the program i get the error:

"**Error**:Mixed mode (byte/short) comparison in conditional branch".

the thing is the section of the code it is reffering to is comparing a char to a byte, as far as i thought a char was considered to be a number so i'm not sure as to why this error is occuring. although i've only been coding in ROBOTC for the past week (i haven't used version of c previously either).

here is the code, the problem line is "if letters[i][0] == l"
Code:
void DrawLetter(char l){
   nMotorEncoder[motorA] = 0;
   nMotorEncoder[motorB] = 0;
   nMotorEncoder[motorC] = 0;
   bool finished = false;
   for (int i=0; i < sizeof(letters)/sizeof(letters[0][0])/6 ; i++){ //calculate the number of rows in array and cycles through them
   if (letters[i][0] == l){ 
nMotorEncoderTarget[letters[i][1]] = letters[i][2];
      motor[letters[i][1]] = letters[i][3];
      motor[letters[i][4]] = letters[i][5];
      while(nMotorRunState[letters[i][1]] != runStateIdle); //does until nMotorRunState = runStateIdle
         motor[letters[i][1]] = 0;
         motor[letters[i][4]] = 0;
         finished = true;  //returns if the letter has been reached or not
      } else if (finished) return; //exits loop if letter is completed
  }// for
}//drawLetter


any ideas as to why this is happening or how i can get around it?

here is an example of the array:
Code:
const int letters[][] = {
  {'A',1,485,-75,0,0}, // the last two are a second set of target motors and associated power levels as to make diagonal lines
  {'A',2,180,75,0,0},
  {'A',1,485,75,0,0}
};

let me know if you need any more details and any help would be greatly appreciated.


Sun Oct 30, 2011 7:22 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1023
Post Re: ROBOTC programming error warning
It sounds like you are storing different data types in your 2-dimensional int array. Since your array is declared as array of int (16-bit signed value), it is a different type from char (8-bit signed value). The compiler doesn't like comparing different types. There are two ways to fix it. The quick way is to type-cast the comparision. For example:
Code:
   if ((char)letters[i][0] == l){ 
      ...
   }

But a more correct way is to define the correct data types. It seems you need to use structure. For example:
Code:
typedef struct
{
    char letter;
    int data1;
    int data2;
    int data3;
    int data4;
    int data5;
} LETTER_DATA;

LETTER_DATA Letters[] =
{
  {'A',1,485,-75,0,0}, // the last two are a second set of target motors and associated power levels as to make diagonal lines
  {'A',2,180,75,0,0},
  {'A',1,485,75,0,0}
}

Since I don't know what those numbers are for, I just named them dataX. You should give it more descriptive names.


Mon Oct 31, 2011 3:36 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.