Commit efc05ff5 authored by Jake Read's avatar Jake Read
Browse files

add remote stepper config to firmware, note phase angle sketch in log

parent 01e3ba73
...@@ -179,6 +179,10 @@ void STEP_A4950::setCurrent(float cscale){ ...@@ -179,6 +179,10 @@ void STEP_A4950::setCurrent(float cscale){
dacs->writeDac1(dacLUT[_bStep] * _cscale); dacs->writeDac1(dacLUT[_bStep] * _cscale);
} }
void STEP_A4950::setInversion(boolean inv){
_dir_invert = inv;
}
void STEP_A4950::dacRefresh(void){ void STEP_A4950::dacRefresh(void){
dacs->refresh(); dacs->refresh();
} }
...@@ -93,6 +93,7 @@ class STEP_A4950 { ...@@ -93,6 +93,7 @@ class STEP_A4950 {
boolean getDir(void); boolean getDir(void);
// current settings // current settings
void setCurrent(float cscale); void setCurrent(float cscale);
void setInversion(boolean inv);
// for the dacs // for the dacs
void dacRefresh(void); void dacRefresh(void);
}; };
......
...@@ -8,22 +8,59 @@ ...@@ -8,22 +8,59 @@
OSAP* osap = new OSAP("stepper motor drop"); OSAP* osap = new OSAP("stepper motor drop");
VPort_UCBus_Drop* vPortUcBusDrop = new VPort_UCBus_Drop(); VPort_UCBus_Drop* vPortUcBusDrop = new VPort_UCBus_Drop();
// clank cz: // bare defaults: use vm / bus id to set on startup
// AXIS SPU INVERT uint8_t axis_pick = 0;
// X: 320 false float spu = 400.0F;
// YL: 320 true float old_spu = 400.0F;
// YR: 320 false volatile boolean spu_was_set = false;
// Z: 924.4r false float c_scale = 0.2F;
// E: 830 currently false, not sure
// per bondtech, for BMG on 16 microsteps, do 415: we are 32 microsteps
// https://www.bondtech.se/en/customer-service/faq/
#define AXIS_PICK 0 // E: 3 Z: 2, Y: 1, X: 0
#define AXIS_INVERT false
#define SPU 320 //924.444444F
#define C_SCALE 0.4F // 0-1, floating
#define TICKS_PER_PACKET 25.0F #define TICKS_PER_PACKET 25.0F
// ENDPOINT 0
boolean onAxisPickSet(uint8_t* data, uint16_t len){
if(data[0] > 3){
axis_pick = 0;
} else {
axis_pick = data[0];
}
return true;
}
Endpoint* axisPickEP = osap->endpoint(onAxisPickSet);
// ENDPOINT 1
boolean onAxisInvertSet(uint8_t* data, uint16_t len){
if(data[0] > 0){
stepper_hw->setInversion(true);
} else {
stepper_hw->setInversion(false);
}
return true;
}
Endpoint* axisInvertEP = osap->endpoint(onAxisInvertSet);
// ENDPOINT 2
boolean onSPUSet(uint8_t* data, uint16_t len){
chunk_float32 spuc = { .bytes = { data[0], data[1], data[2], data[3] } };
old_spu = spu;
spu = fabsf(spuc.f);
spu_was_set = true;
return true;
}
Endpoint* spuEP = osap->endpoint(onSPUSet);
// ENDPOINT 3
boolean onCScaleSet(uint8_t* data, uint16_t len){
chunk_float32 cscalec = { .bytes = { data[0], data[1], data[2], data[3] } };
if(cscalec.f > 1.0F){
cscalec.f = 1.0F;
} else if (cscalec.f < 0.0F){
cscalec.f = 0.0F;
}
stepper_hw->setCurrent(cscalec.f);
return true;
}
Endpoint* cscaleEP = osap->endpoint(onCScaleSet);
void setup() { void setup() {
ERRLIGHT_SETUP; ERRLIGHT_SETUP;
CLKLIGHT_SETUP; CLKLIGHT_SETUP;
...@@ -35,7 +72,7 @@ void setup() { ...@@ -35,7 +72,7 @@ void setup() {
osap->description = "remote stepper drop"; osap->description = "remote stepper drop";
osap->addVPort(vPortUcBusDrop); osap->addVPort(vPortUcBusDrop);
// stepper // stepper
stepper_hw->init(AXIS_INVERT, C_SCALE); stepper_hw->init(false, c_scale);
} }
// have available, // have available,
...@@ -61,14 +98,20 @@ void UCBus_Drop::onPacketARx(void){ ...@@ -61,14 +98,20 @@ void UCBus_Drop::onPacketARx(void){
if(setBlock) return; if(setBlock) return;
//DEBUG2PIN_TOGGLE; //DEBUG2PIN_TOGGLE;
// last move is done, convert back steps -> float, // last move is done, convert back steps -> float,
current_floating_pos = current_step_pos / SPU; if(spu_was_set){
current_floating_pos = current_step_pos / old_spu;
current_step_pos = lroundf(current_floating_pos * spu);
spu_was_set = false;
} else {
current_floating_pos = current_step_pos / spu;
}
vel = 0.0F; // reset zero in case packet is not move vel = 0.0F; // reset zero in case packet is not move
uint8_t bptr = 0; uint8_t bptr = 0;
// switch bus packet types // switch bus packet types
switch(inBufferA[0]){ switch(inBufferA[0]){
case UB_AK_GOTOPOS: case UB_AK_GOTOPOS:
{ {
bptr = AXIS_PICK * 4 + 1; bptr = axis_pick * 4 + 1;
chunk_float32 target = { chunk_float32 target = {
.bytes = { inBufferA[bptr], inBufferA[bptr + 1], inBufferA[bptr + 2], inBufferA[bptr + 3] } .bytes = { inBufferA[bptr], inBufferA[bptr + 1], inBufferA[bptr + 2], inBufferA[bptr + 3] }
}; };
...@@ -87,9 +130,9 @@ void UCBus_Drop::onPacketARx(void){ ...@@ -87,9 +130,9 @@ void UCBus_Drop::onPacketARx(void){
stepper_hw->dir(false); stepper_hw->dir(false);
} }
// how many steps, // how many steps,
delta_steps = lroundf(abs(delta * SPU)); delta_steps = lroundf(abs(delta * spu));
// what speed // what speed
vel = abs(delta * SPU) / TICKS_PER_PACKET; vel = abs(delta * spu) / TICKS_PER_PACKET;
// for str8 r8 // for str8 r8
/* /*
if(delta_steps == 0){ if(delta_steps == 0){
...@@ -103,12 +146,12 @@ void UCBus_Drop::onPacketARx(void){ ...@@ -103,12 +146,12 @@ void UCBus_Drop::onPacketARx(void){
case UB_AK_SETPOS: case UB_AK_SETPOS:
{ {
// reqest is to set position, not go to it... // reqest is to set position, not go to it...
bptr = AXIS_PICK * 4 + 1; bptr = axis_pick * 4 + 1;
chunk_float32 target = { chunk_float32 target = {
.bytes = { inBufferA[bptr], inBufferA[bptr + 1], inBufferA[bptr + 2], inBufferA[bptr + 3] } .bytes = { inBufferA[bptr], inBufferA[bptr + 1], inBufferA[bptr + 2], inBufferA[bptr + 3] }
}; };
float target_current_pos = target.f; float target_current_pos = target.f;
int32_t target_current_steps = lroundf(target_current_pos * SPU); int32_t target_current_steps = lroundf(target_current_pos * spu);
setBlock = true; // don't do step work while these are modified setBlock = true; // don't do step work while these are modified
current_floating_pos = target_current_pos; current_floating_pos = target_current_pos;
current_step_pos = target_current_steps; current_step_pos = target_current_steps;
......
Subproject commit 0a37169e44d354fa301704ac0a351fb81bcca585 Subproject commit 7bbcbf8d8364d9beaf501d1acf6b34a77e4086f3
...@@ -353,6 +353,12 @@ I'm just going to get into the 'magnetic angle' pointing system for the DACs now ...@@ -353,6 +353,12 @@ I'm just going to get into the 'magnetic angle' pointing system for the DACs now
This makes sense: so when I'm at '0 degs' my A phase is on 100%, B phase is zero. Or, the way I've my LUT written, I'll have A at 0 and B at full-width positive. If I don't like this for some reason (It'll calibrate away) I can change the LUT. This makes sense: so when I'm at '0 degs' my A phase is on 100%, B phase is zero. Or, the way I've my LUT written, I'll have A at 0 and B at full-width positive. If I don't like this for some reason (It'll calibrate away) I can change the LUT.
FWIW **at 2021 02 03** I ended up drawing this out later:
![phase](2021-02-03_phase-steps-angle.jpg)
In the stepper, we have one 'complete electrical phase' inside of four of what we normally call 'steps' - this spans 7.2 physical degrees when we have a 200 'step' (pole) motor.
I'm up to pointing, now I just need to deliver some power to the motor. I'm up to pointing, now I just need to deliver some power to the motor.
OK, this is making sense and I can point my magnetic vector around: OK, this is making sense and I can point my magnetic vector around:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment