Log in

View Full Version : Ultrasonic will not work with another Ultrasonic plz help


Jackel148
21-03-2006, 16:00
Let me first say that I am working with Vex programing for teh FVC compatition. I have tried several times to get my ultrasonics working together. I have tried putting a print to screen for each and they work individually, however, when I try to put them both together they will not work. Can anyone help me with my problem?

Alex698
21-03-2006, 17:10
how are you setting them up? ie pointing at each other or straight forward towards a target?

Mike Betts
21-03-2006, 18:07
Jackel,

Each sensor must be on its own interrupt line and digital output line. Also, you must stagger the output pulse so that both will not transmit a pulse at the same time.

I can give you code fragments on how to so it in C but not EasyC.

Mike

Gdeaver
21-03-2006, 18:08
Your are probable having the 2 sonars interfere with each other both physically and in the timing subroutines. Don't know how you have them set up and what your measuring, but you could mount one sonar on a servo. Point in 1 direction read it , move to another direction and read it.

Keith Watson
21-03-2006, 18:13
Also, you must stagger the output pulse so that both will not transmit a pulse at the same time.And you might want to think about how to handle when another robot is also sending out sonar pulses. :ahh:

Jackel148
21-03-2006, 21:57
how are you setting them up? ie pointing at each other or straight forward towards a target?

I have them set up so that the two of them are facing forward and I am trying to get them to both line up the bot so that it is straight...I tried putting a boared in the middle so that they could not interfere with each other however when I did a print to screen I got nothing which is what happened the rest of the times.

If it is them interfering with each other how would i fix that?

Mike Betts
21-03-2006, 22:36
Here is a code fragment for managing 3 ultrasonic sensors:

int Service_Ultrasonic_Sensors (void)
{

ultra_counter++;
switch (ultra_counter) // Process Ultrasonic Transducer
{
case 1:
for (pulsecount = 0 ; pulsecount < PULSE_WIDTH ; pulsecount++)
{
rc_dig_out10 = 1; // Make another pulse
};
rc_dig_out10 = 0; // The pulse is over
break;
case 2:
for (pulsecount = 0 ; pulsecount < PULSE_WIDTH ; pulsecount++)
{
rc_dig_out11 = 1; // Make another pulse
};
rc_dig_out11 = 0; // The pulse is over
break;
case 3:
for (pulsecount = 0 ; pulsecount < PULSE_WIDTH ; pulsecount++)
{
rc_dig_out12 = 1; // Make another pulse
};
rc_dig_out12 = 0; // The pulse is over
break;
case 4:
if (ultra_left_flag == TRUE)
{
INTCONbits.GIEL = 0; // Disable Low Priority Interrupts
ultra_left_time = ultra_left_stop - ultra_left_start;
INTCONbits.GIEL = 1; // Enable Low Priority Interrupts
ultra_good_count++;
}
else
{
ultra_left_time = -1;
ultra_bad_count++;
};
if (ultra_front_flag == TRUE)
{
INTCONbits.GIEL = 0; // Disable Low Priority Interrupts
ultra_front_time = ultra_front_stop - ultra_front_start;
INTCONbits.GIEL = 1; // Enable Low Priority Interrupts
ultra_good_count++;
}
else
{
ultra_front_time = -1;
ultra_bad_count++;
};
if (ultra_right_flag == TRUE)
{
INTCONbits.GIEL = 0; // Disable Low Priority Interrupts
ultra_right_time = ultra_right_stop - ultra_right_start;
INTCONbits.GIEL = 1; // Enable Low Priority Interrupts
ultra_good_count++;
}
else
{
ultra_right_time = -1;
ultra_bad_count++;
};
ultra_left_flag = FALSE;
ultra_front_flag = FALSE;
ultra_right_flag = FALSE;
ultra_counter = 0;
break;
default: // for any unexpected result
ultra_left_flag = FALSE;
ultra_front_flag = FALSE;
ultra_right_flag = FALSE;
ultra_counter = 0;
break;
};

}

The code above can be called once per communications loop or via a timer interrupt, et cetera...

the variables ultra_bad_count and ultra_good_count were used during development and can be deleted.

An example interrupt routine is:

void Service_DIO4_Interrupt(unsigned char state)
{
if (state == 1) // rising-edge interrupt
{
ultra_front_start = Read_Timer_3 (); // Read Start Time.
}
else // falling-edge interrupt
{
ultra_front_flag = TRUE;
ultra_front_stop = Read_Timer_3 (); // Read Stop Time
}
}


The user routine has only to test for the time to be greater than zero to know that it is valid data.

Hopefully, this helps.


Mike

Jackel148
21-03-2006, 22:44
I will try to convert this please check back tommorow and see if it worked thanks for the help.

Jackel

Steve0100
08-05-2006, 00:13
Jackel,

Each sensor must be on its own interrupt line and digital output line. Also, you must stagger the output pulse so that both will not transmit a pulse at the same time.

I can give you code fragments on how to so it in C but not EasyC.

Mike

This is the same problem that I just encountered, in trying to use 4 Ultrasonic sensors on a 4- wheel holonomic robot. Very very frustrating.

Does anyone have an EasyC solution to using multiple sonar sensors? I've tried using waits in between Ultrasonic sensor readings to try and avoid timing loop interference, but that has not worked. Each sensor works individually but not when more than one is used at a time. Is there too much latency in Starting and Stopping each individual Ultrasonics sensor in turn?

Thanks!

Ctx32
09-05-2006, 14:03
This is the same problem that I just encountered, in trying to use 4 Ultrasonic sensors on a 4- wheel holonomic robot. Very very frustrating.

Does anyone have an EasyC solution to using multiple sonar sensors? I've tried using waits in between Ultrasonic sensor readings to try and avoid timing loop interference, but that has not worked. Each sensor works individually but not when more than one is used at a time. Is there too much latency in Starting and Stopping each individual Ultrasonics sensor in turn?

Thanks!

I have 4 working using EasyC, But i need help with the encoders
I was going to send a pic, But don't know how on this forum.
My email is ctx3201@comcast.net
Let me know and I'll send it to you or tell me how to send a pic to this forum.
Calvin

Ctx32
10-05-2006, 15:31
I have 4 working using EasyC, But i need help with the encoders
I was going to send a pic, But don't know how on this forum.
My email is ctx3201@comcast.net
Let me know and I'll send it to you or tell me how to send a pic to this forum.
Calvin

Heres the pic link:
http://i71.photobucket.com/albums/i124/ctx3201/4Ultras.jpg