LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

4by4 puzzle type parking system


@rgb8 wrote:

hi,thank you for the reply. Will it be possible for you to help me a bit concerning the implementation in labview as am a beginner?maybe a VI with some guideline. Also, can you please help me concerning the C algorithm how to use the nested for loop for P_next(nest pallet to be used).


Try to do it yourself first. If you run into problems, post your code to show what you've done, and explain how it isn't working.

 

In your C code, the f_next function is repeated sections like this:

   if (board[A][B] == '-')
   {
        pf_y = A;
        pf_x = B;
        board[A][B] = board[ptemp_y][ptemp_x];
   }

Anytime you have repeated code like this, where the only thing that changes is the array indices, look for a way to do it in a loop.

I realize that you're not iterating through the indices in order, but you can easily deal with that by creating a new array of the indices in the correct order, then looping through that array.

0 Kudos
Message 11 of 41
(1,516 Views)

The entrance/exit point of the 4by4 puzzle system has coordinates (3,0). I have considered the shortest path for parking/retrieval of a car with respect to the coordinates (3,0).  A car to be retrieved, is brought to coordinates (3,0) through shortest path.  Once, the pallet is on coordinates (3,0), the car drives away. Now, the pallet on coordinates (3,0) becomes the next free pallet.  Consider parking of a car: after a car has been parked on pallet with coordinates (3,0), I had determine the nearest free pallet.  The nearest free pallet with respect to coordinates (3,0) is in the order shown in the f_next function.  Since it is not in a sequential order,is it possible to use a loop.

0 Kudos
Message 12 of 41
(1,504 Views)

Create an array of the coordinates in the correct order, and iterate through that array. You could use a 2-D array of [[2,0],[3,1],[2,1],[1,0],...]. Then you need only a single for loop, and you loop through that array until board[x][y] contains '-'.

 

A simple form would be something like:

int index_order[15][2] = {{2,0},{3,1},{2,1},{1,0},...}; // fill this in completely of course
int i;
for (i=0; i<15;++i){
pf_y = index_order[i][0];
pf_x = index_order[i][1];
if (board[pf_y][pf_x] = '-'){
board[pf_y][pf_x] = board[ptemp_y][ptemp_x];
break;
}
}

 

0 Kudos
Message 13 of 41
(1,494 Views)

I have implemented the f_next function using the for loop and it worked out perfectly.  Thank you very much.

void f_next (void)
{
    int index_order[15][2] = {{2,0},{3,1},{2,1},{1,0},{1,1},{3,2},{2,2},{3,3},{2,3},{1,2},{0,2},{0,1},{1,3},{0,2},{0,3}};
    int i;

    for (i=0; i<15;++i)
    {
        pf_y = index_order[i][0];
        pf_x = index_order[i][1];

        if (board[pf_y][pf_x] == '-')
        {
            board[pf_y][pf_x] = board[ptemp_y][ptemp_x];
            break;
        }
    }

}

 

  Can the C program as it is, be written in labview.  I mean can i just rewrite it as it is but using comparison and numeric.  Or is there a simpler way to do it in labview and how do i create the display.  

0 Kudos
Message 14 of 41
(1,470 Views)

There's a simpler way to do it in LabVIEW, and there's also a simpler way to do it in C. For example, it looks like you have identical code for (count == 2) through (count == 15). While you could take your existing C program and rewrite it directly in LabVIEW, you wouldn't end up with a good LabVIEW program because the C code has so much unnecessary repetition. In addition,  translating C directly to LabVIEW often leads to poor LabVIEW practices (excessive use of local variables and sequence structures, for example) because LabVIEW operates differently than C. I would recommend that you spend some time thinking about your algorithm - not in a specific programming language, but how you would approach it generally.

 

To do this properly in LabVIEW you will need to structure the code differently. You'll want to use buttons instead of typing letters for commands, and you could use a single array indicator to show the current state of the parking instead of printing it out over and over again. The board should be stored as an array in a shift register, and the array elements should be enumerations rather than characters.

0 Kudos
Message 15 of 41
(1,461 Views)

In fact, I had been trying a small part of the C program (a few if condition) in LabView 8.5.  Eventually, I ended up with many local variables.  Please give some advice.

0 Kudos
Message 16 of 41
(1,456 Views)

You need to think about it completely differently. Figure out what the program needs to do, independent of the language that you're using to do it.

 

Here's one possible very basic starting point.

parkingpuzzle-start.png

0 Kudos
Message 17 of 41
(1,436 Views)

I am not sure what you are trying to do.  I do not read C. However, it looks as though you never assigning values to ptemp_x and ptemp_y in the C code segment. You also do not assign values to them in the LV code under some cirmcumstances.

 

I doubt you need those (temporary?) variables at all.  In LabVIEW the WIRE is the variable. A local variable is a link to a control or indicator. Controls and indicators are for human access to data, not the data itself. With a few specialized exceptions local variables are rarely needed.  Try to do it without using any local variables.

 

Other comments: The data type should probably be integer, not double.  Equal comparisons on doubles can be problematic due to the finite representation of fractions in binary.  If the data will never have fractional values, use an integer datatype.

Use the =0? primitive to eliminate the need for the zero constants. Use the compound arithmetic node set to AND mode and expanded to 4 inputs.

Get rid of the sequence structures. Learn to use the power of dataflow.  Your sequences do almost nothing.  The one in the innermost case structure decrements es_x and es_y and increments them tiny fractions of a second later.

 

Here is a first step toward cleaning up your code. Note that it is not complete because I could not tell what some of it was supposed to do.

 

Lynn

 

inner cases.png

0 Kudos
Message 18 of 41
(1,434 Views)

Could you please attach the vi for labview 8.5.

0 Kudos
Message 19 of 41
(1,430 Views)

Ah, sorry, somehow misread 8.6 instead of 8.5 in the earlier post, I did mean to save it in the right version for you.

Here you go.

0 Kudos
Message 20 of 41
(1,422 Views)