@@ -899,6 +899,8 @@ OK this is crazy, I have every fn in the class commented out, and the thing stil
So, tried my way around that, I have honestly no idea what is going on here. I'm going to try writing from the base class again.

OK, did that and seems like I'm writing into the thing. Crazy. Here's the code:
```cpp
...
...
@@ -995,4 +997,48 @@ Not cool. Also seems pretty terrence regardless: easy to stall.
Ah, I was mapping 1.8 - 1.0, should have been 7.2 - 1.0: the 0-1 'phase angle' sweeps thru 4 full steps, not one.
OK well this is a decent minimum viable thing: it commutates. There's (I think) an obvious relationship between control loop and maximum RPM, so it's probably all maths and optimization from here out. The encoder read is the the obvious bottleneck, so is that modulus operation. I'm not totally sure I'm applying phase angle ideally... ah yeah, obviously better results when I do 180* phase rotation rather than 90, why did I think it was 90? Thing's rippen at 5krpm w/ no load, that should do pretty well, stoked to put it on an axis tomorrow and issue some commands from the browser to whip things around. Exciting futures for motion control.
\ No newline at end of file
OK well this is a decent minimum viable thing: it commutates. There's (I think) an obvious relationship between control loop and maximum RPM, so it's probably all maths and optimization from here out. The encoder read is the the obvious bottleneck, so is that modulus operation. I'm not totally sure I'm applying phase angle ideally... ah yeah, obviously better results when I do 180* phase rotation rather than 90, why did I think it was 90? Thing's rippen at 5krpm w/ no load, that should do pretty well, stoked to put it on an axis tomorrow and issue some commands from the browser to whip things around. Exciting futures for motion control.

## 2020 10 16
Next real steps for this are formulating it into a paper / research question, then getting into the work.
OK - the work. Am going to do a torque command from the browser first, full width.
That works, now I'm noticing some oddball behaviour - the control loop seems to lag depending on where the encoder reading is: I thought that was because the maths was taking longer (father to modulo down) but I might just have some pins mixed up? Ah - this was a mistaken end-of-transmission from the SPI level... fixed, I was correct orginally, just had the pin flipping confused.
So yeah, this is the long modulo. I guess it won't hurt to try writing a second LUT for phase angle, see if I can bring that execution time down... ready to brick in 3..2..1.. bricked haha, IDK how to align such a big table in RAM I guess.
So to store that in flash, I could perhaps build the LUT to be like [ra0, pa0, ra1, pa1, ..., ra1024, pa1024] and access with 2x or 2x + 1 indices. Let's see if I can write a flash table this long without any trouble.
OK, so my loop is now more like:
```cpp
_ra=lut[result*2];// the real angle (position 0-360)
_pa=lut[result*2+1];// the phase angle (0 - 1 in a sweep of 4 steps)
// this is the phase angle we want to apply, 90 degs off & wrap't to 1
if(step_cl->get_torque()<0){
_pa-=0.25;// 90* phase swop
if(_pa<0){
_pa+=1.0F;
}
}else{
_pa+=0.25;
if(_pa>1){
_pa-=1.0F;
}
}
// now we ask our voltage modulation machine to put this on the coils
// with the *amount* commanded by our _tc torque ask
and runs 2.4us. The whole loop is now nicely just around 10us, so I could choke the whole micro and run 100kHz and probably trip up, or I'll try running ~ 75kHz, or I could be satisfied with 50 and leave overhead for the processor to do ... well ... other stuff, haha. I.E I will probably want this headroom for positioning PID, etc. Maybe I should just get it mounted on an axis and proceed with the next steps instead of fiddling with speed before I know it's necessary or warranted.
- consider writing another LUT for RA -> Phase Angle (PA)
- could do in RAM at startup, might crash ur shit tho
- do commands from the browser to jiggy jog
- put on an axis, see how fast it can swing it
- begin the maths, the control, etc... see if you can optimize that loop, high speed is ur friend