Fixing "stuck in jogging" bug.

This commit is contained in:
David Carley
2022-08-31 15:56:33 +00:00
parent 2f97bdd4aa
commit ed1e4e6511
3 changed files with 20 additions and 9 deletions

View File

@@ -201,7 +201,7 @@ enum {
#define I2C_DEV TWIC
#define I2C_ISR TWIC_TWIS_vect
#define I2C_ADDR 0x2b
#define I2C_MAX_DATA 8
#define I2C_MAX_DATA 16
// Motor

View File

@@ -62,8 +62,10 @@ static void _i2c_end_command() {
static void _i2c_command_byte(uint8_t byte) {
if (i2c.length < I2C_MAX_DATA) {
i2c.data[i2c.length++] = byte;
}
}
ISR(I2C_ISR) {

View File

@@ -123,6 +123,12 @@ class Mach(Comm):
if log['msg'] == 'Switch not found':
self.estop()
def _end_cycle(self):
if (self._get_cycle() != 'idle' and self._is_ready()
and not self.planner.is_busy() and not super().is_active()):
self.planner.position_change()
self._set_cycle('idle')
def _update(self, update):
# Detect motor faults
for motor in range(4):
@@ -138,11 +144,9 @@ class Mach(Comm):
if state_changed and state == 'ESTOPPED':
self.planner.reset(stop=False)
# Exit cycle if state changed to READY
if (state_changed and self._get_cycle() != 'idle' and self._is_ready()
and not self.planner.is_busy() and not super().is_active()):
self.planner.position_change()
self._set_cycle('idle')
# Check if cycle has ended
if state_changed:
self._end_cycle()
# Planner stop
if state == 'READY' and self.stopping:
@@ -191,8 +195,13 @@ class Mach(Comm):
@overrides(Comm)
def comm_next(self):
if self.planner.is_running() and not self._is_holding():
return self.planner.next()
shouldFetch = self.planner.is_running() and not self._is_holding()
cmd = self.planner.next() if shouldFetch else None
if cmd is None:
self._end_cycle()
return cmd
@overrides(Comm)
def comm_error(self):