ROBOTC.net forums
http://www.robotc.net/forums/

Lego Two-Dimensional Array
http://www.robotc.net/forums/viewtopic.php?f=1&t=5683
Page 1 of 2

Author:  MariosRobot [ Tue Apr 09, 2013 7:49 am ]
Post subject:  Lego Two-Dimensional Array

Dear,
i want to make a Two-Dimensional Array for Lego,
i want to make a path planning to avoid the obstacles and find the shorter path in a map

how to create this program?

thanks in advance
best regards

Author:  mightor [ Tue Apr 09, 2013 9:23 am ]
Post subject:  Re: Lego Two-Dimensional Array

I can help you with the array but you're on your own with the other thing. Good luck though!

Code:
int array[10][10];


= Xander

Author:  MariosRobot [ Tue Apr 09, 2013 12:06 pm ]
Post subject:  Re: Lego Two-Dimensional Array

thanks bro, i will start the project with this

Author:  mightor [ Tue Apr 09, 2013 12:23 pm ]
Post subject:  Re: Lego Two-Dimensional Array

Good start but I think you're likely to need a bit more code to get the whole thing working :)

= Xander

Author:  MariosRobot [ Fri May 10, 2013 7:56 am ]
Post subject:  Re: Lego Two-Dimensional Array

i have one square 5X5,
any square 25cm
so the big square is 125X125 cm
how to define this in a two dimensional array?

Attachments:
PathPlanning.png
PathPlanning.png [ 25.96 KiB | Viewed 11108 times ]

Author:  mightor [ Fri May 10, 2013 8:37 am ]
Post subject:  Re: Lego Two-Dimensional Array

You could make obstacles to be -1
Code:
int maze[][] = {{10, 9, 8, 7, 8},
{11, 10, -1, 6, 7},
{-1, -1, -1, 5, 6},
{1, 2, -1, 4, 5}
{0, 1, 2, 3, 4}};


= Xander

Author:  MariosRobot [ Fri May 10, 2013 9:07 am ]
Post subject:  Re: Lego Two-Dimensional Array

thanks a lot bro

Author:  MariosRobot [ Fri May 10, 2013 5:06 pm ]
Post subject:  Re: Lego Two-Dimensional Array

another one question bro, how to define the start point and end point?

Author:  mightor [ Sat May 11, 2013 1:03 am ]
Post subject:  Re: Lego Two-Dimensional Array

Well, that depends, do you know before you start the robot where the start and finish are? How does your robot distinguish the tiles? Or do you already know "I start here and I finish there"?

= Xander

Author:  MariosRobot [ Sat May 11, 2013 3:17 am ]
Post subject:  Re: Lego Two-Dimensional Array

i want to give the start point and the end point and found the shorter path and avoid obstacles
for found the obstacles i will use the sonar sensor
but i don't know how to define start and end point

Author:  mightor [ Sat May 11, 2013 3:29 am ]
Post subject:  Re: Lego Two-Dimensional Array

You should have a look to see how others have implemented this in C. Also take a look here:
http://www.mcs.alma.edu/LMICSE/LabMater ... lgCoL4.htm
http://www.me.iitb.ac.in/~adeshmukh/floodfill.php

= Xander

Author:  MariosRobot [ Mon Jun 03, 2013 5:51 pm ]
Post subject:  Re: Lego Two-Dimensional Array

Dear,
i want only to move from one point to other point,
is it easy?

thanks in advance
best regards

Author:  roboRed [ Mon Jun 03, 2013 7:43 pm ]
Post subject:  Re: Lego Two-Dimensional Array

mightor wrote:
I can help you with the array but you're on your own with the other thing. Good luck though!

Code:
int array[10][10];


= Xander



I didn't know that that was possible!!!! :shock: :eek:

Author:  Ernest3.14 [ Mon Jun 03, 2013 9:34 pm ]
Post subject:  Re: Lego Two-Dimensional Array

Just a quick interjection:
I've read of the wavefront method multiple times; is it the only method? It's always mentioned as the most primitive, so surely there must be better ones :)

Author:  MariosRobot [ Tue Jun 04, 2013 7:11 am ]
Post subject:  Re: Lego Two-Dimensional Array

can you help me with robotC code?

my instructor give me some code's parts and i implemented an algorithm but not working

Code:
#pragma config(Sensor, S4,     sonarSensor,    sensorSONAR)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

int  M[25][25];
int  V[25][25];
int maxx = 24;
int maxy = 24;
int Gx, Gy, x, y;
int goal, Sx, Sy;

//Assign sequencial values in the value array
void assignvalues(){
  bool check = false;

  while (check == false){
       for (y=Gy; y>=0; y--){
          for (x=Gx; x<=maxx; x++){
               if (((y-1)>=0) && (M[x][y-1]!=1) && ((V[x][y]+1)<V[x][y-1]))
                  V[x][y-1] = V[x][y] + 1;

            if (((x-1)>=0) && (M[x-1][y]!=1) && ((V[x][y]+1)<V[x-1][y]))
              V[x-1][y] = V[x][y] + 1;

            if (((y+1)<=maxy) && (M[x][y+1]!=1) && ((V[x][y]+1)<V[x][y+1]))
              V[x][y+1] = V[x][y] + 1;

            if (((x+1)<=maxx) && (M[x+1][y]!=1) && ((V[x][y]+1)<V[x+1][y]))
              V[x+1][y] = V[x][y] + 1;
           }

          for (x=Gx-1; x>=0; x--){
            if (((y-1)>=0) && (M[x][y-1]!=1) && ((V[x][y]+1)<V[x][y-1]))
              V[x][y-1] = V[x][y] + 1;

            if (((x-1)>=0) && (M[x-1][y]!=1) && ((V[x][y]+1)<V[x-1][y]))
              V[x-1][y] = V[x][y] + 1;

            if (((y+1)<=maxy) && (M[x][y+1]!=1) && ((V[x][y]+1)<V[x][y+1]))
              V[x][y+1] = V[x][y] + 1;

            if (((x+1)<=maxx) && (M[x+1][y]!=1) && ((V[x][y]+1)<V[x+1][y]))
              V[x+1][y] = V[x][y] + 1;
          }
        }

       for (y=Gy+1; y<=maxy; y++){
          for (x=Gx; x<=maxx; x++){
            if (((y-1)>=0) && (M[x][y-1]!=1) && ((V[x][y]+1)<V[x][y-1]))
              V[x][y-1] = V[x][y] + 1;

            if (((x-1)>=0) && (M[x-1][y]!=1) && ((V[x][y]+1)<V[x-1][y]))
              V[x-1][y] = V[x][y] + 1;

            if (((y+1)<=maxy) && (M[x][y+1]!=1) && ((V[x][y]+1)<V[x][y+1]))
              V[x][y+1] = V[x][y] + 1;

            if (((x+1)<=maxx) && (M[x+1][y]!=1) && ((V[x][y]+1)<V[x+1][y]))
              V[x+1][y] = V[x][y] + 1;
          }

          for (x=Gx-1; x>=0; x--){
            if (((y-1)>=0) && (M[x][y-1]!=1) && ((V[x][y]+1)<V[x][y-1]))
              V[x][y-1] = V[x][y] + 1;

            if (((x-1)>=0) && (M[x-1][y]!=1) && ((V[x][y]+1)<V[x-1][y]))
              V[x-1][y] = V[x][y] + 1;

            if (((y+1)<=maxy) && (M[x][y+1]!=1) && ((V[x][y]+1)<V[x][y+1]))
              V[x][y+1] = V[x][y] + 1;

            if (((x+1)<=maxx) && (M[x+1][y]!=1) && ((V[x][y]+1)<V[x+1][y]))
              V[x+1][y] = V[x][y] + 1;
          }
        }
        check = true;
        for(int j=0;j<=maxy;j++)
           for(int i=0;i<=maxx;i++)
             if ((M[i][j]!=1) && (V[i][j]==-1)) //-1:obstacle
               check = false;
  }

}

}
task main()
{
  int i, j;

  //Assign values in the Main array
   for(j=0;j<=maxy;j++){
     for(i=0;i<=maxx;i++){
       M[i][j] = 1;
     }
  }

  M[1][0] = 0;
  M[2][0] = 0;
  M[3][0] = 0;
  M[4][0] = 0;
  M[5][0] = 0;
 
  M[2][1] = 0;
  M[3][1] = 0;
  M[4][1] = 0;
  M[5][1] = 0;
  M[6][1] = 0;
 

  for (i=3; i<25; i++){
     M[i][2] = 0;}

  for (i=3; i<25; i++){
     M[i][3] = 0;}

  for (i=3; i<25; i++){
     M[i][4] = 0;}

  for (i=3; i<25; i++){
     M[i][5] = 0;}

  for (i=3; i<25; i++){
     M[i][6] = 0;}
   M[1][6] = 0;
   M[2][6] = 0;

   for (i=3; i<25; i++){
      M[i][7] = 0;}
   M[1][7] = 0;
   M[2][7] = 0;
   for (i=3; i<25; i++){
      M[i][7] = 1;}

    M[1][8] = 0;
    M[2][8] = 0;
   for (i=3; i<25; i++){
      M[i][8] = 0;}
   for (i=3; i<25; i++){
     M[i][8] = 1;}

   for (i=3; i<25; i++){
      M[i][9] = 0;}
   for (i=3; i<25; i++){
      M[i][9] = 0;}
  M[22][9] = 0;
   M[23][9] = 0;

   for (i=3; i<25; i++){
      M[i][10] = 0;}

    M[24][10] = 0;
    M[25][10] = 0;

    M[2][11] = 0;
    M[3][11] = 0;
    M[4][11] = 0;

    M[3][12] = 0;
    M[4][12] = 0;

   

   for (i=3; i<25; i++){
      M[i][13] = 0;}

   for (i=3; i<25; i++){
      M[i][14] = 0;}

   for (i=3; i<25; i++){
      M[i][15] = 0;}

   for (i=3; i<25; i++){
      M[i][16] = 0;}

   for (i=22; i<28; i++){
      M[i][17] = 0;}

    //Reset the values in the Value array
    for (j=0; j<=maxy; j++)
      for (i=0; i<=maxx; i++)
        V[i][j] = -1;

    V[Gx][Gy] = 0;

   Gx=25;
   Sx=1;
   
  // Move forward until 7 cm from the wall.
    while (SensorValue(sonarSensor) > 7)
    {
        motor[motorA] = 10;
        motor[motorC] = 10;
    }

   // go backward
    motor[motorA] = -6;
    motor[motorC] = -6;
    wait1Msec(5000); // stop in 5 seconds
 }

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