From 31f85163b5981a78a2b6704168d0ae12929b53be Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 31 May 2011 09:39:16 +0200 Subject: digital/mimot: better find zero/limit --- digital/ai/src/twi_master/mimot.c | 34 ++++++++++++++++++++++++++++------ digital/ai/src/twi_master/mimot.h | 10 ++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) (limited to 'digital/ai/src') diff --git a/digital/ai/src/twi_master/mimot.c b/digital/ai/src/twi_master/mimot.c index c3b82823..6159e6c9 100644 --- a/digital/ai/src/twi_master/mimot.c +++ b/digital/ai/src/twi_master/mimot.c @@ -165,20 +165,42 @@ mimot_move_motor1_absolute (uint16_t position, uint8_t speed) void mimot_motor0_zero_position (int8_t speed) +{ + mimot_motor0_find_zero (speed, 0, 0); +} + +void +mimot_motor1_zero_position (int8_t speed) +{ + mimot_motor1_find_zero (speed, 0, 0); +} + +void +mimot_motor0_find_zero (int8_t speed, uint8_t use_switch, + uint16_t reset_position) { uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE); buffer[0] = 'B'; - buffer[1] = speed; - twi_master_send_buffer (2); + buffer[1] = 0; + buffer[2] = speed; + buffer[3] = use_switch; + buffer[4] = v16_to_v8 (reset_position, 1); + buffer[5] = v16_to_v8 (reset_position, 0); + twi_master_send_buffer (6); } void -mimot_motor1_zero_position (int8_t speed) +mimot_motor1_find_zero (int8_t speed, uint8_t use_switch, + uint16_t reset_position) { uint8_t *buffer = twi_master_get_buffer (MIMOT_SLAVE); - buffer[0] = 'C'; - buffer[1] = speed; - twi_master_send_buffer (2); + buffer[0] = 'B'; + buffer[1] = 1; + buffer[2] = speed; + buffer[3] = use_switch; + buffer[4] = v16_to_v8 (reset_position, 1); + buffer[5] = v16_to_v8 (reset_position, 0); + twi_master_send_buffer (6); } void diff --git a/digital/ai/src/twi_master/mimot.h b/digital/ai/src/twi_master/mimot.h index 97575b0d..c59c1608 100644 --- a/digital/ai/src/twi_master/mimot.h +++ b/digital/ai/src/twi_master/mimot.h @@ -92,6 +92,16 @@ mimot_motor0_zero_position (int8_t speed); void mimot_motor1_zero_position (int8_t speed); +/** Find zero position. */ +void +mimot_motor0_find_zero (int8_t speed, uint8_t use_switch, + uint16_t reset_position); + +/** Find zero position. */ +void +mimot_motor1_find_zero (int8_t speed, uint8_t use_switch, + uint16_t reset_position); + /** Clamp motor0. */ void mimot_motor0_clamp (int8_t speed, int16_t pwm); -- cgit v1.2.3