My implementation of divide is repeated addition of the denominator until the numerator is exceeded, then subtract the denominator once. So, 1/3 = 0+3-3 = 0.
My method will always "truncate" in this fashion. I suppose a little bit of extra logic could be used to evaluate how close the partial result is to the numerator in order to do rounding, but I usually find that the consistency of slight inaccuracy is beneficial!
Only in recent few years, have a I seen jet engine embedded controllers using floating point maths. Rescaling values which are in a known range to fit within an integer range is not a new thing and there are multiple tricks and techniques all well documented all over the interenet. Microchip even offers code samples for lots of these.
I suggest that inside your MCU, you don’t use any real-world values at all:
- Multiply EVERYTHING up before you start. If you have a value which is always going to be in the range 0…255, store it in an unsigned 16-bit integer.Even better, store it in the MOST significant byte, so that (effectively) the LSB becomes your “remainder”.
- Write a procedure or a macro to multiply it up then divide it back down again. Don’t forget that multiplying by 256 is “clear MSbyte then SWAP LS/MS bytes.”
- Bear in mind, that I’m talking RISC assembler. For all I know, if you try to do this in BASIC, your code will be massive.
What’s goin’ on? Why is the guy in that video copying what his robot arm is doing? There are a few odd bits where it looks like he forgets the sequence and does his own thing.
Really nice work CTC. Great craftmanship as usual. In the beginning paragraph you mention that you don’t want to use a computer, I take it, it was an exercise to see what you could do with a micro? Are you going to attach it to computer before you get the nano-ITX?
Thanks. I’m not really sure what path I’ll take with it. I’ve always been intrigued by the little biscuit PCs, ever since I was working on putting a computer in my car back in 2001. But I’ve never actually messed around with one, whereas I have plenty of experience with cheap CraigsList laptops – I’ve currently got two on my network functioning as servers for things like DNS and DHCP. So I might just go that route if I can lay my hands on another cheap laptop – it’d be bigger than a biscuit PC, but odds are it’d have a little more processing power too.
And that’s a good idea about running the arm from one of my existing computers to start messing with that sort of stuff now – that’d also help me determine what kind of hardware I’ll need. But all my machines run Linux, and it seems like a big majority of the vision processing etc software runs in Windows. So that might be a limitation. But I guess it’s time to looking into what’s available.
- I was lucky enough to see - I was lucky enough to see this before it went public. However, seeing the video again, makes me smile again, it’s really cool work, Dan! Great arm control as they say
Ah, interesting. That was just the impression I had gotten – I hadn’t done much searching yet. Good to know there’s options for Linux – I’d much rather run that on a robot controller. Easier to take advancage of lesser hardware, and built-in SSH etc makes it easier to control remotely. Thanks for the links.