Shop OBEX P1 Docs P2 Docs Learn Events
Atan and Atan2 problem comiling — Parallax Forums

Atan and Atan2 problem comiling

AnubispodAnubispod Posts: 42
edited 2013-03-27 09:04 in Propeller 1
Hi i try to use atan and atan2 in my code.

here is of what i have :
void sensfusion6GetEulerRPY(float* roll, float* pitch, float* yaw) {
   float gx, gy, gz; // estimated gravity direction
    gx = 2 * (q1*q3 - q0*q2);
   gy = 2 * (q0*q1 + q2*q3);
   gz = q0*q0 - q1*q1 - q2*q2 + q3*q3;
    *yaw = atan2(2*q1*q2 - 2*q0*q3, 2*q0*q0 + 2*q1*q1 - 1) * 180 / M_PI;
   *pitch = atan(gx / sqrt(gy*gy + gz*gz)) * 180 / M_PI;
   *roll = atan(gy / sqrt(gx*gx + gz*gz)) * 180 / M_PI;
 }



and that is what he gives me in the compiler
Project Directory: C:/Users/R2D2/Documents/SimpleIDE/testme/  propeller-elf-gcc.exe -o a.out -Os -mxmmc -I . -m32bit-doubles -fno-exceptions -Dprintf=__simple_printf Motor_led_Driver.h Motor_led_Driver.c MPU6050_XS.c MPU6050_XS.h Filter.h Filter.c testme.h pid.h pid.c controller.h controller.c sensfusion6.h sensfusion6.c testme.c
 C:\Users\R2D2\AppData\Local\Temp\ccQFPoVi.o: In function `_sensfusion6GetEulerRPY':
  (.text+0xd08): undefined reference to `_atan2'
  C:\Users\R2D2\AppData\Local\Temp\ccQFPoVi.o: In function `_sensfusion6GetEulerRPY':
  (.text+0xd68): undefined reference to `_sqrt'
  C:\Users\R2D2\AppData\Local\Temp\ccQFPoVi.o: In function `_sensfusion6GetEulerRPY':
  (.text+0xd84): undefined reference to `_atan'
  C:\Users\R2D2\AppData\Local\Temp\ccQFPoVi.o: In function `_sensfusion6GetEulerRPY':
  (.text+0xdd0): undefined reference to `_sqrt'
  C:\Users\R2D2\AppData\Local\Temp\ccQFPoVi.o: In function `_sensfusion6GetEulerRPY':
  (.text+0xde8): undefined reference to `_atan'
  collect2: ld returned 1 exit status
  Done. Build Failed!
  Check source for bad function call or global variable name `_atan2'
  C:\Users\R2D2\AppData\Local\Temp\ccQFPoVi.o: In function `_sensfusion6GetEulerRPY':
  (.text+0xd68): 

i hope some one knows :)

Best regards
Oliver .R

Comments

  • KyeKye Posts: 2,200
    edited 2013-03-24 10:52
    Did you include math.h?
  • AnubispodAnubispod Posts: 42
    edited 2013-03-24 10:59
    yes i did, like you can see the defined M_PI works from the math.h just not the rest ...????
  • jazzedjazzed Posts: 11,803
    edited 2013-03-24 11:22
    Also need to check "Math Lib" in the Project Manager -> Linker tab.
  • AnubispodAnubispod Posts: 42
    edited 2013-03-24 11:34
    ok that reduced the errors to this :)
    Project Directory: C:/Users/R2D2/Documents/SimpleIDE/testme/  propeller-elf-gcc.exe -o a.out -Os -mlmm -I . -m32bit-doubles -fno-exceptions -Dprintf=__simple_printf Motor_led_Driver.h Motor_led_Driver.c MPU6050_XS.c MPU6050_XS.h Filter.h Filter.c testme.h pid.h pid.c controller.h controller.c sensfusion6.h sensfusion6.c testme.c -lm
     c:/propgcc/bin/../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld.exe: region `hub' overflowed by 3696 bytes
      (.text+0xd84): undefined reference to `_atan'
      (.text+0xde8): undefined reference to `_atan'
      Done. Build Failed!
      Check source for bad function call or global variable name `_atan'
      (.text+0xde8): 
     
    
    

    is this due to not enoughf mem or i am missing some ?? i use a protoboard usb with LMM if its due to lack of mem i have read some about cmm mode but its not in the list of simple ide ??
  • AnubispodAnubispod Posts: 42
    edited 2013-03-24 12:29
    Ok i figured it , i had to link the math lib directly in simple ide, but is there a way to make the math lib smaller so it includes only the used functions
    ??? I reached the 32K in lmm , and that sucks since i need more code there and as fast as lmm is , xmm with my epprom is to slow.
    Would be sram or 1 MB SPI Flash memory faster the the upper 32k of the epprom ??
    If not i would have to go with a diffrent mcu for my hexacopter design.
    Best regards Oliver
  • ersmithersmith Posts: 6,054
    edited 2013-03-24 12:51
    Anubispod wrote: »
    Ok i figured it , i had to link the math lib directly in simple ide, but is there a way to make the math lib smaller so it includes only the used functions ???

    It does include only the used functions, but due to the way functions are implemented sometimes one function may use another function.

    If you're very close to the limit on LMM, try using CMM (compressed memory model). This runs all code in hub memory, but compresses the instructions so more of them fit (you can get about twice as much code). It runs faster than XMM, usually.

    Also, try linking with 32 bit doubles. I know you're only using float in the example you gave, but internally the math functions use doubles, so if 32 bits of precision is enough then you can get some smaller/faster code by changing double to 32 bits.

    Eric
  • jazzedjazzed Posts: 11,803
    edited 2013-03-24 13:01
    Anubispod wrote: »
    Ok i figured it , i had to link the math lib directly in simple ide, but is there a way to make the math lib smaller so it includes only the used functions
    ???

    It already does that.

    If you can use 32 math, check the Program Manager->Compiler option "32bit Double" - that is smaller than the 64bit default.

    We have considered providing the existing F32 COG features as a C library. The core team just hasn't had time yet. One could try using spin2cpp to create the F32 functions. I'm not completely convinced that an F32 C library would be much smaller than the current math functions though.
    Anubispod wrote: »
    I reached the 32K in lmm , and that sucks since i need more code there and as fast as lmm is , xmm with my epprom is to slow.
    Would be sram or 1 MB SPI Flash memory faster the the upper 32k of the epprom ??
    If not i would have to go with a diffrent mcu for my hexacopter design.
    Best regards Oliver

    1MB SPI Flash is several times faster than EEPROM. There are a few devices currently supported. Windbond SPI chips will work.
  • AnubispodAnubispod Posts: 42
    edited 2013-03-24 13:02
    Im already on 32bit doubles, and the cmm i ahve not yet tried since i could not figure out how to use it ;(
    But i think i need eather extra hardware sram or so.

    Best regards
    Oliver.R
  • jazzedjazzed Posts: 11,803
    edited 2013-03-24 13:12
    Anubispod wrote: »
    Im already on 32bit doubles, and the cmm i ahve not yet tried since i could not figure out how to use it ;(
    But i think i need eather extra hardware sram or so.

    Best regards
    Oliver.R

    If you have SimpleIDE v0-8-5, choose Project Manager -> Project Options -> Compiler = CMM. Works same as LMM except a little slower (still much faster than any XMM solution).

    To use SRAM you will need SRAM and SD card. To use regular Flash, you only need one SPI Flash chip. If you want faster Flash and have the pins, you can add 2 QuadSPI Flash parts in parallel and use SSF option.
  • AnubispodAnubispod Posts: 42
    edited 2013-03-24 13:12
    Wich SPI Fash is good to use ?? like this one ? W25X10CL

    512 pages,
    4KB sectors,
    32/64KB blocks,
    Fast Write,
    Dual SPI

    Best regards
    Oliver.R
  • jazzedjazzed Posts: 11,803
    edited 2013-03-24 13:32
    Anubispod wrote: »
    Wich SPI Fash is good to use ?? like this one ? W25X10CL

    512 pages,
    4KB sectors,
    32/64KB blocks,
    Fast Write,
    Dual SPI

    Best regards
    Oliver.R

    Get a 10 pack of these: http://www.digikey.com/product-detail/en/W25Q80BVSNIG/W25Q80BVSNIG-ND/2815927
    Or the same in PDIP8: http://www.digikey.com/product-detail/en/W25Q80BVDAIG/W25Q80BVDAIG-ND/2208452

    About the same as what you mentioned except has QuadSPI which allows for faster code if you need it and have P0-8 free + 2 pins. If you don't have pins for the fast 2 chip solution, a single SPI Flash is still much better than EEPROM.

    I have some Stamp-Like PCB modules that use dual-QuadSpi if you want some.
  • AnubispodAnubispod Posts: 42
    edited 2013-03-24 13:51
    Ok so that i get that right i need for 2xQuad 10 pins ?

    and how is it with the spi driver where and how many are needed ?

    so far i run an estimate that i will use 6 cogs

    0 = Main Loop
    1 - IMU (pasm reading and configure IMU includes i2c in pasm is 330 longs)
    2 - Motor Driver and LED (pasm pwm fits 420 longs)
    3 - Comm ( (pasm or c im not shure yet)Nordic 2.4GHz Telemetrie and Controller Xbox)
    4 - SPI for Comm
    5 - RX (pasm loop getting data from a RC Reciver as PPM and RSSI)

    So i hope the new Hardware does not use more then 1 so 1 is left for later mods
    And what are those boards you have some info or pic or price :)

    Best regards
    Oliver .R
  • jazzedjazzed Posts: 11,803
    edited 2013-03-24 19:09
    >> Ok so that i get that right i need for 2xQuad 10 pins ?

    Only for byte-wide Flash code storage. The solution is roughly 30% faster than SPI Flash. Some comparisons are made below.

    >> and how is it with the spi driver where and how many are needed ?

    The cache drivers for typical SPI Flash use 4 pins. We have drivers for the Windbond parts and SQI. Any cache driver uses a COG.

    >> so far i run an estimate that i will use 6 cogs

    Take note that, at the moment Propeller-GCC XMM modes only support multiple COGs with cognew using PASM/GAS or COGC.
    Multiple LMM/CMM COGs started with cogstart or _start_cog_thread will not work with XMMC or other XMM modes.

    >> And what are those boards you have some info or pic or price :)

    I'll send you some un-assembled PCBs for free in first class mail in the USA. They are entirely surface mount boards except for the edge pins.

    Check this thread for more info: http://forums.parallax.com/showthread.php/129713-Introducing-the-SpinSocket(tm)-Concept?p=978250&viewfull=1#post978250

    I was looking around and found some performance comparisons: http://forums.parallax.com/showthread.php/136397-Speed-Comparisons-of-Spin-LMM-and-XMMC?p=1057256&viewfull=1#post1057256

    According to that table:
    • Propeller-GCC LMM is about 3x faster than Spin.
    • Propeller-GCC CMM is a little faster than SPIN.
    • Spin is a little more than 2x faster than the 10 pin Flash.
    • The 10 pin flash solution is about 30% faster than regular Flash.
    • Regular Flash is 2x faster than EEPROM.
    • EEPROM is 3x faster than SD-XMMC.
  • AnubispodAnubispod Posts: 42
    edited 2013-03-25 06:27
    Thanks jazzed for the good infos , im not shure yet as if i need the extra hardware, since i have made some changes
    instead of printf i use a serial cog what gave me a lot of room kb wise.

    But still i have this funky error on compiling its not it self the atan function then more when i pass the pointer back from the float.
    i attached the project files so its easy to see.

    open project and compile all works well
    compiles in LMM with

    25976 bytes sent so 6k-+ left for the missing code i need ( SPI /Comm and RC Reciver )

    open file :sensfusion6.c go down and uncomment the marked error casing lines
    and then compile

    as you guys can see the yaw works as long i take it in steps so atan2 works,
    atan works but not passing the value back

    ????
    one solution is linking the .o file of the mathlib directly in but of course that makes my ram go puff

    I hope its a bug some where

    Best regards Oliver .R
  • ersmithersmith Posts: 6,054
    edited 2013-03-25 08:39
    jazzed wrote: »

    I was looking around and found some performance comparisons: http://forums.parallax.com/showthread.php/136397-Speed-Comparisons-of-Spin-LMM-and-XMMC?p=1057256&viewfull=1#post1057256

    According to that table:
    • Propeller-GCC LMM is about 3x faster than Spin.
    • Propeller-GCC CMM is a little faster than SPIN.
    • Spin is a little more than 2x faster than the 10 pin Flash.

    Those must be numbers without optimization. With optimization PropGCC LMM is at least 10x faster than Spin, and CMM is usually 2x-4x faster than Spin. I haven't done a lot of benchmarks in XMM, but I'd assume -Os would help quite a bit there (since execution time is often dominated by the time to fetch instructions from external memory).

    Eric
  • ersmithersmith Posts: 6,054
    edited 2013-03-25 08:47
    Anubispod wrote: »
    open file :sensfusion6.c go down and uncomment the marked error casing lines
    and then compile
    You mean lines 220 and 225, marked with "//Buggy line when uncommented it trows errors"? I tried uncommenting those and everything still compiles for me. What error do you get?

    Eric
  • AnubispodAnubispod Posts: 42
    edited 2013-03-25 08:58
    I get that error :
    #
    Project Directory: C:/Users/R2D2/Documents/SimpleIDE/testme/  propeller-elf-gcc.exe -o a.out -Os -mlmm -I . -m32bit-doubles -fno-exceptions Motor_led_Driver.h Motor_led_Driver.c MPU6050_XS.c MPU6050_XS.h Filter.h Filter.c testme.h pid.h pid.c controller.h controller.c sensfusion6.h sensfusion6.c FullDuplexSerial.h FullDuplexSerial.c testme.c -lm
     C:\Users\R2D2\AppData\Local\Temp\cc639TdE.o: In function `_sensfusion6GetEulerRPY':
      (.text+0xd88): undefined reference to `_atan'
      C:\Users\R2D2\AppData\Local\Temp\cc639TdE.o: In function `_sensfusion6GetEulerRPY':
      (.text+0xdec): undefined reference to `_atan'
      collect2: ld returned 1 exit status
      Done. Build Failed!
      Check source for bad function call or global variable name `_atan'
      C:\Users\R2D2\AppData\Local\Temp\cc639TdE.o: In function `_sensfusion6GetEulerRPY':
      (.text+0xdec): 
    

    mhhh??? so you can compile???
    damm what wrong here
  • ersmithersmith Posts: 6,054
    edited 2013-03-25 09:39
    What version of the PropGCC tools do you have? I see that back in July we fixed a bug where the atan function was missing from the library in 32 bit builds. You may need to update to propellergcc v0_3_5, or to any of the p2test releases. The p2test version of PropGCC works on Propeller 1, and has much faster and smaller floating point routines, so that might help you as well.

    Eric
  • AnubispodAnubispod Posts: 42
    edited 2013-03-25 09:57
    Great Job , it works i deinstalled all from simple ide and got the new version for cmm
    and it compiles in cmm and lm now thanks a lot so i can continue with my porting of stuff to finish my mockup code and get to my hardware design :)

    Best regards
    Oliver.R
  • AnubispodAnubispod Posts: 42
    edited 2013-03-25 10:29
    Little Update, i just also installed the prop2 version , and as you promised me the float stuff was smaller and wow fast.
    I get it now compiled in LMM with mixed optima, and get all the code in 23k so i got 9 k left

    Best regards
    Oliver .R
  • jazzedjazzed Posts: 11,803
    edited 2013-03-25 13:00
    Nice outcome so far.

    Eric, sorry about the old performance numbers. Unfortunately, I can imagine someone quoting an old post like that again.

    Smaller floating point will be very welcome.

    I forgot about the atan/atan2 bug. I'm guessing the distribution got used because of the outdated info in www.parallax.com/propellergcc .
  • photomankcphotomankc Posts: 943
    edited 2013-03-26 23:10
    jazzed wrote: »
    I have some Stamp-Like PCB modules that use dual-QuadSpi if you want some.

    Id be interested to see those.
  • jazzedjazzed Posts: 11,803
    edited 2013-03-27 08:01
    photomankc wrote: »
    Id be interested to see those.

    I take it you saw this? http://forums.parallax.com/showthrea...l=1#post978250
    Don't have time to build them myself just now. PM your address if you want some PCBs.
  • photomankcphotomankc Posts: 943
    edited 2013-03-27 09:04
    Hmmm, no I had not seen that thread before. I'll PM you for the PCB's, that is a perfect fit for the RobotPlate I'm working on for the RaspberryPi. Would allow for adding the propeller as a module rather than squeezing it all onto the plate PCB.
Sign In or Register to comment.