Go Down

Topic: Converting to double or float from custom type (Read 173 times) previous topic - next topic

salVatoRe1234

Hello everyone,

for a university project I need to develop a device which supports AHRS. I have found out that there is this library

 https://forum.pololu.com/t/state-of-the-art-ahrs-for-25/8091

which is working perfectly on my Arduino Mega 2560 and MPU9150 IMU.

My objective, though, is to compare the yaw angle of different devices simultaneously on a common third party controller, so I need to pass information to the latter in a "standard format".

I have tried to figure out how to extract the only information I need, which in this case would be the yaw value, by attempting to figure out what variable of what type contains the data.

I have come to the conclusion that, being these "custom" types, it's impossible to simply cast the vector which is created at line 113 in the "ArduinoIMU" code included in the GitHub code (sorry I don't know how to embed code)

RTMath::displayRollPitchYaw({}, (RTVector3&)fusion.getFusionPose());

since no conversion from (RTVector3&) to other types is defined.

Has anyone ever tried and succeded in such a task?

jremington

#1
Jul 11, 2019, 10:13 pm Last Edit: Jul 11, 2019, 10:18 pm by jremington
Quote
since no conversion from (RTVector3&) to other types is defined.
RTVector3 is just a class defining a structure with 3 double/float values, so I don't understand the problem. Why would you want to "convert" it to something else?

Take a look at how the results are printed by the library. Here is the library code:

Code: [Select]
void RTMath::displayRollPitchYaw(const char *label, RTVector3& vec)
{
    Serial.print(label);
    Serial.print(" roll:"); Serial.print(vec.x() * RTMATH_RAD_TO_DEGREE);
    Serial.print(" pitch:"); Serial.print(vec.y() * RTMATH_RAD_TO_DEGREE);
    Serial.print(" yaw:"); Serial.print(vec.z() * RTMATH_RAD_TO_DEGREE);
}


For instructions on how to use this forum (including how to post code), see the "How to use this forum" post.

salVatoRe1234

Thank you for the quick reply. I'd like to convert it to double or int in order to map the value to a PWM pin to obtain a voltage as output, which can be read by the controller I cited in the first post.

I'll check the link you provided to learn how to post properly.

salVatoRe1234

Ok I have found the section in the library where RTFLOAT is defined as double or float depending on what is set. So, instead of casting RTVector3 to other types, would it be easier to modify other libraries to accept this format?

jremington

#4
Jul 11, 2019, 11:26 pm Last Edit: Jul 11, 2019, 11:26 pm by jremington
How do you plan to get the yaw value from the Arduino?

If you are using Serial.print(), simply modify the display function to print only the yaw value.

On the standard Arduino, double is exactly the same as float (32 bits).

salVatoRe1234

My idea was to let most of the code provided on GitHub intact, and modify it slightly as follows. Get the yaw angle stored in a variable which is a "standard" double or float (not a RTFLOAT), convert it to int in order to pass it to the Arduino function map and finally use this value to write to e.g. pin 11 with  analogWrite. I will then connect this pin to my controller. 
The controller I am using is equipped with a 67-pin board (both analog and digital I/O) so this is why I am trying to get the yaw angle value mapped to a voltage. With third party program I can convert the obtained voltage back to radians or degrees originally provided by the Arduino code.

jremington

#6
Jul 12, 2019, 02:36 am Last Edit: Jul 12, 2019, 02:38 am by jremington
In RTMath::displayRollPitchYaw(const char *label, RTVector3& vec)

Instead of or in addition to this line:
Code: [Select]
    Serial.print(" yaw:"); Serial.print(vec.z() * RTMATH_RAD_TO_DEGREE);
write
Code: [Select]
float yaw = vec.z() * RTMATH_RAD_TO_DEGREE;
and do anything you want with "yaw".

salVatoRe1234

Thank you very much for your help. This has solved the task.

GolamMostafa

On the standard Arduino, double is exactly the same as float (32 bits).
Does standard Arduino include Arduino DUE?

Delta_G

Does standard Arduino include Arduino DUE?
When someone says "Standard arduino" they usually mean the UNO / Nano / Mega varieties. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

GolamMostafa

When someone says "Standard arduino" they usually mean the UNO / Nano / Mega varieties. 
+.

Go Up