Shop OBEX P1 Docs P2 Docs Learn Events
NEWB question — Parallax Forums

NEWB question

seanpaulseanpaul Posts: 5
edited 2011-04-15 04:55 in Propeller 1
How do I create matrices in spin?

Comments

  • LeonLeon Posts: 7,620
    edited 2011-04-15 00:00
    You only have single-dimensional arrays in Spin so you can't do matrix operations easily. There is some assembler code in the Obex that gives you most of the usual matrix stuff up to 11x11. It requires a separate FPU chip, however.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2011-04-15 00:10
    Not true, depending on size. For a simple thing like a 3x3 rotation matrix, it can be done in spin, but you can't allocate a 2D array - you have to settle for 9 longs. 15 bit fixed point works well. Have a look at the code in the Propeller DCM thread - it does vector and matrix math in Spin.

    If you're trying to use very large matrices, Spin will likely be too slow. Can you give us more specifics?
  • LeonLeon Posts: 7,620
    edited 2011-04-15 00:30
    I didn't say it couldn't be done, I said that it wasn't easy!

    Using one of the C compilers is another option, they should support multi-dimensional arrays.
  • seanpaulseanpaul Posts: 5
    edited 2011-04-15 04:37
    OK here it goes...
    I am participating in a micromouse competition tomorrow. I originally had my algorithm in MATLab which I was planning on transferring into C (via cspin) and then having that interact with my movement commands (written in spin). However, apparently MATLab just recently updated the MATLab to C package and any support such as online tutorials and videos are gone. Over the course of the last 48 hours I manually transferred my MATLab code to C, only to find out the code was almost 4 times to large for the propeller RAM! Now I am either going to make a much simplified version of C code or try to write an algorithm in spin. I hope I got that all out without confusion. I havent slept much recently...any suggestions?
  • martinhmartinh Posts: 58
    edited 2011-04-15 04:55
    Can you show the matlab code (if it is not a secret), I program in the matlab language as well as in C. I cannot promise to solve your problem, but maybe can help a bit.

    Addendum: I just noticed that the homespun compiler supports extended syntax for multdimensional arrays in spin. If that helps have a look here:
    http://propeller.wikispaces.com/Homespun+Spin+Compiler
Sign In or Register to comment.