Skip to content

Commit

Permalink
Attempt various fixes to the MCMCU commands that check if a certain m…
Browse files Browse the repository at this point in the history
…otor

has stopped moving.

These fixes don't seem to fix the error in the final position where the
motor is left by the hard home routine, which is probably due to the
clearing of the motor position register after the hard home. Other
approaches should be tried.
  • Loading branch information
Jonan CM committed Jan 13, 2014
1 parent 82182d4 commit f65a15e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
10 changes: 10 additions & 0 deletions delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@ void delay_us(unsigned int duration)
for (count = 0; count < limit; ++count);
}

void delay_ms(unsigned int duration)
{
delay_us(duration * 1000);
}

void delay_s(unsigned int duration)
{
delay_us(duration * 1000000);
}

#endif
54 changes: 42 additions & 12 deletions motorctl/gpcorecom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1965,9 +1965,14 @@ inline void check_halt_motor_a(void)
int count, prev_steps = motor_steps[MOTOR_A], curr_steps;
for (count = HALT_COUNT; count > 0;)
{
delay_us(5);
// QEA and QEB change at a rate of 2 KHz (0.5 ms) at maximum velocity.
// Thus, in order to detect changes in the position, we must wait around
// 1 second for greater safety.
delay_s(1);
// Compare the previous and current state of the motor step counter
// register to see if there have been any changes in motor position.
curr_steps = motor_steps[MOTOR_A];
count -= 1 - (curr_steps - prev_steps > 0);
count -= 1 - (curr_steps == prev_steps);
}
mcuicom_send(CMDEND);
}
Expand All @@ -1977,9 +1982,14 @@ inline void check_halt_motor_b(void)
int count, prev_steps = motor_steps[MOTOR_B], curr_steps;
for (count = HALT_COUNT; count > 0;)
{
delay_us(5);
// QEA and QEB change at a rate of 2 KHz (0.5 ms) at maximum velocity.
// Thus, in order to detect changes in the position, we must wait around
// 1 second for greater safety.
delay_s(1);
// Compare the previous and current state of the motor step counter
// register to see if there have been any changes in motor position.
curr_steps = motor_steps[MOTOR_B];
count -= 1 - (curr_steps - prev_steps > 0);
count -= 1 - (curr_steps == prev_steps);
}
mcuicom_send(CMDEND);
}
Expand All @@ -1989,9 +1999,14 @@ inline void check_halt_motor_c(void)
int count, prev_steps = motor_steps[MOTOR_C], curr_steps;
for (count = HALT_COUNT; count > 0;)
{
delay_us(5);
// QEA and QEB change at a rate of 2 KHz (0.5 ms) at maximum velocity.
// Thus, in order to detect changes in the position, we must wait around
// 1 second for greater safety.
delay_s(1);
// Compare the previous and current state of the motor step counter
// register to see if there have been any changes in motor position.
curr_steps = motor_steps[MOTOR_C];
count -= 1 - (curr_steps - prev_steps > 0);
count -= 1 - (curr_steps == prev_steps);
}
mcuicom_send(CMDEND);
}
Expand All @@ -2001,9 +2016,14 @@ inline void check_halt_motor_d(void)
int count, prev_steps = motor_steps[MOTOR_D], curr_steps;
for (count = HALT_COUNT; count > 0;)
{
delay_us(5);
// QEA and QEB change at a rate of 2 KHz (0.5 ms) at maximum velocity.
// Thus, in order to detect changes in the position, we must wait around
// 1 second for greater safety.
delay_s(1);
// Compare the previous and current state of the motor step counter
// register to see if there have been any changes in motor position.
curr_steps = motor_steps[MOTOR_D];
count -= 1 - (curr_steps - prev_steps > 0);
count -= 1 - (curr_steps == prev_steps);
}
mcuicom_send(CMDEND);
}
Expand All @@ -2013,9 +2033,14 @@ inline void check_halt_motor_e(void)
int count, prev_steps = motor_steps[MOTOR_E], curr_steps;
for (count = HALT_COUNT; count > 0;)
{
delay_us(5);
// QEA and QEB change at a rate of 2 KHz (0.5 ms) at maximum velocity.
// Thus, in order to detect changes in the position, we must wait around
// 1 second for greater safety.
delay_s(1);
// Compare the previous and current state of the motor step counter
// register to see if there have been any changes in motor position.
curr_steps = motor_steps[MOTOR_E];
count -= 1 - (curr_steps - prev_steps > 0);
count -= 1 - (curr_steps == prev_steps);
}
mcuicom_send(CMDEND);
}
Expand All @@ -2025,9 +2050,14 @@ inline void check_halt_motor_f(void)
int count, prev_steps = motor_steps[MOTOR_F], curr_steps;
for (count = HALT_COUNT; count > 0;)
{
delay_us(5);
// QEA and QEB change at a rate of 2 KHz (0.5 ms) at maximum velocity.
// Thus, in order to detect changes in the position, we must wait around
// 1 second for greater safety.
delay_s(1);
// Compare the previous and current state of the motor step counter
// register to see if there have been any changes in motor position.
curr_steps = motor_steps[MOTOR_F];
count -= 1 - (curr_steps - prev_steps > 0);
count -= 1 - (curr_steps == prev_steps);
}
mcuicom_send(CMDEND);
}

0 comments on commit f65a15e

Please sign in to comment.