Saturday, 19 March 2016

fpga - Microcontroller/cpu for fast trigonometry in robot?


This concerns hardware that does weighs little, because a (fat cat sized, 6 legs with 3 DOF) walking robot should carry it around. Because of that walking it'll need to do a lot of trigonometry (using matrix math or not i'm not sure yet) and this is where this question comes from.


PIC, Arduino or cheap AVR is not fast enough to calculate everything 100/second and keep things like inertia and obstacle avoidance in mind, or even bruteforce paths/gaits.





  • Plan A is to carry the brain on the robot. Be it microprocessor, micro ITX, nettop or other; what is efficient hardware to do trigonometry / matrix math fast?


    I searched online and expected to find out about AVR, x86, or ARM microcontrollers specialized in this but no luck there.




  • Plan B is to have a x86 machine connected via WiFi to do the heavy lifting. Great for prototyping also, but i'd like this to migrate to plan A eventually when the hardware miniaturizes. But even then, what desktop CPU can do trigonometry the fastest?




  • Plan C is to distribute the load and have one power efficient microcontroller/core for each leg, although that is not the best solution for many reasons i like the extend-ability of it.





I have not decided on the language and/or library used yet, but prefer Pascal and C++.


(suggestions for more suitable tags welcome, i am new here)



Answer



It does not sound like your application is really all that compute intensive. A dsPIC, for example, can execute 400 k instruction for each one of your iterations. That's a lot. It will be useful, however, to have good low level I/O capability, PWM generators, timers, and the like.


Sine and cosine is really not that hard to do in a integer machine like a dsPIC. I have done it a few time myself. The trick is to pick the right representation for angles. Radians may be nice from a theoretical point of view, but is inconvenient computationally. Degress are artificial and just silly. Use the full range of whatever your machine-sized integer is to represent one full rotation. For example, on a dsPIC, which is a 16 bit processor, one full rotation is 65536 counts, which is way more accuracy and resolution than you need to control a robot or that you can measure anyway.


One advantage of this representation is that all the wrapping happens automatically just due to how unsigned integer adds and subtracts work. Another significant advantage is that this representation lends itself particularly well to using lookup tables for sine and cosine. You only need to store 1/4 cycle. The top two bits of the angle tell you which quadrant you are in, which tells you whether to index into the table forwards or backwards, and whether to negate the result or not. The next N lower bits are used to index into the table, with the table having 2N segments (2N+1 points). Note that indexing into the table backwards is then just complementing the table index bits.


You can give the table enough points so that picking the nearest answer is good enough. For example, if the table has 1024 segments, then sine and cosine will be computed to the nearest 1/4096 of a circle. That's going to be plenty for controlling a robot. If you want more accuracy, you can either make the table bigger or use the remaining lower bits of the angle to linearly interpolate between adjacent table entries.


Anyway, the point is it seems your requirements for this processor don't match up with the stated problem. I'd probably use a dsPIC33F. It is certainly small, light weight, and much more power efficient than a full blown general purpose computing process like a x86 on a single board computer.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...