Skip to content

Commit 3b8ab47

Browse files
committed
Fixed effects ratio incorrectly affecting endstop
1 parent a8fb47f commit 3b8ab47

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Changes this version:
22
- Changed default power from 2000 to 5000 as 2000 is not enough to calibrate many motors
33
- Internal change moving effects into effectscalculator to simplify managing effects from different sources
4+
- Effect intensity tuning value now only affects game effects. Fixes the effect intensity incorrectly affecting the endstop.
45

56
### Changes since 1.9.x:
67
- Added local encoder index option to reload a previously stored offset

Firmware/FFBoard/Inc/Axis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ class Axis : public PersistentStorage, public CommandHandler, public ErrorHandle
234234
uint8_t fx_ratio_i = 204; // Reduce effects to a certain ratio of the total power to have a margin for the endstop. 80% = 204
235235
uint16_t power = 5000;
236236
float torqueScaler = 0; // power * fx_ratio as a ratio between 0 & 1
237+
float effect_margin_scaler = 0;
237238
bool invertAxis = false;
238239
uint8_t endstopStrength = 127; // Sets how much extra torque per count above endstop is added. High = stiff endstop. Low = softer
239-
const float endstopGain = 50; // Overall max endstop intensity
240+
const float endstopGain = 25; // Overall max endstop intensity
240241

241242

242243
uint8_t idlespringstrength = 127;

Firmware/FFBoard/Src/Axis.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Axis::Axis(char axis,volatile Control_t* control) :CommandHandler("axis", CLSID_
5353
restoreFlash(); // Load parameters
5454
CommandHandler::registerCommands(); // Internal commands
5555
registerCommands();
56-
56+
updateTorqueScaler(); // In case no flash setting has been loaded yet
5757
}
5858

5959
Axis::~Axis()
@@ -79,7 +79,7 @@ void Axis::registerCommands(){
7979
registerCommand("pos", Axis_commands::pos, "Encoder position",CMDFLAG_GET);
8080
registerCommand("maxspeed", Axis_commands::maxspeed, "Speed limit in deg/s",CMDFLAG_GET | CMDFLAG_SET);
8181
registerCommand("maxtorquerate", Axis_commands::maxtorquerate, "Torque rate limit in counts/ms",CMDFLAG_GET | CMDFLAG_SET);
82-
registerCommand("fxratio", Axis_commands::fxratio, "Effect ratio. Reduces effects excluding endstop. 255=100%",CMDFLAG_GET | CMDFLAG_SET);
82+
registerCommand("fxratio", Axis_commands::fxratio, "Effect ratio. Reduces game effects excluding endstop. 255=100%",CMDFLAG_GET | CMDFLAG_SET);
8383
registerCommand("curtorque", Axis_commands::curtorque, "Axis torque",CMDFLAG_GET);
8484
registerCommand("curpos", Axis_commands::curpos, "Axis position",CMDFLAG_GET);
8585
registerCommand("curspd", Axis_commands::curspd, "Axis speed",CMDFLAG_GET);
@@ -452,7 +452,7 @@ void Axis::setIdleSpringStrength(uint8_t spring){
452452
}else{
453453
idle_center = true;
454454
}
455-
idlespringclip = clip<int32_t,int32_t>((int32_t)spring*50,0,10000);
455+
idlespringclip = clip<int32_t,int32_t>((int32_t)spring*35,0,10000);
456456
idlespringscale = 0.5f + ((float)spring * 0.01f);
457457
}
458458

@@ -523,8 +523,8 @@ uint16_t Axis::getPower(){
523523
}
524524

525525
void Axis::updateTorqueScaler() {
526-
float effect_margin_scaler = ((float)fx_ratio_i/255.0);
527-
torqueScaler = ((float)power / (float)0x7fff) * effect_margin_scaler;
526+
effect_margin_scaler = ((float)fx_ratio_i/255.0);
527+
torqueScaler = ((float)power / (float)0x7fff);
528528
}
529529

530530
float Axis::getTorqueScaler(){
@@ -547,7 +547,7 @@ int16_t Axis::updateEndstop(){
547547
return 0;
548548
}
549549
float addtorque = clipdir*metric.current.posDegrees - (float)this->degreesOfRotation/2.0; // degress of rotation counts total range so multiply by 2
550-
addtorque *= (float)endstopStrength * endstopGain * torqueScaler; // Apply endstop gain for stiffness.
550+
addtorque *= (float)endstopStrength * endstopGain; // Apply endstop gain for stiffness.
551551
addtorque *= -clipdir;
552552

553553
return clip<int32_t,int32_t>(addtorque,-0x7fff,0x7fff);
@@ -566,10 +566,11 @@ bool Axis::updateTorque(int32_t* totalTorque) {
566566
}
567567

568568
// Scale effect torque
569-
effectTorque *= torqueScaler;
570-
571-
int32_t torque = effectTorque + updateEndstop();
572-
torque += axisEffectTorque * torqueScaler; // Updated from effect calculator
569+
int32_t torque = effectTorque; // Game effects
570+
torque *= effect_margin_scaler;
571+
torque += axisEffectTorque; // Independent effects
572+
torque += updateEndstop();
573+
torque *= torqueScaler; // Scale to power
573574

574575
// TODO speed and accel limiters
575576
if(maxSpeedDegS > 0){

0 commit comments

Comments
 (0)