Ich hab jetz ein programm gemacht womit wen er einen becher sieht auf ihn zufährt und dann wegschiebt und wenn er keinen siht dann nur im kreiß fährt abber ich weis jetz nicht wie ich es auch noch unterbringen kann dass er imring bleibt
Hier ist das eine programm
Code:
/***************************************************************************
 *   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 version 2 of the License,                *
 *   If you extend the program please maintain the list of authors.        *
 *   If you want to use this software for commercial purposes and you      *
 *   don't want to make it open source, please contact the authors for     *
 *   licensing.                                                            *
 ***************************************************************************/

#include "asuro.h"
#include <stdlib.h>

/*************************************************************************

	uint8_t objekt_sichtbar(uint8_t abstand)
 
 	Ist ein Objekt in der Entfernung kleiner oder gleich
	dem Eingangsparameter "abstand" erkennbar?

	objekt_sichtbar(7) liefert TRUE zurück, falls überhaupt 
	ein Object detektierbar.
	
	abstand:
	0: 5cm
	1: 7cm 
	2: 13cm
	3: 15cm
	4: 16cm
	5: 17cm
	6: 18cm
	7: 22cm

	( Testobjekt: Joghurtecher, Umgebungsbeleuchtung: Zimmer )

	return: TRUE falls Objekt gefunden
			FALSE wenn nicht

	Zeitbedarf: 5ms

*************************************************************************/
uint8_t objekt_sichtbar(uint8_t distance)
{
	uint16_t j,z;
	
   	DDRD |= (1 << DDD1);   // Port D1 als Ausgang
   	PORTD &= ~(1 << PD1);   // PD1 auf LOW

	OCR2  = 254-distance;   // wenn OCR2=0xFE dann Objekt sehr nahe 
	z=0;
	for(j=0;j<30;j++) // loop time: 5ms
	{
		if (PIND & (1 << PD0))z++;
		Sleep(6); // 6*Sleep(6)=1ms
	}
	if (z>=29) return FALSE; // Objekt nicht gefunden
	else return TRUE;
}
/*************************************************************************

	uint8_t abstand()
 
 	Abstandsermittelung über IR-Sendiode / IR-Empfänger.
	0:kleinster Abstand
	7:größter Abstand
	255: kein Objekt

	Zeitbedarf: 5ms*9=45ms

	author: robo.fr, christoph ( ät ) roboterclub-freiburg.de
	date: 2008

*************************************************************************/
uint8_t abstand()
{
	uint8_t k,n;
	
	k=255;
	for(n=0;n<8;n++)
	{
	  if (!objekt_sichtbar(n)) k=n; // solange kein Objekt, Distanz erhoehen
	}  
	return k;
}
/*************************************************************************

	Hauptprogramm

*************************************************************************/
int main(void)
{
   	uint8_t n;
   
   	Init();

	FrontLED(ON);
   	while(1)
	{
	   	n=abstand();
		StatusLED(OFF);
	   	BackLED(OFF,OFF);
		MotorSpeed(200,200);
	   		
		if(n!=255)
	   	{
		    if (n<11) MotorSpeed(0,200);
		    if (n<10) MotorSpeed(0,200);
		    if (n<9) MotorSpeed(0,200);
		    if (n<8) MotorSpeed(0,200);
	   		if (n<7) MotorSpeed(0,200);
	   		if (n<6) MotorSpeed(0,200);
	   		if (n<5) MotorSpeed(0,200);
	   		if (n<4) MotorSpeed(0,200);
			if (n<3) MotorSpeed(0,200);
			if (n<2) MotorSpeed(200,200);
			if (n<1) MotorSpeed(200,200);
			Msleep(10);
		}
	}
}