It is currently Sat May 18, 2013 9:33 am
       


All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: RP6 moveatspeed / stopwatch
PostPosted: Tue Jan 31, 2012 9:29 am 
Offline
New User

Joined: Tue Jan 31, 2012 9:02 am
Posts: 3
Attachment:
RP6_achter.c [1.16 KiB]
Downloaded 29 times
Hallo,

ich hab einen RP6 und wollte ein Programm schreiben, bei dem der Roboter einen Achter fährt. Dazu will ich einen Timer in Zusammenhang mit stopwatch einsetzen - nicht sehr elegant, aber nur zum Testen.
Angefügtes Programm funktioniert nicht, der Roboter soll ca. 20 sec im Kreis fahren (mit moveatspeed(80, 30)), bis ungefähr zum Ausgangspunkt) und danach die Richtung des Kreises ändern (moveatspeed(30,80)) usw.
Wie kombiniere ich moveatspeed und stopwatch richtig?

danke für Tipps

Anbei der Quelltext


Top
 Profile E-mail  
 
 Post subject: Re: RP6 moveatspeed / stopwatch
PostPosted: Tue Jan 31, 2012 12:54 pm 
Offline
Administrator
User avatar

Joined: Fri Mar 25, 2005 6:19 pm
Posts: 1378
Location: NRW
Hallo,

lösch mal den else zweig (nicht getestet)

Code:

    uint8_t a = 80;
    uint8_t b = 30;

...

      if(getStopwatch1() >= 20000) /* sind 20sec vorbei? */
      {
         if(a == 80 && b == 30)  /* wie war die richtung? */
         {
            a = 30;             /* richtung ändern*/
            b = 80;
         }
         else if(a == 30 && b == 80)
         {
            a = 80;
            b = 30;
         }
          setStopwatch1(0);  /* zurücksetzen */
      }

// kein else


MfG,
SlyD


Top
 Profile E-mail  
 
 Post subject: Re: RP6 moveatspeed / stopwatch
PostPosted: Wed Feb 01, 2012 2:02 pm 
Offline
New User

Joined: Tue Jan 31, 2012 9:02 am
Posts: 3
hallo,

danke für die Antowrt, hat aber nichts bewirkt.

ich habs jetzt so gelöst (quelltext anbei), ist aber immer noch nicht so, wie ich es haben will. Könnte essein, dass der Sekundentakt für die stopwatch ungenau ist?


Attachments:
RP6_achter.c [1.08 KiB]
Downloaded 33 times
Top
 Profile E-mail  
 
 Post subject: Re: RP6 moveatspeed / stopwatch
PostPosted: Wed Feb 01, 2012 3:21 pm 
Offline
Administrator
User avatar

Joined: Fri Mar 25, 2005 6:19 pm
Posts: 1378
Location: NRW
Mit dem else hätte es allerdings ganz sicher nicht funktioniert ;)
Denn dann wäre ja sofort nachdem die Stopwatch auf 0 zurück gesetzt wurde wieder der else Teil ausgeführt worden - und zwar ständig bis wieder 20000 erreicht gewesen wäre.

Modulo ( % ) 20000 funktioniert nicht sicher - die Stopwatch ist nur für einen kurzen Zeitraum 20000 und ob die If Abfrage dann auch durchgeführt wird weiss man nicht (bei dem kleinen Programm eigentlich schon - aber das ist nicht skalierbar ;-) ).
Der Timer läuft ja asynchron zum Programm.

Bei Stopwatches IMMER >= oder <= verwenden.

Tipp: Mach Debug Ausgaben ins Programm --> writeString writeInteger etc. und teste es erstmal ganz OHNE Motoren. Wenn dann das Timing so ist wie Du es gerne hättest, mach die Motorfunktionen mit rein.
(und erstmal 5000 statt 20000 verwenden evtl. )

MfG,
SlyD


Top
 Profile E-mail  
 
 Post subject: Re: RP6 moveatspeed / stopwatch
PostPosted: Thu Feb 02, 2012 8:42 am 
Offline
New User

Joined: Tue Jan 31, 2012 9:02 am
Posts: 3
danke für die Tipps, jetzt hats so funktioniert wie gewünscht.

nostromo


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group