trying to fix microsteps fix

This commit is contained in:
sanjayk03-dev
2025-08-31 17:35:38 +05:30
parent 6b151d1fc6
commit 7e0739eea3
2 changed files with 81 additions and 35 deletions

View File

@@ -122,7 +122,20 @@ module.exports = {
attached: function() { attached: function() {
// Sync all state values with motor config when component mounts // Sync all state values with motor config when component mounts
// This ensures UI shows correct values even if rotary was toggled on another page // This ensures UI shows correct values even if rotary was toggled on another page
// Debug: Log current state values before sync
console.log(`DEBUG: Motor ${this.index} state values on mount:`);
console.log(` current_step_angle (${this.index}sa):`, this.current_step_angle);
console.log(` current_microsteps (${this.index}mi):`, this.current_microsteps);
console.log(` current_travel_per_rev (${this.index}tr):`, this.current_travel_per_rev);
this.syncStateToConfig(); this.syncStateToConfig();
// Debug: Log motor config values after sync
console.log(`DEBUG: Motor ${this.index} config values after sync:`);
console.log(` motor step-angle:`, this.motor['step-angle']);
console.log(` motor microsteps:`, this.motor['microsteps']);
console.log(` motor travel-per-rev:`, this.motor['travel-per-rev']);
}, },
watch: { watch: {
@@ -217,42 +230,62 @@ module.exports = {
const motor_axes = ["X", "Y", "Z", "A", "B", "C"]; const motor_axes = ["X", "Y", "Z", "A", "B", "C"];
// Sync all motor properties that have corresponding state values // Define mapping between state properties and motor config properties
if (this.current_axis !== undefined && motor_axes[this.current_axis] !== this.motor['axis']) { const stateToMotorMapping = [
this.motor['axis'] = motor_axes[this.current_axis]; {
} stateKey: 'current_axis',
motorKey: 'axis',
transform: (value) => motor_axes[value]
},
{
stateKey: 'current_max_velocity',
motorKey: 'max-velocity'
},
{
stateKey: 'current_max_soft_limit',
motorKey: 'max-soft-limit'
},
{
stateKey: 'current_min_soft_limit',
motorKey: 'min-soft-limit'
},
{
stateKey: 'current_max_accel',
motorKey: 'max-accel'
},
{
stateKey: 'current_max_jerk',
motorKey: 'max-jerk'
},
{
stateKey: 'current_step_angle',
motorKey: 'step-angle'
},
{
stateKey: 'current_travel_per_rev',
motorKey: 'travel-per-rev'
},
{
stateKey: 'current_microsteps',
motorKey: 'microsteps'
}
];
if (this.current_max_velocity !== undefined && this.current_max_velocity !== this.motor['max-velocity']) { // Sync all properties using the mapping
this.motor['max-velocity'] = this.current_max_velocity; stateToMotorMapping.forEach(({ stateKey, motorKey, transform }) => {
} const stateValue = this[stateKey];
if (this.current_max_soft_limit !== undefined && this.current_max_soft_limit !== this.motor['max-soft-limit']) { if (stateValue === undefined) {
this.motor['max-soft-limit'] = this.current_max_soft_limit; return; // Skip if state value is not defined
} }
if (this.current_min_soft_limit !== undefined && this.current_min_soft_limit !== this.motor['min-soft-limit']) { const transformedValue = transform ? transform(stateValue) : stateValue;
this.motor['min-soft-limit'] = this.current_min_soft_limit; const currentMotorValue = this.motor[motorKey];
}
if (transformedValue !== currentMotorValue) {
if (this.current_max_accel !== undefined && this.current_max_accel !== this.motor['max-accel']) { this.motor[motorKey] = transformedValue;
this.motor['max-accel'] = this.current_max_accel; }
} });
if (this.current_max_jerk !== undefined && this.current_max_jerk !== this.motor['max-jerk']) {
this.motor['max-jerk'] = this.current_max_jerk;
}
if (this.current_step_angle !== undefined && this.current_step_angle !== this.motor['step-angle']) {
this.motor['step-angle'] = this.current_step_angle;
}
if (this.current_travel_per_rev !== undefined && this.current_travel_per_rev !== this.motor['travel-per-rev']) {
this.motor['travel-per-rev'] = this.current_travel_per_rev;
}
if (this.current_microsteps !== undefined && this.current_microsteps !== this.motor['microsteps']) {
this.motor['microsteps'] = this.current_microsteps;
}
} }
} }
}; };

View File

@@ -740,6 +740,19 @@ class RotaryHandler(bbctrl.APIHandler):
# Force a complete reload to ensure all values are properly encoded and sent to frontend # Force a complete reload to ensure all values are properly encoded and sent to frontend
config.reload() config.reload()
# Debug: Log the current state values for motor 2 to verify they're being set
log.info(f"DEBUG: After reload - Motor 2 state values:")
log.info(f" 2sa (step-angle): {ctrl.state.get('2sa')}")
log.info(f" 2mi (microsteps): {ctrl.state.get('2mi')}")
log.info(f" 2tr (travel-per-rev): {ctrl.state.get('2tr')}")
# TARGETED FIX: Explicitly ensure microsteps gets sent to state
# This addresses potential issues with microsteps being treated as machine variable
motor_2_final = motors[2]
ctrl.state.set('2mi', motor_2_final.get('microsteps'))
ctrl.state.set('2sa', motor_2_final.get('step-angle'))
ctrl.state.set('2tr', motor_2_final.get('travel-per-rev'))
# Explicitly trigger state notification to ensure frontend gets updates # Explicitly trigger state notification to ensure frontend gets updates
# This forces immediate WebSocket notification of all state changes # This forces immediate WebSocket notification of all state changes
ctrl.state._notify() ctrl.state._notify()