View unanswered posts | View active topics It is currently Wed May 04, 2016 12:30 pm

 Page 2 of 2 [ 27 posts ] Go to page Previous  1, 2
 Print view Previous topic | Next topic
Lego Two-Dimensional Array
Author Message

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Lego Two-Dimensional Array
I am not sure what you're expecting from us. You have no comments in your code, so I have no idea what you expect this code to do.

= 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 Jun 04, 2013 7:21 am
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
Re: Lego Two-Dimensional Array
path planning algorithm, move from one point to other point

Tue Jun 04, 2013 7:39 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Lego Two-Dimensional Array
Maybe you should talk to your supervisor about this. You have a function called assignvalues(), but you don't call it anywhere in your code. I am not sure what the point of it is.

= 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 Jun 04, 2013 7:46 am
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
Re: Lego Two-Dimensional Array
the assignvalues it is all possible moves, make all possible moves to put values in the array.

Tue Jun 04, 2013 7:59 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Lego Two-Dimensional Array
Perhaps, but it is not doing anything.

= 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 Jun 04, 2013 8:19 am
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
Re: Lego Two-Dimensional Array
i know bro, for this reason i ask you for a little help, i am difficult with robotC code
can you help me?
only move from one point to other point

Tue Jun 04, 2013 5:24 pm
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
Re: Lego Two-Dimensional Array
also i try to define step by step all values in square(manual)

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

int startpoint;//define start point
int endpoint;//define end point
int square[5][5];//define array 5X5

{
// define with 0 all values in array
square[1][1]=0;
square[1][2]=0;
square[1][3]=0;
square[1][4]=0;
square[1][5]=0;

square[2][1]=0;
square[2][2]=0;
square[2][3]=0;
square[2][4]=0;
square[2][5]=0;

square[3][1]=0;
square[3][2]=0;
square[3][3]=0;
square[3][4]=0;
square[3][5]=0;

square[4][1]=0;
square[4][2]=0;
square[4][3]=0;
square[4][4]=0;
square[4][5]=0;

square[5][1]=0;
square[5][2]=0;
square[5][3]=0;
square[5][4]=0;
square[5][5]=0;

//start to increase by 1 all values next to 0
square[5][4]=1;
square[4][5]=1;

//increase by 1 all values next to 1
square[5][3]=2;
square[4][4]=2;
square[3][5]=2;

//increase by 1 all values next to 2
square[5][2]=3;
square[4][3]=3;
square[3][4]=3;
square[2][5]=3;

//increase by 1 all values next to 3
square[5][1]=4;
square[4][2]=4;
square[3][3]=4;
square[2][4]=4;
square[1][5]=4;

//increase by 1 all values next to 4
square[4][1]=5;
square[3][2]=5;
square[2][3]=5;
square[1][4]=5;

//increase by 1 all values next to 5
square[3][1]=6;
square[2][2]=6;
square[1][3]=6;

//increase by 1 all values next to 6
square[2][1]=7;
square[1][2]=7;

//increase by 1 all values next to 7
square[1][1]=8;

// define the location [5][5] as end point and the location [1][1] as start point
startpoint=square[1][1];
endpoint=square[5][5];
}

how to move the robot from location [5][5] to location [1][1]?
if every time moving to a lower number will find the shorter path, but i don't no how to implement this

best regard

Wed Jun 05, 2013 7:30 am
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
Re: Lego Two-Dimensional Array
i implement the algorithm and working perfect, but i search how to define 25 cm for any square
i try with a lot of number but i not found, can you help me?

this is my program
//GLOBAL VARIABLES grid world dimensions
const int x_size = 5;
const int y_size = 5;

//GLOBAL ARRAY representation of grid world using a 2-Dimensional array
//0 = Free space
//1 = obstacle
//2 = goal
//99 = robot
int map[x_size][y_size] =
{{0,0,0,0,0},
{0,1,99,1,0},
{0,1,1,1,0},
{0,0,0,0,0},
{0,0,2,0,0},
};

//FUNCTION move forward for a variable number of grid blocks
void moveForward(int blocks)
{
//convert number of blocks to encoder counts
//wheel circumference = 17.6 cm
//one block = 23.7 cm
int countsToTravel = (23.7/17.6)*(360)*blocks;

//encoder target for countsToTravel
nMotorEncoder[motorA] = 0;
nMotorEncoder[motorC] = 0;
nMotorEncoderTarget[motorA] = countsToTravel;
nMotorEncoderTarget[motorC] = countsToTravel;
motor[motorA] = 50;
motor[motorC] = 50;
while(nMotorRunState[motorA] != runStateIdle && nMotorRunState[motorC] != runStateIdle) {}

//stop for half second at end of movement
motor[motorA] = 0;
motor[motorC] = 0;
wait1Msec(500);
}

//FUNCTION left point turn 90 degrees
void turnLeft90()
{
//distance one wheel must travel for 90 degree point turn = 10.68 cm
//wheel circumference = 17.6 cm
int countsToTravel = (8.6/17.6)*(360);

//encoder target for countsToTravel
nMotorEncoder[motorA] = 0;
nMotorEncoder[motorC] = 0;
nMotorEncoderTarget[motorA] = countsToTravel;
nMotorEncoderTarget[motorC] = countsToTravel;
motor[motorA] = 50;
motor[motorC] = -50;
while(nMotorRunState[motorA] != runStateIdle && nMotorRunState[motorC] != runStateIdle) {}

//stop for half second at end of movement
motor[motorA] = 0;
motor[motorC] = 0;
wait1Msec(500);
}

//FUNCTION right point turn 90 degrees
void turnRight90()
{
//distance one wheel must travel for 90 degree point turn = 10.68 cm
//wheel circumference = 17.6 cm
int countsToTravel = (8.6/17.6)*(360);

//encoder target for countsToTravel
nMotorEncoder[motorA] = 0;
nMotorEncoder[motorC] = 0;
nMotorEncoderTarget[motorA] = countsToTravel;
nMotorEncoderTarget[motorC] = countsToTravel;
motor[motorA] = -50;
motor[motorC] = 50;
while(nMotorRunState[motorA] != runStateIdle && nMotorRunState[motorC] != runStateIdle) {}

//stop for half second at end of movement
motor[motorA] = 0;
motor[motorC] = 0;
wait1Msec(500);
}

//FUNCTION print wavefront map to NXT screen
void PrintWavefrontMap()
{
int printLine = y_size-1;
for(int y = 0; y < y_size; y++)
{
string printRow = "";
for(int x=0; x < x_size; x++)
{
if(map[x][y] == 99)
printRow = printRow + "R ";
else if(map[x][y] == 2)
printRow = printRow + "G ";
else if(map[x][y] == 1)
printRow = printRow + "X ";
else if(map[x][y] < 5)
printRow = printRow + map[x][y] + " ";
else if(map[x][y] == '*')
printRow = printRow + "* ";
else
printRow = printRow + map[x][y];
}
nxtDisplayString(printLine, printRow);
printLine--;
}
}

//FUNCTION wavefront algorithm to find most efficient path to goal
void WavefrontSearch()
{
int goal_x, goal_y;
bool foundWave = true;
int currentWave = 2; //Looking for goal first

while(foundWave == true)
{
foundWave = false;
for(int y=0; y < y_size; y++)
{
for(int x=0; x < x_size; x++)
{
if(map[x][y] == currentWave)
{
foundWave = true;
goal_x = x;
goal_y = y;

if(goal_x > 0) //This code checks the array bounds heading WEST
if(map[goal_x-1][goal_y] == 0) //This code checks the WEST direction
map[goal_x-1][goal_y] = currentWave + 1;

if(goal_x < (x_size - 1)) //This code checks the array bounds heading EAST
if(map[goal_x+1][goal_y] == 0)//This code checks the EAST direction
map[goal_x+1][goal_y] = currentWave + 1;

if(goal_y > 0)//This code checks the array bounds heading SOUTH
if(map[goal_x][goal_y-1] == 0) //This code checks the SOUTH direction
map[goal_x][goal_y-1] = currentWave + 1;

if(goal_y < (y_size - 1))//This code checks the array bounds heading NORTH
if(map[goal_x][goal_y+1] == 0) //This code checks the NORTH direction
map[goal_x][goal_y+1] = currentWave + 1;
}
}
}
currentWave++;
PrintWavefrontMap();
wait1Msec(500);
}
}

//FUNCTION follow most efficient path to goal
//and update screen map as robot moves
void NavigateToGoal()
{
//Store our Robots Current Position
int robot_x, robot_y;

//First - Find Goal and Target Locations
for(int x=0; x < x_size; x++)
{
for(int y=0; y < y_size; y++)
{
if(map[x][y] == 99)
{
robot_x = x;
robot_y = y;
}
}
}

//Found Goal and Target, start deciding our next path
int current_x = robot_x;
int current_y = robot_y;
int current_facing = 0;
int next_Direction = 0;
int current_low = 99;

while(current_low > 2)
{
current_low = 99; //Every time, reset to highest number (robot)
next_Direction = current_facing;
int Next_X = 0;
int Next_Y = 0;

//Check Array Bounds West
if(current_x > 0)
if(map[current_x-1][current_y] < current_low && map[current_x-1][current_y] != 1) //Is current space occupied?
{
current_low = map[current_x-1][current_y]; //Set next number
next_Direction = 3; //Set Next Direction as West
Next_X = current_x-1;
Next_Y = current_y;
}

//Check Array Bounds East
if(current_x < (x_size -1))
if(map[current_x+1][current_y] < current_low && map[current_x+1][current_y] != 1) //Is current space occupied?
{
current_low = map[current_x+1][current_y]; //Set next number
next_Direction = 1; //Set Next Direction as East
Next_X = current_x+1;
Next_Y = current_y;
}

//Check Array Bounds South
if(current_y > 0)
if(map[current_x][current_y-1] < current_low && map[current_x][current_y-1] != 1)
{
current_low = map[current_x][current_y-1]; //Set next number
next_Direction = 2; //Set Next Direction as South
Next_X = current_x;
Next_Y = current_y-1;
}

//Check Array Bounds North
if(current_y < (y_size - 1))
if(map[current_x][current_y+1] < current_low && map[current_x][current_y+1] != 1) //Is current space occupied?
{
current_low = map[current_x][current_y+1]; //Set next number
next_Direction = 0; //Set Next Direction as North
Next_X = current_x;
Next_Y = current_y+1;
}

//Okay - We know the number we're heading for, the direction and the coordinates.
current_x = Next_X;
current_y = Next_Y;
map[current_x][current_y] = '*';

while(current_facing != next_Direction)
{
if (current_facing > next_Direction)
{
turnLeft90();
current_facing--;
}
else if(current_facing < next_Direction)
{
turnRight90();
current_facing++;
}
}
moveForward(1);
PrintWavefrontMap();
wait1Msec(500);
}
}

{
WavefrontSearch(); //Build map of route with wavefront algorithm
NavigateToGoal(); //Follow most efficient path to goal
wait1Msec(5000); //Leave time to view the LCD screen
}

Wed Jun 12, 2013 5:02 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Lego Two-Dimensional Array
This look a lot like the code in here: http://www.robotc.net/blog/2011/08/08/r ... -training/

= 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]

Wed Jun 12, 2013 5:28 am
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
Re: Lego Two-Dimensional Array
can you help me? only with 25 cm

Wed Jun 12, 2013 6:51 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Lego Two-Dimensional Array
Are you planning to do any of this work yourself or are you just going to copy and paste your way through your education?

Read the code, it's in there.

= 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]

Wed Jun 12, 2013 10:02 am
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
Re: Lego Two-Dimensional Array
someone can help me to define the correct values and correct speed to move the robot 25X25 cm of any block?

best regards

Thu Jun 13, 2013 6:36 am
Display posts from previous:  Sort by
 Page 2 of 2 [ 27 posts ] Go to page Previous  1, 2

#### 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