From 9d3573134462335051e46b990e97e1d32bef4b29 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 31 Mar 2008 13:03:47 +0200 Subject: * digital/io/src: - adapted FSM to AVR program. --- digital/io/src/getsamples_cb.c | 75 ++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 28 deletions(-) (limited to 'digital/io/src/getsamples_cb.c') diff --git a/digital/io/src/getsamples_cb.c b/digital/io/src/getsamples_cb.c index 27f0d9b0..aeb7f586 100644 --- a/digital/io/src/getsamples_cb.c +++ b/digital/io/src/getsamples_cb.c @@ -1,12 +1,31 @@ -/* - * THIS IS AN AUTOMATICALLY GENERATED FILE, DO NOT EDIT! +/* getsamples_cb.c - getsamples FSM callbacks. */ +/* {{{ * - * Skeleton for get_samples callbacks implementation. + * Copyright (C) 2008 NĂ©lio Laranjeiro * - * - */ + * 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 "fsm.h" #include "getsamples_cb.h" -#include "getsamples_robo.h" +#include "getsamples.h" #include "asserv.h" /* @@ -14,13 +33,13 @@ * => FORWARD_CONTROL * Prepare the arm to the correct position. */ -getsamples_branch_t -getsamples__PREPARE_ARM__arm_moved (getsamples_t *user) +fsm_branch_t +getsamples__PREPARE_ARM__arm_moved (void) { // Try to end the position to the distributor. - asserv_set_x_position (user->distributor_x); + asserv_set_x_position (getsamples_data.distributor_x); // Go to the color distributor. - asserv_set_y_position (user->distributor_y); + asserv_set_y_position (getsamples_data.distributor_y); return getsamples_next (PREPARE_ARM, arm_moved); } @@ -29,8 +48,8 @@ getsamples__PREPARE_ARM__arm_moved (getsamples_t *user) * => TAKE_SAMPLES * End the position to the distributor. */ -getsamples_branch_t -getsamples__FORWARD_CONTROL__position_reached (getsamples_t *user) +fsm_branch_t +getsamples__FORWARD_CONTROL__position_reached (void) { // Take as many samples as necessary. This shall be updated to verify the asserv_move_arm (1666, 100); @@ -42,26 +61,26 @@ getsamples__FORWARD_CONTROL__position_reached (getsamples_t *user) * => GO_TO_POSITION * Go to the distributor. The distributor to reach shall be setted in the fsm structure. */ -getsamples_branch_t -getsamples__START__ok (getsamples_t *user) +fsm_branch_t +getsamples__START__ok (void) { - asserv_set_x_position (user->distributor_x - 20); - asserv_set_y_position (user->distributor_y - 20); + asserv_set_x_position (getsamples_data.distributor_x - 20); + asserv_set_y_position (getsamples_data.distributor_y - 20); return getsamples_next (START, ok); } -/** +/* * TAKE_SAMPLES =sample_took=> * no_more => BACKWARD * If the quantity of samples are tooked, then go backeward and conitnue classifying the samples. * more => TAKE_SAMPLES * Continue to take samples and classify the next sample. */ -getsamples_branch_t -getsamples__TAKE_SAMPLES__sample_took (getsamples_t *user) +fsm_branch_t +getsamples__TAKE_SAMPLES__sample_took (void) { // Decrement the samples counter. - if (user->samples) + if (getsamples_data.samples) { asserv_move_arm (1666, 100); return getsamples_next_branch (TAKE_SAMPLES, sample_took, more); @@ -69,9 +88,9 @@ getsamples__TAKE_SAMPLES__sample_took (getsamples_t *user) else { // Try to end the position to the distributor. - asserv_set_x_position (user->distributor_x - 20); + asserv_set_x_position (getsamples_data.distributor_x - 20); // Go to the color distributor. - asserv_set_y_position (user->distributor_y - 20); + asserv_set_y_position (getsamples_data.distributor_y - 20); return getsamples_next_branch (TAKE_SAMPLES, sample_took, no_more); } @@ -82,8 +101,8 @@ getsamples__TAKE_SAMPLES__sample_took (getsamples_t *user) * => END * Ending this state machine. */ -getsamples_branch_t -getsamples__BACKWARD__position_reached (getsamples_t *user) +fsm_branch_t +getsamples__BACKWARD__position_reached (void) { asserv_move_arm (5000, 100); return getsamples_next (BACKWARD, position_reached); @@ -94,8 +113,8 @@ getsamples__BACKWARD__position_reached (getsamples_t *user) * => GO_TO_POSITION * Go to another point before trying to go to this one again. */ -getsamples_branch_t -getsamples__GO_TO_POSITION__position_failed (getsamples_t *user) +fsm_branch_t +getsamples__GO_TO_POSITION__position_failed (void) { // TODO In this case i don't know what to do. return getsamples_next (GO_TO_POSITION, position_failed); @@ -106,8 +125,8 @@ getsamples__GO_TO_POSITION__position_failed (getsamples_t *user) * => PREPARE_ARM * Go to the position desired, it is very near the position of the distributor in case it is a ice distributor or sample distributor. */ -getsamples_branch_t -getsamples__GO_TO_POSITION__position_reached (getsamples_t *user) +fsm_branch_t +getsamples__GO_TO_POSITION__position_reached (void) { // Put the ARM in the position to allow the robot to take samples from the // distributor. -- cgit v1.2.3