summaryrefslogtreecommitdiffhomepage
path: root/digital/io
diff options
context:
space:
mode:
authorNicolas Schodet2010-04-07 23:50:36 +0200
committerNicolas Schodet2010-04-07 23:50:36 +0200
commit760a56ba0746070e205184a15f0b05ef7b6304df (patch)
treed75a5bf99dbced32a86e247b285ae235e7fdd151 /digital/io
parentc4556705ce9cb0fc517a3d5ae89b96e8c1db756c (diff)
digital/io: forget sharps
Diffstat (limited to 'digital/io')
-rw-r--r--digital/io/README6
-rw-r--r--digital/io/src/Makefile2
-rw-r--r--digital/io/src/ai_move_cb.c45
-rw-r--r--digital/io/src/eeprom.avr.c23
-rw-r--r--digital/io/src/main.c99
-rw-r--r--digital/io/src/main.h7
-rw-r--r--digital/io/src/move.c2
-rw-r--r--digital/io/src/move.fsm2
-rw-r--r--digital/io/src/sharp.c254
-rw-r--r--digital/io/src/sharp.h145
-rw-r--r--digital/io/src/simu.host.c21
-rw-r--r--digital/io/src/trace.trc1
-rw-r--r--digital/io/tools/io/init.py2
-rw-r--r--digital/io/tools/io/io.py2
14 files changed, 21 insertions, 590 deletions
diff --git a/digital/io/README b/digital/io/README
index 47820383..8aa66ce5 100644
--- a/digital/io/README
+++ b/digital/io/README
@@ -1,8 +1,8 @@
io - Input & Output with Artificial Intelligence (ai) support on AVR.
-The io card is used to control and get information from the sensors (like
-sharps), to control the asserv card (to move the bot) and to make the
-choices of what to do (ai).
+The io card is used to control and get information from the sensors, to
+control the asserv card (to move the bot) and to make the choices of what to
+do (ai).
Copyright (C) 2008 Dufour Jrmy
diff --git a/digital/io/src/Makefile b/digital/io/src/Makefile
index 9bd93afd..2896d528 100644
--- a/digital/io/src/Makefile
+++ b/digital/io/src/Makefile
@@ -3,7 +3,7 @@ BASE = ../../avr
# Name of the program to build.
PROGS = io
# Sources to compile.
-io_SOURCES = main.c asserv.c servo.avr.c eeprom.avr.c sharp.c pwm.c \
+io_SOURCES = main.c asserv.c servo.avr.c eeprom.avr.c pwm.c \
switch.avr.c chrono.c main_timer.avr.c servo_pos.c \
simu.host.c contact.c
# Modules needed for IO.
diff --git a/digital/io/src/ai_move_cb.c b/digital/io/src/ai_move_cb.c
index f130f139..4fe68f86 100644
--- a/digital/io/src/ai_move_cb.c
+++ b/digital/io/src/ai_move_cb.c
@@ -32,7 +32,6 @@
#include "asserv.h"
#include "playground.h"
#include "move.h"
-#include "sharp.h"
#include "bot.h"
#include "trace_event.h"
@@ -50,22 +49,6 @@
#define MOVE_REAL_OBSTACLE_RADIUS 150
/**
- * The sharp distance between the bot and the obstacle.
- */
-#define MOVE_SHARP_DISTANCE 300
-
-/**
- * The distance between the axis of the bot and the front sharp.
- */
-#define MOVE_AXIS_FRONT_SHARP 150
-
-/**
- * The standard distance of the obstacle.
- */
-#define MOVE_OBSTACLE_DISTANCE \
- (MOVE_REAL_OBSTACLE_RADIUS + MOVE_SHARP_DISTANCE + MOVE_AXIS_FRONT_SHARP)
-
-/**
* The radius of the obstacle for the path module.
* It corresponds to the real radius of the obstacle plus the distance you
* want to add to avoid it.
@@ -78,22 +61,6 @@
#define MOVE_OBSTACLE_VALIDITY (6 * 225)
/**
- * Cycles count to ignore sharp event in the main loop.
- */
-#define MOVE_MAIN_IGNORE_SHARP_EVENT (3 * 225)
-
-/**
- * Number of cycles to wait before trying to read the sharps values again when
- * we are stopped.
- */
-#define MOVE_WAIT_TIME_FOR_POOLING_SHARP (MOVE_MAIN_IGNORE_SHARP_EVENT)
-
-/**
- * A detection offset for the sharps.
- */
-#define MOVE_DETECTION_OFFSET 250
-
-/**
* Verify after the computation of the obstacle, this shall only be called
* after the function move_compute_obstacle_position.
* \return true if the position computed is in the table, false otherwise.
@@ -101,10 +68,10 @@
uint8_t
move_obstacle_in_table (move_position_t pos)
{
- if ((pos.x <= PG_WIDTH - MOVE_DETECTION_OFFSET)
- && (pos.x > MOVE_DETECTION_OFFSET)
- && (pos.y <= PG_LENGTH - MOVE_DETECTION_OFFSET)
- && (pos.y > MOVE_DETECTION_OFFSET))
+ if ((pos.x <= PG_WIDTH)
+ && (pos.x > 0)
+ && (pos.y <= PG_LENGTH)
+ && (pos.y > 0))
return 0x1;
else
return 0x0;
@@ -219,8 +186,6 @@ move_obstacle_here (void)
move_data.obstacle.y);
TRACE (TRACE_MOVE__OBSTACLE, move_data.obstacle.x,
move_data.obstacle.y);
- TRACE (TRACE_MOVE__SHARP, sharp_get_raw (0), sharp_get_raw (1),
- sharp_get_raw (2), sharp_get_raw (3), sharp_get_raw (4));
}
else
{
@@ -368,8 +333,6 @@ ai__MOVE_MOVING_BACKWARD_TO_TURN_FREELY__bot_move_failed (void)
fsm_branch_t
ai__MOVE_WAIT_FOR_CLEAR_PATH__state_timeout (void)
{
- if (sharp_path_obstrued (asserv_get_last_moving_direction ()))
- move_obstacle_here ();
uint8_t ret = move_get_next_position (&move_data.intermediate);
if (ret == 1)
{
diff --git a/digital/io/src/eeprom.avr.c b/digital/io/src/eeprom.avr.c
index c958910f..a32b9606 100644
--- a/digital/io/src/eeprom.avr.c
+++ b/digital/io/src/eeprom.avr.c
@@ -28,7 +28,6 @@
#include "servo.h" /* SERVO_NUMBER */
#include "servo_pos.h"
-#include "sharp.h" /* sharp_threshold */
#include <avr/eeprom.h> /* eeprom_{read,write}_byte */
@@ -48,7 +47,7 @@
* @warning: you must update this value every time you change the structure of
* data stored into the EEPROM.
*/
-#define EEPROM_PARAM_KEY 0x06
+#define EEPROM_PARAM_KEY 0x07
/** @} */
@@ -58,7 +57,6 @@ eeprom_load_param ()
{
uint8_t compt;
uint8_t pos;
- uint16_t *ptr16;
/* The parameters start at the given address */
uint8_t *ptr8 = (uint8_t *) EEPROM_PARAM_START;
@@ -73,15 +71,6 @@ eeprom_load_param ()
for (pos = 0; pos < SERVO_POS_NUMBER; pos++)
servo_pos_high_time[compt][pos] = eeprom_read_byte(ptr8++);
}
-
- /* Load sharp module data */
- ptr16 = (uint16_t *) ptr8;
- /* Threshold values, high and low */
- for (compt = 0; compt < SHARP_NUMBER; compt++)
- {
- sharp_threshold[compt][0] = eeprom_read_word (ptr16++);
- sharp_threshold[compt][1] = eeprom_read_word (ptr16++);
- }
}
/* Store parameters in the EEPROM. */
@@ -89,7 +78,6 @@ void
eeprom_save_param ()
{
uint8_t compt, pos;
- uint16_t *ptr16;
/* The parameters start at the given address */
uint8_t *ptr8 = (uint8_t *) EEPROM_PARAM_START;
@@ -102,15 +90,6 @@ eeprom_save_param ()
for (pos = 0; pos < SERVO_POS_NUMBER; pos++)
eeprom_write_byte (ptr8++, servo_pos_high_time[compt][pos]);
}
-
- /* Store sharp module data */
- ptr16 = (uint16_t *) ptr8;
- /* Threshold values, high and low */
- for (compt = 0; compt < SHARP_NUMBER; compt++)
- {
- eeprom_write_word (ptr16++, sharp_threshold[compt][0]);
- eeprom_write_word (ptr16++, sharp_threshold[compt][1]);
- }
}
/* Clear parameters in the EEPROM by invalidating the key. */
diff --git a/digital/io/src/main.c b/digital/io/src/main.c
index ecc115af..42a7ae17 100644
--- a/digital/io/src/main.c
+++ b/digital/io/src/main.c
@@ -46,7 +46,6 @@
#include "bot.h"
#include "servo_pos.h"
#include "chrono.h" /* chrono_end_match */
-#include "sharp.h" /* sharp module */
#include "pwm.h"
#include "playground.h"
#include "contact.h"
@@ -76,17 +75,6 @@ enum team_color_e bot_color;
uint8_t main_post_event_for_top_fsm = 0xFF;
/**
- * Do not generate sharps event for FSM during a certain count of cycles.
- */
-uint16_t main_sharp_ignore_event;
-
-/**
- * Sharps stats counters.
- */
-uint8_t main_stats_sharps, main_stats_sharps_cpt;
-uint8_t main_stats_sharps_interpreted_, main_stats_sharps_interpreted_cpt_;
-
-/**
* Asserv stats counters.
*/
static uint8_t main_stats_asserv_, main_stats_asserv_cpt_;
@@ -160,18 +148,6 @@ main_event_to_fsm (void)
/* Post the event */
FSM_HANDLE_EVENT (&ai_fsm, save_event);
}
- /* Sharps event for move FSM */
- /* Get the current direction of the bot */
- uint8_t moving_direction = asserv_get_last_moving_direction ();
- /* If we are moving */
- if (moving_direction)
- {
- if (sharp_path_obstrued (moving_direction))
- {
- /* Generate an event for move FSM */
- FSM_HANDLE_EVENT (&ai_fsm, AI_EVENT_obstacle_in_front);
- }
- }
/* TODO: Check other sensors */
}
@@ -204,8 +180,6 @@ main_init (void)
fsm_init (&ai_fsm);
/* Start FSM. */
fsm_handle_event (&ai_fsm, AI_EVENT_start);
- /* Sharp module */
- sharp_init ();
/* PWM module */
pwm_init ();
/* Servo pos init. */
@@ -274,48 +248,10 @@ main_loop (void)
switch_update ();
/* Update path module */
path_decay ();
- /* Sharps module */
- /* Update the ignore sharp event flag */
- if (main_sharp_ignore_event)
- main_sharp_ignore_event--;
- /* Update sharps */
- sharp_update ();
-
/* Manage events. */
main_event_to_fsm ();
}
- /* Send Sharps raw stats. */
- if (main_stats_sharps && !--main_stats_sharps_cpt)
- {
- uint8_t count;
- uint8_t cache[SHARP_NUMBER * 2];
- /* Reset counter */
- main_stats_sharps_cpt = main_stats_sharps;
- for (count = 0; count < SHARP_NUMBER; count++)
- {
- uint16_t tmp = sharp_get_raw (count);
- cache[count * 2] = v16_to_v8 (tmp, 1);
- cache[count * 2 + 1] = v16_to_v8 (tmp, 0);
- }
- proto_send ('H', 2 * SHARP_NUMBER, cache);
- }
- /* Send Sharps interpreted stats. */
- if (main_stats_sharps_interpreted_ &&
- !--main_stats_sharps_interpreted_cpt_)
- {
- uint8_t count;
- uint8_t cache[SHARP_NUMBER];
- /* Reset counter */
- main_stats_sharps_interpreted_cpt_ =
- main_stats_sharps_interpreted_;
- for (count = 0; count < SHARP_NUMBER; count++)
- {
- cache[count] = sharp_get_interpreted (count);
- }
- proto_send ('I', SHARP_NUMBER, cache);
- }
-
/* Send asserv stats if needed */
if (main_stats_asserv_ && !--main_stats_asserv_cpt_)
{
@@ -379,13 +315,6 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
proto_send1b ('S', switch_get_color () << 1 | switch_get_jack ());
break;
- case c ('H', 1):
- /* Print raw stats for sharps.
- * - 1b: frequency of sharp stats.
- */
- main_stats_sharps_cpt = main_stats_sharps = args[0];
- break;
-
case c ('M', 1):
/* Main stats timer.
* - 1b: 1 to enable, 0 to disable.
@@ -393,24 +322,6 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
main_stats_timer_ = args[0];
break;
- case c ('I', 1):
- /* Print interpreted stats for sharps.
- * - 1b: frequency of sharp stats.
- */
- main_stats_sharps_interpreted_cpt_ = main_stats_sharps_interpreted_ =
- args[0];
- break;
-
- case c ('h', 5):
- /* Configure sharps threshold.
- * - 1b: sharp id number;
- * - 2b: sharp low threshold;
- * - 2b: sharp high threshold.
- */
- sharp_set_threshold (args[0], v8_to_v16 (args[1], args[2]),
- v8_to_v16 (args[3], args[4]));
- break;
-
case c ('w', 4):
/* Set PWM.
* - 1w: PWM value id number;
@@ -448,16 +359,6 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
proto_send ('p', SERVO_POS_NUMBER,
servo_pos_high_time[compt]);
}
- /* Sharp */
- for (compt = 0; compt < SHARP_NUMBER; compt++)
- {
- proto_send5b
- ('h', compt,
- v16_to_v8 (sharp_threshold[compt][0], 1),
- v16_to_v8 (sharp_threshold[compt][0], 0),
- v16_to_v8 (sharp_threshold[compt][1], 1),
- v16_to_v8 (sharp_threshold[compt][1], 0));
- }
}
break;
}
diff --git a/digital/io/src/main.h b/digital/io/src/main.h
index 8791d5ed..15f1fce0 100644
--- a/digital/io/src/main.h
+++ b/digital/io/src/main.h
@@ -33,11 +33,4 @@
*/
extern uint8_t main_post_event_for_top_fsm;
-/**
- * Do not generate sharps event for FSM during a certain count of cycles.
- * This flag is used by the move FSM to prevent it from being alerted by the
- * main loop that there is an object in from of the bot.
- */
-extern uint16_t main_sharp_ignore_event;
-
#endif /* main_h */
diff --git a/digital/io/src/move.c b/digital/io/src/move.c
index eec8799d..4343e60f 100644
--- a/digital/io/src/move.c
+++ b/digital/io/src/move.c
@@ -43,8 +43,6 @@ move_start (asserv_position_t position, uint8_t backward)
move_data.final.a = position.a;
move_data.backward_movement_allowed = backward;
move_data.final_move = 0;
- /* Reset move FSM flags */
- main_sharp_ignore_event = 0;
/* Start the FSM. */
fsm_handle_event (&ai_fsm, AI_EVENT_move_start);
}
diff --git a/digital/io/src/move.fsm b/digital/io/src/move.fsm
index c278c748..c1bfa9e9 100644
--- a/digital/io/src/move.fsm
+++ b/digital/io/src/move.fsm
@@ -19,7 +19,7 @@ Events:
move_start
initialize the FSM and start the movement directly.
obstacle_in_front
- the bot has seen something (with the sharps) (front is the same when going backward).
+ the bot has seen something (front is the same when going backward).
MOVE_IDLE:
move_start -> MOVE_MOVING
diff --git a/digital/io/src/sharp.c b/digital/io/src/sharp.c
deleted file mode 100644
index ec38a67b..00000000
--- a/digital/io/src/sharp.c
+++ /dev/null
@@ -1,254 +0,0 @@
-/* sharp.c */
-/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
- *
- * Copyright (C) 2008 Dufour Jérémy
- *
- * APBTeam:
- * Web: http://apbteam.org/
- * Email: team AT apbteam DOT org
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * }}} */
-
-#include "common.h"
-#include "sharp.h"
-
-#include "modules/adc/adc.h" /* ADC functions */
-#include "modules/utils/utils.h"
-#include "io.h"
-
-/** Sharp conversion table.
- * The first value is the distance in millimeters, the second on the distance
- * returned by the sharps.
- */
-uint16_t sharp_conv_table[SHARP_NB_ELEMENT_TABLE_CONV][2] =
- {{650, 100}, {550, 120}, {450, 140},
- {400, 160}, {350, 180}, {300, 200},
- {250, 220}, {200, 280}, {140, 400},
- {100, 480}, {90, 500}, {80, 500}};
-
-
-/**
- * Raw filter iteration.
- * How many values should we get when reading a sharp?
- */
-#define SHARP_RAW_FILTER 2
-
-/**
- * Cached array of raw sharp values.
- */
-uint16_t sharp_values_[SHARP_NUMBER];
-
-/**
- * Low (0 index) and high (1 index) thresholds for interpreted sharp values.
- */
-uint16_t sharp_threshold[SHARP_NUMBER][2];
-
-/**
- * Filter counter for each sharp.
- */
-uint8_t sharp_filter_[SHARP_NUMBER];
-
-/**
- * Sharp cache interpreted.
- */
-uint8_t sharp_cache_interpreted_[SHARP_NUMBER];
-
-/**
- * Filter number value before changing state.
- */
-#define SHARP_FILTER_NUMBER 4
-
-/**
- * Previous sharp interpreted values.
- */
-uint8_t sharp_previous_values_[SHARP_NUMBER];
-
-/**
- * Update the interpreted values.
- * @param sharp_id the sharp id number
- * @return the interpreted value of the sharp.
- */
-uint8_t
-sharp_update_interpreted (uint8_t sharp_id)
-{
- uint8_t current_state;
- /* Check if sharp state is lower than the low threshold */
- if (sharp_values_[sharp_id] < sharp_threshold[sharp_id][0])
- /* Update current state seen by the sharp */
- current_state = 0;
- /* Check if sharp state is higher than the high threshold */
- else if (sharp_values_[sharp_id] > sharp_threshold[sharp_id][1])
- /* Update current state seen by the sharp */
- current_state = 1;
- /* In the middle */
- else
- /* Return the previous value */
- return sharp_previous_values_[sharp_id];
-
- /* Filter the value */
- /* Check if previous value is the current state */
- if (sharp_previous_values_[sharp_id] == current_state)
- {
- /* Reset filter counter */
- sharp_filter_[sharp_id] = SHARP_FILTER_NUMBER;
- /* Return current state */
- return current_state;
- }
- /* Otherwise, check if this sharp value has been the same
- * SHARP_FILTER_NUMBER times */
- else if (--sharp_filter_[sharp_id] == 0)
- {
- /* Current value change (for SHARP_FILTER_NUMBER times)! */
- /* Update previous value */
- sharp_previous_values_[sharp_id] = current_state;
- /* Reset filter counter */
- sharp_filter_[sharp_id] = SHARP_FILTER_NUMBER;
- /* Return current state */
- return current_state;
- }
- else
- /* Return previous state */
- return sharp_previous_values_[sharp_id];
-}
-
-/* Initialize sharp module. */
-void
-sharp_init (void)
-{
- /* Pins are in input mode by default */
-
- /* ADC initialize */
- adc_init ();
-}
-
-/* Update read data from sharps. */
-void
-sharp_update (void)
-{
- static uint8_t sharp_filter_count = SHARP_RAW_FILTER;
- static uint8_t sharp_id = 0;
- static uint16_t min_value = 0xFFFF;
- uint16_t current;
-
- /* Start the capture */
- adc_start (sharp_id);
- /* Wait until ADC mesure is finished */
- while (!adc_checkf ())
- ;
- /* Get the value */
- current = adc_read ();
- /* Only keep the minimum. */
- min_value = UTILS_MIN (min_value, current);
- /* Filter decrement. */
- sharp_filter_count--;
-
- /* Enough reading? */
- if (!sharp_filter_count)
- {
- /* Store value. */
- sharp_values_[sharp_id] = min_value;
- /* Update interpreted cached value */
- sharp_cache_interpreted_[sharp_id] = sharp_update_interpreted
- (sharp_id);
- /* Next sharp. */
- sharp_id++;
- sharp_id %= SHARP_NUMBER;
- /* Reset. */
- min_value = 0xFFFF;
- sharp_filter_count = SHARP_RAW_FILTER;
- }
-}
-
-/* Get raw cached data from sharps. */
-uint16_t
-sharp_get_raw (uint8_t sharp_id)
-{
- /* Sanity check */
- if (sharp_id < SHARP_NUMBER)
- /* Return raw cached value */
- return sharp_values_[sharp_id];
- return 0;
-}
-
-/* Configure the thresholds of a sharp. */
-void
-sharp_set_threshold (uint8_t sharp_id, uint16_t low, uint16_t high)
-{
- /* Sanity check */
- if (sharp_id < SHARP_NUMBER)
- {
- /* Set low and high threshold */
- sharp_threshold[sharp_id][0] = low;
- sharp_threshold[sharp_id][1] = high;
- }
-}
-
-/* Get interpreted value from sharps. */
-uint8_t
-sharp_get_interpreted (uint8_t sharp_id)
-{
- return sharp_cache_interpreted_[sharp_id];
-}
-
-/* Is there an obstacle in front of the bot? */
-uint8_t
-sharp_path_obstrued (uint8_t moving_direction)
-{
- /* If we are moving forward */
- if (moving_direction == 1)
- {
- /* Use only front sharps */
- if (sharp_get_interpreted (SHARP_FRONT_LEFT) +
- sharp_get_interpreted (SHARP_FRONT_MIDDLE) +
- sharp_get_interpreted (SHARP_FRONT_RIGHT) >= 1)
- /* Something in front */
- return 1;
- }
- /* If we are moving backward */
- else if (moving_direction == 2)
- {
- /* Use only back sharps */
- if (sharp_get_interpreted (SHARP_BACK_LEFT) ||
- sharp_get_interpreted (SHARP_BACK_RIGHT))
- /* Something in front */
- return 1;
- }
- return 0;
-}
-
-/**
- * Get the distance of the sharp computed on the value. It does a search in the
- * table.
- * @param sharp_value the value of the seen by the sharp.
- * @return the value in mm of the object seen.
- */
-uint16_t
-sharp_get_distance_mm (uint16_t sharp_value)
-{
- uint8_t index;
-
- for (index = 1; index < SHARP_NB_ELEMENT_TABLE_CONV; index++)
- {
- if (sharp_conv_table[index][1] > sharp_value)
- {
- return sharp_conv_table[index - 1][0];
- }
- }
-
- return 0;
-}
-
diff --git a/digital/io/src/sharp.h b/digital/io/src/sharp.h
deleted file mode 100644
index 4b0eb1de..00000000
--- a/digital/io/src/sharp.h
+++ /dev/null
@@ -1,145 +0,0 @@
-#ifndef sharp_h
-#define sharp_h
-/* sharp.h */
-/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
- *
- * Copyright (C) 2008 Dufour Jérémy
- *
- * APBTeam:
- * Web: http://apbteam.org/
- * Email: team AT apbteam DOT org
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * }}} */
-
-/**
- * @file Module to control distance measuring sensors (sharp).
- * They can be used to detect obstacles, for example a bot.
- * It uses the Analog to Digital Converter (ADC) of the AVR to read and
- * understand data from the sharp sensors.
- * This module keep a value of the last read values from the sharp and update
- * it when calling the correct function.
- */
-
-/**
- * List of sharps supported (and their identifier).
- * Making a change to this list required an update to the EEPROM module key.
- */
-typedef enum sharp_list
-{
- /**
- * Front left sharp.
- */
- SHARP_FRONT_LEFT = 0,
- /**
- * Front middle sharp.
- */
- SHARP_FRONT_MIDDLE = 1,
- /**
- * Front right sharp.
- */
- SHARP_FRONT_RIGHT = 2,
- /**
- * Back left sharp.
- */
- SHARP_BACK_LEFT = 3,
- /**
- * Back right sharp.
- */
- SHARP_BACK_RIGHT = 4,
- /**
- * Middle back sharp. It used to know if there are some pucks in the back
- * of the bot.
- */
- SHARP_BACK_MIDDLE = 5,
- /**
- * Number of sharps.
- * It must be the last member.
- */
- SHARP_NUMBER
-} sharp_list;
-
-/** Sharps conversion table number of elements. */
-#define SHARP_NB_ELEMENT_TABLE_CONV 12
-
-/**
- * Low (0 index) and high (1 index) thresholds for interpreted sharp values.
- */
-extern uint16_t sharp_threshold[SHARP_NUMBER][2];
-
-/**
- * Initialize sharp module.
- */
-void sharp_init (void);
-
-/**
- * Update read data from sharps.
- * This function is blocking. To get the value you have to use the get
- * function (@a sharp_get_raw).
- */
-void sharp_update (void);
-
-/**
- * Get raw cached data from sharps.
- * It read the cached data (updated by the @a sharp_update function).
- * @param sharp_id the sharp id to get raw data from.
- * @return the raw data read from the sharps (0 is a non valid value).
- */
-uint16_t sharp_get_raw (uint8_t sharp_id);
-
-/**
- * Get the distance of the sharp computed on the value. It does a search in the
- * table.
- * @param sharp_value the value of the seen by the sharp.
- * @return the value in mm of the object seen.
- */
-uint16_t
-sharp_get_distance_mm (uint16_t sharp_value);
-
-/**
- * Configure the thresholds of a sharp.
- * @param sharp_id the sharp id to configure the thresholds.
- * @param low low threshold of the sharp.
- * @param high high threshold of the sharp.
- */
-void sharp_set_threshold (uint8_t sharp_id, uint16_t low, uint16_t high);
-
-/**
- * Get interpreted value from sharps.
- * It is used to know if there is something in front of the sharp.
- * @param sharp_id the sharp number to get interpreted value from.
- * @return
- * - 0 if there is nothing in front of the sharp.
- * - 1 if there is something in front of the sharp;
- * - other values when error occurs.
- */
-uint8_t sharp_get_interpreted (uint8_t sharp_id);
-
-/**
- * Is there an obstacle in front of the bot?
- * This function correctly handles the moving direction of the bot to check
- * only the necessary sharps.
- * @param moving_direction
- * - 1 when moving forward ;
- * - 2 when moving backward.
- * @return
- * - 0 if there is nothing in front ;
- * - 1 if there is an obstacle in front of the bot.
- */
-uint8_t
-sharp_path_obstrued (uint8_t moving_direction);
-
-#endif /* sharp_h */
diff --git a/digital/io/src/simu.host.c b/digital/io/src/simu.host.c
index e3c9fc69..5b1da61f 100644
--- a/digital/io/src/simu.host.c
+++ b/digital/io/src/simu.host.c
@@ -26,7 +26,6 @@
#include "simu.host.h"
#include "servo.h"
-#include "sharp.h"
#include "pwm.h"
#include "modules/utils/utils.h"
@@ -41,7 +40,7 @@ enum
MSG_SIMU_IO_JACK = 0xb0,
MSG_SIMU_IO_COLOR = 0xb1,
MSG_SIMU_IO_SERVO = 0xb2,
- MSG_SIMU_IO_SHARPS = 0xb3,
+ MSG_SIMU_IO_ADC = 0xb3,
MSG_SIMU_IO_PATH = 0xb4,
MSG_SIMU_IO_PWM = 0xb5,
MSG_SIMU_IO_CONTACT = 0xb6,
@@ -60,7 +59,7 @@ uint8_t servo_high_time_current_[SERVO_NUMBER];
/** Do not update too often, interface is too slow. */
uint8_t simu_servo_update = 10, simu_servo_update_cpt;
uint8_t simu_switch_update = 100, simu_switch_update_cpt;
-uint8_t simu_sharps_update = 9, simu_sharps_update_cpt;
+uint8_t simu_adc_update = 9, simu_adc_update_cpt;
uint8_t simu_pwm_update = 10, simu_pwm_update_cpt;
/** Sampled switches. */
@@ -88,7 +87,7 @@ simu_init (void)
PINC = 0x3f;
simu_servo_update_cpt = 1;
simu_switch_update_cpt = 1;
- simu_sharps_update_cpt = 1;
+ simu_adc_update_cpt = 1;
simu_pwm_update_cpt = 1;
}
@@ -139,14 +138,16 @@ simu_step (void)
if (!r)
simu_switches |= 2;
}
- /* Update sharps. */
- if (simu_sharps_update && !--simu_sharps_update_cpt)
+ /* Update ADC. */
+ if (simu_adc_update && !--simu_adc_update_cpt)
{
- simu_sharps_update_cpt = simu_sharps_update;
- m = mex_msg_new (MSG_SIMU_IO_SHARPS);
+ simu_adc_update_cpt = simu_adc_update;
+ m = mex_msg_new (MSG_SIMU_IO_ADC);
m = mex_node_request (m);
- uint8_t i;
- for (i = 0; i < SHARP_NUMBER; i++)
+ uint8_t i, n;
+ n = mex_msg_len (m) / 2;
+ assert (n < UTILS_COUNT (adc_values));
+ for (i = 0; i < n; i++)
mex_msg_pop (m, "H", &adc_values[i]);
mex_msg_delete (m);
}
diff --git a/digital/io/src/trace.trc b/digital/io/src/trace.trc
index 2d3cfb90..b61fc03e 100644
--- a/digital/io/src/trace.trc
+++ b/digital/io/src/trace.trc
@@ -5,4 +5,3 @@ EVENT main_timer__late "MainTimer: we are late."
EVENT fsm__handle_event from 1 event 1 to 1 "FSM: %i =%i=> %i."
EVENT move__go_to xs 2 ys 2 as 2 xd 2 yd 2 ad 2 "Move: (%d, %d, %x) -> (%d, %d, %x)."
EVENT move__obstacle x 2 y 2 "Move: obstacle a (%d, %d)."
-EVENT move__sharp s 2 s 2 s 2 s 2 s 2 "Sharps values: %x %x %x %x %x."
diff --git a/digital/io/tools/io/init.py b/digital/io/tools/io/init.py
index e0f816a2..e5d383af 100644
--- a/digital/io/tools/io/init.py
+++ b/digital/io/tools/io/init.py
@@ -2,6 +2,4 @@
host = dict (
servo_pos = ((1, 255), (255, 1), (1, 255), (1, 255), (1, 255),
(1, 255), (1, 255), (1, 255)),
- sharp_threshold = ((0x7f, 0x90), (0x7f, 0x90), (0x7f, 0x90),
- (0x7f, 0x90), (0x7f, 0x90), (0x7f, 0x90)),
)
diff --git a/digital/io/tools/io/io.py b/digital/io/tools/io/io.py
index fd755e71..ffd1e2e5 100644
--- a/digital/io/tools/io/io.py
+++ b/digital/io/tools/io/io.py
@@ -35,8 +35,6 @@ class Proto:
p = self.param
for i, t in enumerate (p['servo_pos']):
self.proto.send ('p', 'BBB', i, *t)
- for i, t in enumerate (p['sharp_threshold']):
- self.proto.send ('h', 'BHH', i, t[0], t[1])
def write_eeprom (self):
self.proto.send ('p', 'cc', 'E', 's')