View unanswered posts | View active topics It is currently Sat Oct 25, 2014 11:18 am






Reply to topic  [ 4 posts ] 
Problems with Mindsensors 
Author Message
Rookie

Joined: Mon Oct 20, 2008 12:49 pm
Posts: 6
Post Problems with Mindsensors
Hi!

I'm in serious need of help with my new Mindstorms sensors. I actually managed to get the right g-values out of the Mindsensors accelometer but the angles still come out wrong. When I read the G-value I need to do the following to get it right:
accel =(MostSigByte<<8)|(0xff&LeastSigByte);

That is something I don't understand even though I have programmed with C for a quite long time now: if raw_val is a byte how come 'bitwise and' with 0xff does any difference. It's like 1=1 if you know what I mean..

I have a hunch that this has something to do with the fact that RobotC doesn't support usigned variables...

The real problem is that when I try to read the 1 byte readings of the angles I'm not able to do the conversion anymore: If I try to make it like I would with assembly it gets even sillier: angle=(raw^0xff)+1;

So I'm pretty much lost here. Thanks in advance for help. Also, I would like to understand how it happens in theory (on bit level) not only have the working code.

Sami F.


Mon Oct 20, 2008 4:00 pm
Profile
Rookie

Joined: Mon Oct 20, 2008 12:49 pm
Posts: 6
Post Re: Problems with Mindsensors
Ok. Let me clarify a little: (I was a little tired when I first started this topic :wink: )

So. I'm trying to read a single byte from the Mindsensors Accelometer v3. If I just print it straight a way it comes out as value ranging from -128 to -65 OR 63 to 127.

What I think that happens is that the value is sent to NXT as an unsigned byte and RobotC assumes that it's a signed byte. For some reason, however, I'm not able to convert it to signed properly which I managed to do with the 2 byte values (since they are sent over to NXT as signed already). I assumed that RobotC is using the most significant bit as the sing (since there is no documentation on this)..

Here is the function with which I retreive the angle data (actually direct snippet from the sample code made by Minsensors.com but it still won't work):

Code:
byte  Get_Tilt(byte axis)
{
   byte acclMsg[5];
   const byte kMsgSize         = 0;
   const byte kAcclAddress     = 1;
   const byte kReadAddress     = 2;

   // Build the I2C message
   acclMsg[kMsgSize]           = 3;
   acclMsg[kAcclAddress]       = kAcclID ;
   acclMsg[kReadAddress]       = axis ;
 
   replyMsg[0] = 0;
   replyMsg[1] = 0;
 
   while (nI2CStatus[kAcclPort] == STAT_COMM_PENDING)
   {
       wait1Msec(1);
   }
   
   sendI2CMsg(kAcclPort, acclMsg[0], 1);
   // when the I2C bus is ready, send the message you built
 
   while (nI2CStatus[kAcclPort] == STAT_COMM_PENDING)
   {
       wait1Msec(1);
   }
 
   readI2CReply(kAcclPort, replyMsg[0], 1);
   
   return(replyMsg[0]);
}


I also tested the sensor on NXC and every single reading came up ok _without_ any conversions. This is something that the RobotC developer team should note.....

PS. IMHO there should be a FAQ for reading 3rd party sensors. Having one would make peoples lives so much easier.


Tue Oct 21, 2008 11:01 am
Profile
Expert
User avatar

Joined: Fri Nov 09, 2007 4:51 am
Posts: 121
Location: Hungary, Europe
Post Re: Problems with Mindsensors
Hi Staffer,

There are dozens of sample programs attached to RobotC. Do not they contain necessary examples?
I have Hitechnic accelero and gyro sensors, and used them correctly (however mindsensors might have
designed different interface).

eL


Tue Oct 21, 2008 9:49 pm
Profile
Rookie

Joined: Mon Oct 20, 2008 12:49 pm
Posts: 6
Post Re: Problems with Mindsensors
elemes wrote:
Hi Staffer,

There are dozens of sample programs attached to RobotC. Do not they contain necessary examples?
I have Hitechnic accelero and gyro sensors, and used them correctly (however mindsensors might have
designed different interface).

eL


-Hi!

There aren't any examples made for Mindsensors' sensors in RobotC samples and all the "try me" stuff is made for HiTechnic sensors (and yes, mindsensors' sensors have different kind of registers). BUT I think that I managed to solve the problems (actually with little help from Mindsensors' kind customer support):

The thnig is that RobotC doesn't actually have even bytes or ubytes (along with the missing unsigned variables). Bytes in RobotC are ints of which only one byte is used. I feel like I've been lied to! :evil: It's really annoying when the progamming language does something else than you'd expect it to do. (Why to enable bytes and ubytes in the first place if they're not fully supported anyways!?) It would have saved me many hours of time if there hadn't been this problem with bytes (or bytes at all)..

So, in order to move a byte out of an array correctly you have to do bitwise operations (byte integer_really=0xff & somebytes[0];). If only this had been documented! :evil: Two scores atleast for NXC.....

Sami F.


Wed Oct 22, 2008 9:54 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: frogsam5, hexafraction 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.