View unanswered posts | View active topics It is currently Fri Oct 18, 2019 5:11 pm

 Page 1 of 1 [ 11 posts ]
 Print view Previous topic | Next topic
aStar (a-star, A-Stern) Algorithm for NXT: TamTam.c
Author Message
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
aStar (a-star, A-Stern) Algorithm for NXT: TamTam.c
hi everyone,
here's my a-star for NXT to solve navigation in labyrinths - or simply in your living rooms.
It uses an a-star algorithm, modified by Dijkstra (the estimated distance to destination is always =0; this simplifies the node structure, enlarges the possible size of the map and excelerates the execution speed).

This is a "virtual solution"; in future this file will be added to the Navigation project (algorithm is to be enclosed to navigator.h file, see different thread).

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)

Last edited by Ford Prefect on Sat Mar 22, 2008 2:08 pm, edited 1 time in total.

Sun Mar 16, 2008 12:00 pm
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030

(You'll need in addition the file RobotC+.h, see below)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)

Last edited by Ford Prefect on Sat Apr 19, 2008 2:59 pm, edited 19 times in total.

Sat Mar 22, 2008 2:08 pm
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030

this is an additional file which is included and needed for some variable definitions a.s.o.:
 Code:///////////////////////////////////////////////////////////////////////// RobotC+.h - damit's ein bisserl einfacher wird...    ;-)          //// Version 0.5.8/////////////////////////////////////////////////////////////////////////===================================================================// mathematische Konstanten und Funktionen//===================================================================// Eulersche Zahl E:const float E=2.718281828450945235360287471352662497757247093699959574966967627724076630353547594571;//********************************************int  min(int a, int b){   int m;   m=(ab ? a:b);   return m;}//********************************************float max(float a, float b){   float m;   m=(a>b ? a:b);   return m;}//********************************************int round(float f){  if(f>0) return (int)(f + 0.5);  else    return (int)(f - 0.5);}//********************************************// ArcusTangens mit Sonderfaellen; Angabe in Grad!// x=Ankathete y=Gegenkathete Tangens=y/xfloat atan2Degrees(float x, float y){  float phi, alpha; //phi=Bogenmass, alpha=Grad;   if (x>0) {phi=atan(y/x);}   else   if ((x<0)&&(y>=0))  {phi=PI+atan(y/x);}   else   if ((x<0)&&(y<0))   {phi=-PI+atan(y/x);}   else   if ((x==0)&&(y>0))  {phi=PI/2;}   else   if ((x==0)&&(y<0))  {phi=-PI/2;}   else   if ((x==0)&&(y==0)) {phi=0;}   alpha=radiansToDegrees(phi);   return alpha;}//********************************************bool IsInRange(int Wert, int Basis, int Toleranz){   return((Wert>=Basis-Toleranz) && (Wert<=Basis+Toleranz));}//===================================================================// Prozeduren fuer Sensoren//===================================================================bool SMuxPressed(int port, byte ch) // MUX-Port an NXT (S1, S2,... ) // ch: 0=direkt, 1=ch1, 2=ch2, 3=ch3{  int v;   bool pressed;   v=SensorValue(port);   if (ch==0)   { pressed=(v<100 ); }   else  if (ch==1)   { pressed=( IsInRange(v,775,30) || IsInRange(v,523,25) || IsInRange(v,343,8)   || IsInRange(v,275,8)) ; }  else   if (ch==2)   { pressed=( IsInRange(v,620,40) || IsInRange(v,523,25) || IsInRange(v,295,8)   || IsInRange(v,275,8)) ; }  else   if (ch==3)   { pressed=( IsInRange(v,363,15) || IsInRange(v,343,8)  || IsInRange(v,295,8)   || IsInRange(v,275,8)) ; }  return pressed;// Wertetabelle fuer Sensor-Muxer (natuerlich Bauform-abhaengig)//*************************************************************////  rcx ch3 ch2 ch1     raw       // RCX-WiderstMux als sensorRawValue definiert//   0   0   0   0     1023       // an 3 Mux-Einaenge UND direktan rcx-Eingang//   0   0   0   1      775       // je 1 Taster angeschlossen//   0   0   1   0      620//   0   0   1   1      523//   0   1   0   0      363//   0   1   0   1      343//   0   1   1   0      295//   0   1   1   1      275//   1   0   0   0       79        // ab hier die Werte, wenn der//   1   0   0   1       64        // 4. Taster direkt am rcx-Sensor-Eingang//   1   0   1   0       74        // gedrueckt wird.//   1   0   1   1       70        // Eine Unterscheidung, ob dann auch//   1   1   0   0       69        // gleichzeitig  noch andere Taster//   1   1   0   1       55        // zusaetzlich gedrueckt sind,//   1   1   1   0       55        // ist dann kaum mehr moeglich.//   1   1   1   1       55        //}//===================================================================// globale Prozeduren fue Motor-Steuerung//===================================================================void  motSync (int m, int s) // setzt Sync-Master & Slave{   if ((m==0) && (s==0))   { nSyncedMotors = synchNone;}   else   if ((m==0) && (s==1))   { nSyncedMotors = synchAB;}   else   if ((m==0) && (s==2))   { nSyncedMotors = synchAC;}   else   if ((m==1) && (s==0))   { nSyncedMotors = synchBA;}   else  if ((m==1) && (s==2))   { nSyncedMotors = synchBC;}   else  if ((m==2) && (s==0))   { nSyncedMotors = synchCA;}   else  if ((m==2) && (s==1))   { nSyncedMotors = synchCB;}   else nSyncedMotors = synchNone;}//===================================================================//===================================================================

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)

Sat Mar 22, 2008 2:38 pm
Rookie

Joined: Sat Jan 10, 2009 6:26 pm
Posts: 14
Re: aStar (a-star, A-Stern) Algorithm for NXT: TamTam.c
Nice, i phink it was what i was looking for, in the future i will tell if this works for me. Meanwhile thanks for the help.

Mon Nov 09, 2009 7:22 pm
Rookie

Joined: Thu Mar 14, 2013 10:32 pm
Posts: 25
Location: Malaysia
Re: aStar (a-star, A-Stern) Algorithm for NXT: TamTam.c
Nice and thanks, i'm also doing a* algorithm .
It would a nice reference to me as guidence.
it would be i use it as reference so i can study and built my own?

the problem is.... i don't understand your language

Mon Jul 22, 2013 10:42 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: aStar (a-star, A-Stern) Algorithm for NXT: TamTam.c
Ford Prefect is not on these forums anymore and he no longer uses ROBOTC. I'm afraid you'll have to use google translate.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Tue Jul 23, 2013 1:31 am
Rookie

Joined: Thu Mar 14, 2013 10:32 pm
Posts: 25
Location: Malaysia
Re: aStar (a-star, A-Stern) Algorithm for NXT: TamTam.c
 mightor wrote:Ford Prefect is not on these forums anymore and he no longer uses ROBOTC. I'm afraid you'll have to use google translate.= Xander

which language i should use?

Tue Jul 23, 2013 5:33 am
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Re: aStar (a-star, A-Stern) Algorithm for NXT: TamTam.c
German

_________________
Matt

Tue Jul 23, 2013 9:38 am
Rookie

Joined: Thu Mar 14, 2013 10:32 pm
Posts: 25
Location: Malaysia
Re: aStar (a-star, A-Stern) Algorithm for NXT: TamTam.c
 mattallen37 wrote:German

thanks

Tue Jul 23, 2013 11:28 am
Rookie

Joined: Thu Mar 14, 2013 10:32 pm
Posts: 25
Location: Malaysia
Re:
Ford Prefect wrote:

(You'll need in addition the file RobotC+.h, see below)

English Version

Wed Jul 24, 2013 2:23 am
Rookie

Joined: Thu Mar 14, 2013 10:32 pm
Posts: 25
Location: Malaysia
Re:
Ford Prefect wrote:
this is an additional file which is included and needed for some variable definitions a.s.o.:
 Code:///////////////////////////////////////////////////////////////////////// RobotC+.h - damit's ein bisserl einfacher wird...    ;-)          //// Version 0.5.8/////////////////////////////////////////////////////////////////////////===================================================================// mathematische Konstanten und Funktionen//===================================================================// Eulersche Zahl E:const float E=2.718281828450945235360287471352662497757247093699959574966967627724076630353547594571;//********************************************int  min(int a, int b){   int m;   m=(ab ? a:b);   return m;}//********************************************float max(float a, float b){   float m;   m=(a>b ? a:b);   return m;}//********************************************int round(float f){  if(f>0) return (int)(f + 0.5);  else    return (int)(f - 0.5);}//********************************************// ArcusTangens mit Sonderfaellen; Angabe in Grad!// x=Ankathete y=Gegenkathete Tangens=y/xfloat atan2Degrees(float x, float y){  float phi, alpha; //phi=Bogenmass, alpha=Grad;   if (x>0) {phi=atan(y/x);}   else   if ((x<0)&&(y>=0))  {phi=PI+atan(y/x);}   else   if ((x<0)&&(y<0))   {phi=-PI+atan(y/x);}   else   if ((x==0)&&(y>0))  {phi=PI/2;}   else   if ((x==0)&&(y<0))  {phi=-PI/2;}   else   if ((x==0)&&(y==0)) {phi=0;}   alpha=radiansToDegrees(phi);   return alpha;}//********************************************bool IsInRange(int Wert, int Basis, int Toleranz){   return((Wert>=Basis-Toleranz) && (Wert<=Basis+Toleranz));}//===================================================================// Prozeduren fuer Sensoren//===================================================================bool SMuxPressed(int port, byte ch) // MUX-Port an NXT (S1, S2,... ) // ch: 0=direkt, 1=ch1, 2=ch2, 3=ch3{  int v;   bool pressed;   v=SensorValue(port);   if (ch==0)   { pressed=(v<100 ); }   else  if (ch==1)   { pressed=( IsInRange(v,775,30) || IsInRange(v,523,25) || IsInRange(v,343,8)   || IsInRange(v,275,8)) ; }  else   if (ch==2)   { pressed=( IsInRange(v,620,40) || IsInRange(v,523,25) || IsInRange(v,295,8)   || IsInRange(v,275,8)) ; }  else   if (ch==3)   { pressed=( IsInRange(v,363,15) || IsInRange(v,343,8)  || IsInRange(v,295,8)   || IsInRange(v,275,8)) ; }  return pressed;// Wertetabelle fuer Sensor-Muxer (natuerlich Bauform-abhaengig)//*************************************************************////  rcx ch3 ch2 ch1     raw       // RCX-WiderstMux als sensorRawValue definiert//   0   0   0   0     1023       // an 3 Mux-Einaenge UND direktan rcx-Eingang//   0   0   0   1      775       // je 1 Taster angeschlossen//   0   0   1   0      620//   0   0   1   1      523//   0   1   0   0      363//   0   1   0   1      343//   0   1   1   0      295//   0   1   1   1      275//   1   0   0   0       79        // ab hier die Werte, wenn der//   1   0   0   1       64        // 4. Taster direkt am rcx-Sensor-Eingang//   1   0   1   0       74        // gedrueckt wird.//   1   0   1   1       70        // Eine Unterscheidung, ob dann auch//   1   1   0   0       69        // gleichzeitig  noch andere Taster//   1   1   0   1       55        // zusaetzlich gedrueckt sind,//   1   1   1   0       55        // ist dann kaum mehr moeglich.//   1   1   1   1       55        //}//===================================================================// globale Prozeduren fue Motor-Steuerung//===================================================================void  motSync (int m, int s) // setzt Sync-Master & Slave{   if ((m==0) && (s==0))   { nSyncedMotors = synchNone;}   else   if ((m==0) && (s==1))   { nSyncedMotors = synchAB;}   else   if ((m==0) && (s==2))   { nSyncedMotors = synchAC;}   else   if ((m==1) && (s==0))   { nSyncedMotors = synchBA;}   else  if ((m==1) && (s==2))   { nSyncedMotors = synchBC;}   else  if ((m==2) && (s==0))   { nSyncedMotors = synchCA;}   else  if ((m==2) && (s==1))   { nSyncedMotors = synchCB;}   else nSyncedMotors = synchNone;}//===================================================================//===================================================================

English Version

 Code:/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / // / RobotC + h -.'s A little something that will be easier ... ;-) / // / Version 0.5.8/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / // / ================================================ ===================/ / Mathematical constants and functions/ / ================================================ ===================/ / Euler number e:const float e = 2.718281828450945235360287471352662497757247093699959574966967627724076630353547594571;/ / ********************************************int min (int a, int b){   int m;   m = (a b a: b?)   return m;}/ / ********************************************float max (float a, float b){   float m;   m = (a> b a: b?)   return m;}/ / ********************************************int round (float f){  if (f> 0) return (int) (f + 0.5);  else return (int) (f - 0.5);}/ / ********************************************/ / Arc tangent with Sonderfaellen, specified in degrees!/ / X = y = opposite side to the adjacent side tan = y / xatan2Degrees float (float x, float y){  float phi, alpha / / phi = radians, alpha = degree;   if (x> 0) {phi = atan (y / x);}   else   if ((x <0) && (y> = 0)) {phi = PI + atan (y / x);}   else   if ((x <0) && (y <0)) {phi = PI + atan (y / x);}   else   if ((x == 0) && (y> 0)) {phi = PI / 2;}   else   if ((x == 0) && (y <0)) {= phi-PI / 2;}   else   if ((x == 0) && (y == 0)) {phi = 0;}   alpha = radiansToDegrees (phi);   return alpha;}/ / ********************************************IsInRange bool (int value, int base, int tolerance){   return ((value> = base-tolerance) && (value <= base + tolerance));}/ / ================================================ ===================/ / Procedures for sensors/ / ================================================ ===================SMuxPressed bool (int port, byte ch) / / MUX port on NXT (S1, S2, ...) / / ch: 0 = right, 1 = ch1, ch2 = 2, 3 = ch3{  int v;   bool pressed;   v = sensor value (port);   if (ch == 0)   Pressed = {(v <100);}   else  if (ch == 1)   {Pressed = (IsInRange (v 775.30) | | IsInRange (v 523.25) | | IsInRange (v, 343.8) | | IsInRange (v, 275.8));}  else   if (ch == 2)   {Pressed = (IsInRange (v, 620,40) | | IsInRange (v 523.25) | | IsInRange (v, 295.8) | | IsInRange (v, 275.8));}  else   if (ch == 3)   {Pressed = (IsInRange (v, 363,15) | | IsInRange (v, 343.8) | | IsInRange (v, 295.8) | | IsInRange (v, 275.8));}  return pressed;/ / Table of values ​​for sensor-muxer (of course design-dependent)/ / ************************************************ *************/ // / Rcx ch1 ch2 ch3 raw / / RCX WiderstMux defined as sensorRawValue/ / 0 0 0 0 1023 / / 3 at Mux Einaenge AND rcx other via input/ / 0 0 0 1 775 / / 1 each probe connected/ / 0 0 1 0 620/ / 0 0 1 1 523/ / 0 1 0 0 363/ / 0 1 0 1 343/ / 0 1 1 0 295/ / 0 1 1 1 275/ / 1 0 0 0 79 / / from here the values ​​when the/ / 1 0 0 1 64 / / 4 Button located on the rcx sensor input/ / 1 0 1 0 74 / / pressured./ / 1 0 1 1 70 / / A distinction, whether then/ / 1 1 0 0 69 / / at the same time, other key/ / 1 1 0 1 55 / / are additionally pressured,/ / 1 1 1 0 55 / / is then hardly possible./ / 1 1 1 1 55 / /}/ / ================================================ ===================/ / Global procedures fue motor control/ / ================================================ ===================motSync void (int m, int s) / / sets sync master & slave{   if ((m == 0) && (s == 0))   {NSyncedMotors = synchNone;}   else   if ((m == 0) && (s == 1))   {NSyncedMotors = synchAB;}   else   if ((m == 0) && (s == 2))   {NSyncedMotors = synchAC;}   else   if ((m == 1) && (s == 0))   {NSyncedMotors = synchBA;}   else  if ((m == 1) && (s == 2))   {NSyncedMotors = synchBC;}   else  if ((m == 2) && (s == 0))   {NSyncedMotors = synchCA;}   else  if ((m == 2) && (s == 1))   {NSyncedMotors = synchCB;}   else nSyncedMotors = synchNone;}/ / ================================================ ===================/ / ================================================ ===================

Wed Jul 24, 2013 2:24 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 11 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning