1. ## vehicle position system

please see the picture given in following link i need to write a code for similar situation whose logic i am not able to understand

Vehicle Positioning System “AND-VPS”, Ahmedabad, Gujarat, India

I understand that to find the correct position, the first and third sensor should be low and the middle sensor should be high as show the image show in link.

I don't understand how logic would be used for a public declaration that instructs the driver to the correct position.
If the truck has stopped on the first sensor then it should be announced to go forward, if it is ahead a lot at third sensor , then it should be told to go back.

2. Draw out a truth table

0 0 0 - "please drive onto the weigh bride"
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 1

As the truck drives onto the platform, you're going to see a sequence of state changes from the three sensors.

3. Originally Posted by Salem
Draw out a truth table

As the truck drives onto the platform, you're going to see a sequence of state changes from the three sensors.
This is my truth table

0 0 0 - " The truck is not on the weighbridge "
0 1 0 " You are in the right place"
1 0 0 " Please go back"
1 0 1 " Not possible conditions "
1 1 1 " Not possible conditions

Looking at the sequence, it seems that while loop should use

Code:
``` main()
{
while (1)
{
while (IR1 == 1)
{

while (IR1 == 1 && IR2 == 1)
{
while (IR1 == 0 && IR2 == 1)
{
printf( " You are on right position" )
}

}

}
}

}```

4. Let say your sensors are connected to bits 0 to 2 of a register called IR:
Code:
```// Do something... (here I'll pass sensors data to the functions).
extern void not_in_weightbridge(unsigned int);
extern void go_back(unsigned int);
extern void right_place(unsigned int);
extern void not_possible(unsigned int);

// Get sensors data.
extern unsigned int getSensors( void );

extern int terminated;  // flag to terminate main loop.

void main_loop( void )
{
unsigned int sensors;

// Table to functions sorted by the sensors data.
static const void (*actions[])(unsigned int) = {
not_in_weightbridge,
right_place,
go_back,
not_possible,
not_possible,  /* 110 missing! */
not_possible
};

while ( ! terminated )
{
unsigned int sensors = getSensors() & 0x7;

actions[sensors](sensors);
}
}```

5. I don't understand how we know there are three sensors from the picture.
What are the little white squares and red dotted lines on the ground?

And if there's three sensors, why does Dadu's code only mention two?
And what's up with the freaky nested while loops?

6. Originally Posted by john.c
What are the little white squares and red dotted lines on the ground?

And if there's three sensors, why does Dadu's code only mention two?
And what's up with the freaky nested while loops?
The white square is the transmitter and receiver of the sensor. When the transmitter detects an object, it sends it to the receiver and the receiver sends it to the micro-controller. So we have a total of three transmitters and three receivers

imagine the situation when the vehicle is stopped at the sensor. The condition says instruct the driver to proceed as long as sensor one is active. Looks like there should be a while loop to check sensor status

7. I suppose that these "sensors" are lasers which have the beam interrupted by the object... But this isn't a good project and something is missing... with 6 pilars you should have 5 sensors:

Code:
```-> beam from LED (other side is receiver).
E
A->------|-------B
|        V       |
V        |       |
|        |       |
|        |       ^
|        |       |
C--------|-----<-D
F```
The question is: Is it acceptable if the object is in one of these positions?

Code:
```         E                   E
A->------|-------B  A->------|-------B
|        V       |  |        V       |
V  xxxx  |       |  V        |       |
|  xxxx  |       |  |        |  xxxx |
|        |       ^  |        |  xxxx ^
|        |       |  |        |       |
C--------|-----<-D  C--------|-----<-D
F                   F

E                   E
A->------|-------B  A->------|-------B
|        V       |  |      xxxx      |
V        |       |  V      xxxx      |
|        |       |  |        |       |
|      xxxx      ^  |        |       ^
|      xxxx      |  |        |       |
C--------|-----<-D  C--------|-----<-D
F                   F```

8. Why can't it just be something like this.
Code:
```L1--------L2--------L3    Lasers
|         |         |
|         |         |
|         |         |
|         |         |
|         |         |
S1--------S2--------S3    Sensors

while (1) {
if (S1)
go forwards
else if (S3)
go backwards
else
correct position
}```

9. Originally Posted by john.c
Why can't it just be something like this.
Code:
```L1--------L2--------L3    Lasers
|         |         |
|         |         |
|         |         |
|         |         |
|         |         |
S1--------S2--------S3    Sensors

while (1) {
if (S1)
go forwards
else if (S3)
go backwards
else
correct position
}```
It make sense, But it is not understood that when the vehicle stops at sensor 2 after crossing sensor 1, so what is the need to check sensor 3 first.

When the vehicle stops at sensor 2, the vehicle's weight is measured

10. What happens if S1 negates before S2 asserts?
- Did the vehicle reverse and leave the weighbridge?
- Is the vehicle shorter than the gap between S1 and S2?

What happens if S1 and S2 are asserted?
- Is it a really long vehicle?
- Are there two vehicles on the weighbridge?

Finite-state machine - Wikipedia
- You have events - S1, S2, S3
- You have states - entry, stop, weigh, leave
You need to make sure the event you receive is consistent with the state you're in.

11. @Dadu, My example was not meant as a full solution.
It was just meant to show you that the nested while loops were incorrect.

12. Originally Posted by Salem
What happens if S1 negates before S2 asserts?
- Did the vehicle reverse and leave the weighbridge?
- Is the vehicle shorter than the gap between S1 and S2?

What happens if S1 and S2 are asserted?
- Is it a really long vehicle?
- Are there two vehicles on the weighbridge?.
System checks if S1 and S2 are high then system announces publicly, go forward

If the driver stops the vehicle at S2, the machine measure weight loaded on vehicle.

If vehicle stops at S2 and S3 without weighing loaf, system announce, go backwards

Something like this

Originally Posted by Salem
Finite-state machine - Wikipedia
- You have events - S1, S2, S3
- You have states - entry, stop, weigh, leave
You need to make sure the event you receive is consistent with the state you're in.
I am trying to make FSM