ROBOTC.net forumshttp://www.robotc.net/forums/ aStar (a-star, A-Stern) Algorithm for NXT: TamTam.chttp://www.robotc.net/forums/viewtopic.php?f=15&t=456 Page 1 of 1

 Author: Ford Prefect [ Sun Mar 16, 2008 12:00 pm ] Post subject: 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).

Author:  Ford Prefect [ Sat Mar 22, 2008 2:08 pm ]
Post subject:

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

Author:  Ford Prefect [ Sat Mar 22, 2008 2:38 pm ]
Post subject:

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;}//===================================================================//===================================================================

 Author: lololol [ Mon Nov 09, 2009 7:22 pm ] Post subject: 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.

 Author: Azhari [ Mon Jul 22, 2013 10:42 pm ] Post subject: 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

 Author: mightor [ Tue Jul 23, 2013 1:31 am ] Post subject: 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

Author:  Azhari [ Tue Jul 23, 2013 5:33 am ]
Post subject:  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?

 Author: mattallen37 [ Tue Jul 23, 2013 9:38 am ] Post subject: Re: aStar (a-star, A-Stern) Algorithm for NXT: TamTam.c German

Author:  Azhari [ Tue Jul 23, 2013 11:28 am ]
Post subject:  Re: aStar (a-star, A-Stern) Algorithm for NXT: TamTam.c

 mattallen37 wrote:German

thanks

Author:  Azhari [ Wed Jul 24, 2013 2:23 am ]
Post subject:  Re:

Ford Prefect wrote:

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

English Version

Author:  Azhari [ Wed Jul 24, 2013 2:24 am ]
Post subject:  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;}/ / ================================================ ===================/ / ================================================ ===================

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/