c't

c't-Projekte - Mailinglisten


[Voriger (Datum)] [Nächster (Datum)] [Voriger (Thread)] [Nächster (Thread)]
[Nach Datum][Nach Thread]

[ct-bot] neues Verhalten bot_cancel_behaviour

Absender: Frank Menzel
Datum: Fr, 19.10.2007 20:45:13
In-reply-to: <9C5B98E6-2422-467F-BCAC-EF768BA1FF6C@xxxxxxxxxxxxxxx>


Hallo,
anbei ein kleines Verhalten, welches durch Deklarieren einer
check-Funktion ein anderes Verhalten deaktivieren kann.
So kann z.B. das follow_maze-Verhalten (Wandfolger) beendet werden,
sobald der bot auf eine Linie fährt und der Linienfolger kann nun
übernehmen. Dazu muß die Checkfunktion nur True liefern, sobald die
Liniensensoren feuern. Oder der bot fährt gewisse Strecke voraus mit
offener Klappe via bot_drive_distance und das Verhalten wird beendet,
sobald sensTrans ein eingefangenes Objekt erkennt. Oder er dreht sich
360 Grad via bot_turn und hört damit sofort auf, sobald ein Objekt zum
Einfangen während der Drehung erkannt wird, catch_pillar kann dieses
dann aufnehmen.
Der Einsatz ist vielfältig...

Gruß, Frank Menzel
Index: C:/botneu/ct-Bot/bot-logic/bot-logik.c
===================================================================
--- C:/botneu/ct-Bot/bot-logic/bot-logik.c	(revision 1288)
+++ C:/botneu/ct-Bot/bot-logic/bot-logik.c	(working copy)
@@ -154,6 +154,10 @@
  	    register_emergency_proc(&hang_on_handler);
 	#endif
 
+        #ifdef BEHAVIOUR_CANCEL_BEHAVIOUR_AVAILABLE
+		insert_behaviour_to_list(&behaviour, new_behaviour(154, bot_cancel_behaviour_behaviour,INACTIVE));
+	#endif
+
 	#ifdef BEHAVIOUR_SCAN_AVAILABLE
 		// Verhalten, das die Umgebung des Bots on-the fly beim fahren scannt
 		insert_behaviour_to_list(&behaviour, new_behaviour(202, bot_scan_onthefly_behaviour,ACTIVE));
Index: C:/botneu/ct-Bot/bot-logic/behaviour_cancel_behaviour.c
===================================================================
--- C:/botneu/ct-Bot/bot-logic/behaviour_cancel_behaviour.c	(revision 0)
+++ C:/botneu/ct-Bot/bot-logic/behaviour_cancel_behaviour.c	(revision 0)
@@ -0,0 +1,93 @@
+/*
+ * c't-Bot
+ *
+ * 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 	behaviour_cancel_behaviour.c
+ * @brief 	deaktiviert ein anderes Verhalten in Abhaengigkeit einer Check-Funktion;
+ *          so kann z.B. der Wandfolger (bot_follow_maze) beendet werden, falls dieser auf
+ *          eine Linie faehrt und der Linienfolger kann nun uebernehmen 
+ * @author 	Frank Menzel (Menzelfr@xxxxxxx)
+ * @date 	19.10.2007
+ */
+
+#include "bot-logic/bot-logik.h"
+
+#ifdef BEHAVIOUR_CANCEL_BEHAVIOUR_AVAILABLE
+
+static uint8 cancel_state = 0;	  /*!< Status des cancel-Verhaltens */
+
+/*!
+ * Abbruchfunktion des Verhaltens()
+ * Die Funktion muss True (1) zurueckgeben, wenn abgebrochen werden soll, sonst False (0).
+ */
+ static int8 (*check_function)(void)=0;
+ 
+/*!
+ * Das Verhalten, welches deaktiviert werden soll mittels der check_function
+ */
+ void (*BehaviourFuncCancel) (struct _Behaviour_t *data)=0;
+
+/*!
+ * Verhalten zum Deaktivieren eines anderen Verhaltens
+ * @param *data	Verhaltensdatensatz
+ */
+void bot_cancel_behaviour_behaviour(Behaviour_t * data) {
+
+switch (cancel_state) {
+	case 0:
+	    // gibt es keine Abbruchfunktion oder abzubrechendes Verhalten, dann ist Schluss
+		if (!check_function || !BehaviourFuncCancel ) {   // nicht definiert, Verhalten wird beendet
+		  cancel_state = 1;  
+		  break;
+		}
+		
+		if (check_function && (*check_function)()) { // wenn definiert und Abbruchbedingung erfuellt
+		  // hier ist die Bedingung erfuellt und das Verhalten wird deaktiviert
+		  deactivateBehaviour(BehaviourFuncCancel);
+		  cancel_state = 1;  // Bedingung erfuellt, Verhalten wird beendet
+		  break;
+		}
+		break;
+	default:
+	    // sicherheitshalber 
+	    cancel_state = 0; check_function=0;
+	    BehaviourFuncCancel=0;	    
+		return_from_behaviour(data);
+		break;
+	}
+
+}
+
+/*!
+ * Botenfunktion zum Deaktivieren eines Verhaltens, wenn die Abbruchbedingung erfuellt ist
+ * @param	*caller Verhaltensdatensatz des Aufrufers
+ * @param   BehaviourFunc abzubrechendes Verhalten
+ * @param   *check Zeiger auf die Abbruchfunktion; liefert diese True, wird das Verhalten beendet
+ */
+void bot_cancel_behaviour(Behaviour_t * caller, void (*BehaviourFunc) (struct _Behaviour_t *data), 
+                          int8 (*check)(void)) {
+	
+	check_function = check;
+	BehaviourFuncCancel = BehaviourFunc;
+    cancel_state = 0;	
+	switch_to_behaviour(caller, bot_cancel_behaviour_behaviour, OVERRIDE);
+}
+
+
+#endif	// BEHAVIOUR_CANCEL_BEHAVIOUR_AVAILABLE
Index: C:/botneu/ct-Bot/include/bot-logic/behaviour_cancel_behaviour.h
===================================================================
--- C:/botneu/ct-Bot/include/bot-logic/behaviour_cancel_behaviour.h	(revision 0)
+++ C:/botneu/ct-Bot/include/bot-logic/behaviour_cancel_behaviour.h	(revision 0)
@@ -0,0 +1,54 @@
+/*
+ * c't-Bot
+ *
+ * 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 	behaviour_cancel_behaviour.h
+ * @brief 	deaktiviert ein anderes Verhalten in Abhaengigkeit einer Check-Funktion;
+ *          so kann z.B. der Wandfolger (bot_follow_maze) beendet werden, falls dieser auf
+ *          eine Linie faehrt und der Linienfolger kann nun uebernehmen 
+ *
+ * @author 	Frank Menzel (Menzelfr@xxxxxxx)
+ * @date 	19.10.2007
+*/
+
+#ifndef BEHAVIOUR_CANCEL_H_
+#define BEHAVIOUR_CANCEL_H_
+
+#include "ct-Bot.h"
+#include "bot-logic/bot-logik.h"
+
+#ifdef BEHAVIOUR_CANCEL_BEHAVIOUR_AVAILABLE
+
+/*!
+ * Verhalten zum Deaktivieren eines anderen Verhaltens
+ * @param *data	Verhaltensdatensatz
+ */
+void bot_cancel_behaviour_behaviour(Behaviour_t * data) ;
+
+/*!
+ * Botenfunktion zum Deaktivieren eines Verhaltens, wenn die Abbruchbedingung erfuellt ist
+ * @param	*caller Verhaltensdatensatz des Aufrufers
+ * @param   BehaviourFunc abzubrechendes Verhalten
+ * @param   *check Zeiger auf die Abbruchfunktion; liefert diese True, wird das Verhalten beendet
+ */
+void bot_cancel_behaviour(Behaviour_t * caller, void (*BehaviourFunc) (struct _Behaviour_t *data), int8 (*check)(void)); 
+#endif
+
+#endif /*BEHAVIOUR_CANCEL_H_*/
Index: C:/botneu/ct-Bot/include/bot-logic/available_behaviours.h
===================================================================
--- C:/botneu/ct-Bot/include/bot-logic/available_behaviours.h	(revision 1288)
+++ C:/botneu/ct-Bot/include/bot-logic/available_behaviours.h	(working copy)
@@ -43,6 +43,8 @@
 
 #define BEHAVIOUR_REMOTECALL_AVAILABLE /*!< Nehmen wir Remote-kommandos entgegen? */
 
+#define BEHAVIOUR_CANCEL_BEHAVIOUR_AVAILABLE /*!< Deaktivieren eines Verhaltens wenn Abbruchbedingung erfuellt */
+
 //#define BEHAVIOUR_CALIBRATE_PID_AVAILABLE	/*!< Kalibrierungsverhalten fuer Motorregelung vorhanden? */
 //#define BEHAVIOUR_CALIBRATE_SHARPS_AVAILABLE	/*!< Kalibrierungsverhalten fuer Distanzsensoren vorhanden? */
 
@@ -170,5 +172,7 @@
 
 #include "bot-logic/behaviour_delay.h"
 
+#include "bot-logic/behaviour_cancel_behaviour.h"
+
 #endif	// BEHAVIOUR_AVAILABLE
 #endif	/*AVAILABLE_BEHAVIOURS_H_*/
Index: C:/botneu/ct-Bot/Changelog.txt
===================================================================
--- C:/botneu/ct-Bot/Changelog.txt	(revision 1288)
+++ C:/botneu/ct-Bot/Changelog.txt	(working copy)
@@ -1,5 +1,7 @@
 CHANGELOG fuer c't-Bot
 ======================
+2007-10-19 Frank Menzel  [Menzelfr@xxxxxxx]: deaktiviert ein anderes Verhalten in Abhaengigkeit einer Check-Funktion
+
 2007-10-18 Timo Sandmann [mail@xxxxxxxxxxxxxxx]: interruptbasierten I2C-Treiber und Unterstuetzung fuer Kompass CMPS03 hinzugefuegt
 
 2007-10-17 Timo Sandmann [mail@xxxxxxxxxxxxxxx]: Verhalten goto_pos entworfen, das eine x/y-Position auf einer Kreisbahn anfaehrt und dabei Fehler korrigiert (genauer als goto_xy), ausserdem math_utils.c angelegt und Code etwas aufgeraeumt
Index: C:/botneu/ct-Bot/.settings/org.eclipse.cdt.core.prefs
===================================================================
--- C:/botneu/ct-Bot/.settings/org.eclipse.cdt.core.prefs	(revision 0)
+++ C:/botneu/ct-Bot/.settings/org.eclipse.cdt.core.prefs	(revision 0)
@@ -0,0 +1,3 @@
+#Fri Oct 19 20:22:48 CEST 2007
+eclipse.preferences.version=1
+indexerId=org.eclipse.cdt.core.fastIndexer