Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Using atan2 on the cRIO (http://www.chiefdelphi.com/forums/showthread.php?t=126674)

William Kunkel 02-17-2014 05:11 PM

Using atan2 on the cRIO
 
Whenever I try to use the atan2 function by including <cmath>, I can compile, but I get "no robot code" and netconsole gives the message "Warning: module 0x26eaa80 (FRC_UserProgram.out) holds reference to undefined symbol atan2f." If I use std::atan2 or atan2f, or even just try atan, the same error occurs. I've also tried using <math.h> instead of <cmath>. All compile, but none are defined. Does the cRIO not have trig functions in its c++ library, or am I doing something wrong?

Joe Hershberger 02-18-2014 01:23 AM

Re: Using atan2 on the cRIO
 
Quote:

Originally Posted by MaraschinoPanda (Post 1344727)
Whenever I try to use the atan2 function by including <cmath>, I can compile, but I get "no robot code" and netconsole gives the message "Warning: module 0x26eaa80 (FRC_UserProgram.out) holds reference to undefined symbol atan2f." If I use std::atan2 or atan2f, or even just try atan, the same error occurs. I've also tried using <math.h> instead of <cmath>. All compile, but none are defined. Does the cRIO not have trig functions in its c++ library, or am I doing something wrong?

I think the problem is not the header you are including, but the library that is not loaded. It is possible that the function is not compiled in, but that would surprise me a bit. Perhaps there is a separate library that needs to be loaded.

DjScribbles 02-19-2014 01:15 PM

Re: Using atan2 on the cRIO
 
#include "Math.h" is likely what you are looking for

virtuald 02-19-2014 05:05 PM

Re: Using atan2 on the cRIO
 
Quote:

Originally Posted by Joe Hershberger (Post 1345028)
I think the problem is not the header you are including, but the library that is not loaded. It is possible that the function is not compiled in, but that would surprise me a bit. Perhaps there is a separate library that needs to be loaded.

Yep. On a normal *nix machine, you have to add -lm to your link command to use the math library. I expect this is the same thing in Wind River.

William Kunkel 02-20-2014 06:14 PM

Re: Using atan2 on the cRIO
 
Huh, I was unaware of that. I'm surprised I haven't come across this before.

wireties 02-20-2014 08:05 PM

Re: Using atan2 on the cRIO
 
Quote:

Originally Posted by virtuald (Post 1346375)
Yep. On a normal *nix machine, you have to add -lm to your link command to use the math library. I expect this is the same thing in Wind River.

That would not be true in this case. The .out file we load on the robots is a relocatable object that is dynamically loaded and linked into the VxWorks kernel space. So it works like adding a kernel module in Linux, not like an executable and library in user space. It would be true if we used real-time processes (RTPs) in VxWorks which are much like processes in Linux but we don't. I think support for them is not included in the kernel we are provided.

Are you sure it is atan2 that is not being resolved? It should be there. The OS image includes the GNU math libraries and we have used atan2 before in field-centric driver algorithms.

Good luck!

Ether 02-20-2014 09:41 PM

Re: Using atan2 on the cRIO
 
Quote:

Originally Posted by MaraschinoPanda (Post 1344727)
Whenever I try to use the atan2 function by including <cmath>, I can compile, but I get "no robot code"...

If you still haven't been able to get the library atan2 function to work, and you need something to tide you over until you can get it figured out, here's a simple C code implementation that's good to within 1/10 of a degree.



taichichuan 02-22-2014 09:15 AM

Re: Using atan2 on the cRIO
 
Hmm... We used the atan2 function in the 2010 bot with no problems. A quick check on the bot shows both an atan and an atan2 in the symbol table. From the netconsole prompt:
-> lkup "atan"
atan 0x000b5218 text
atan2 0x000b542c text

The actual addresses are not important. But the "text" shows that there are funtions out there with the names shown.

Make sure that you include math.h and reference the function as "atan2" not "atan2f". WRS has the double precision version of the function on the bot.

HTH,

Mike

jrw 05-29-2014 01:20 AM

Re: Using atan2 on the cRIO
 
For anyone hitting the same obscure problem here is the answer.

I note from the github repo of the OP's code that they are using the C++11 toolchain from FirstForge. We haven't used the original toolchain, only the C++11 toolchain too, so it might only affect those teams using this.

Anyway, the problem is that the compiler substitutes the float version of trig functions if it thinks you don't need the extra precision.
If you have:
Code:

float f = atan2(float x, float y)
then the compiler will substitute this for the atan2f function, and this is not on board the cRIO.

Change your code to:
Code:

double d = atan2(double x, double y)
and it will be plain sailing. Even casting the floats to doubles as you call the function will work.


All times are GMT -5. The time now is 04:11 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi