View unanswered posts | View active topics It is currently Mon Apr 22, 2019 6:52 am






Reply to topic  [ 3 posts ] 
Datalogging float variables? 
Author Message
Rookie

Joined: Wed Jan 21, 2009 12:38 pm
Posts: 11
Location: South Carolina USA
Post Datalogging float variables?
I am evaluating a trial copy of RobotC and am presently checking out the datalogging features. I have not been successful in using the AddToDatalog function for a float variable. The sample programs I have found give examples for integers, but when I substituted a float variable a compilation error was returned.

Can float values be datalogged? If not, what alternate procedures would be recommended?

Thank you.


Wed Jan 21, 2009 1:18 pm
Profile
Rookie

Joined: Fri Feb 16, 2007 4:11 pm
Posts: 41
Location: Padanaram, MA
Post Re: Datalogging float variables?
Hi Jacket60,

Apparently, only integer values can be datalogged,. I got around this myself by writing a little function which datalogs an equivalent integer and exponent. I'll show my function below. Feel free to use it or any modification of it if you want to.

Code:
void AddFloatToDatalog(float &variable)
{
   int sign;
   bool more;
   float tempVar;      // Define this to aid in debugging
   int tempExp;        // Define this to aid in debugging
   tempVar = variable;
   if(variable == 0)
   {
      value = 0;
      exponent = 0;
      return;
   }
   if(variable < 0)
   {
     sign = -1;
     tempVar = - tempVar;
  }
   else
   {
      sign = 1;
   }
   tempExp = 0;
   more = true;
   if(tempVar < 1)
   {
      do
      {
         if(tempVar < 3200)
         {
            tempVar = tempVar * 10;
            tempExp = tempExp - 1;
         }
         else more = false;
      }
      while (more);
   }
   else
   {
      while (tempVar > 32000)
      {
         tempVar = tempVar / 10;
         tempExp = tempExp + 1;
      }
   }
   if (sign == -1) value = - tempVar;
   else value = tempVar;
   exponent = tempExp;
   AddToDatalog(value);
   AddToDatalog(exponent);
}



Also, you might want to look at my topic "Problem compiling AddToDatalog statements" if you get some strange compiler errors using the datalog.

Regards,

Ted


Thu Jan 22, 2009 4:03 pm
Profile WWW
Rookie

Joined: Wed Jan 21, 2009 12:38 pm
Posts: 11
Location: South Carolina USA
Post Re: Datalogging float variables?
Thanks for your response to my query. I didn't want to have to start getting around the problem unless it was necessary. Except for the documentation, I'm very pleased with ROBOTC. I've used MATLAB Simulink (before retiring) and accordingly was intrigued with the NXT-G concept (which I think is terrific - what a great way to learn programming). However, for the kinds of projects I'd like to work on, I'd rather use ROBOTC.

Also, thanks for your routine which I plan to use.


Fri Jan 23, 2009 1:30 pm
Profile
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.