Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   SONAR Sensor Software Driver (http://www.chiefdelphi.com/forums/showthread.php?t=42717)

Tom Bottiglieri 06-04-2006 15:56

Re: SONAR Sensor Software Driver
 
Quote:

Originally Posted by gnormhurst
Just a further update on the sonar system. We were successful in using the sonar to control our distance to the corner goal (our doors won't open if we're too close, and the balls won't go in if we're too far away). We used sonar both in autonomous and as a driver control (driver initiates "autonomous" using a button. Control is returned when the balls have been dumped or the driver hits the "abort" button.) We even got a Xerox Creativity Award for the system. :D


But here's why I'm writing this note...

We had a strange problem. The sonar system would give steady values until we enabled autonomous, and then the values would start to drop: 150, 150, 150, [start auto] 150, 150, 130, 115, 90, 75, ... All this while the robot was on blocks and unable to move!

I figured it was some bizzare resource interrupt limitation timing thing. Until I discovered that it would do this just by me running the motors. It took a mechanical engineer to put his hand on the frame and say, "I bet it's picking up vibration from the motors!" We removed the sonar unit and held it -- the problem went away. We ended up mounting the unit on a block of foam (a block we made by cutting up one of those balls from the game).

Oddly, the autonomous code seemed to work anyway. It only did this for long distances -- at short distances ( < 30" ) we didn't see this problem.

So, everyone --- be careful how you mount the sonar unit -- it can pick up vibrations and give bad readings!


Thanks again for the driver code -- we never would have been able to complete this in time without it!

-Norm

What were you trying to read a distance off when this happened? Sometimes the sensor gets screwy readings when it is pointed at a curved object. Silly sound waves.

gnormhurst 27-04-2006 18:31

Re: SONAR Sensor Software Driver
 
Quote:

Originally Posted by Tom Bottiglieri
What were you trying to read a distance off when this happened? Sometimes the sensor gets screwy readings when it is pointed at a curved object. Silly sound waves.

We were pointing it at a wall in the Drexel gym. Big, flat and perpendicular to the robot's axis. The test we did of removing the sonar unit from the robot and just holding it there, an inch from where it was mounted, seemed to be conclusive proof that it was indeed vibration pickup from the robot. Further, mounting it on foam stopped the problem.

SPEAKING OF MOUNTING IT ON FOAM: be careful how you mount it to the foam. Just putting a block of foam behind the unit and screwing it down through the foam doesn't work: the screws transmit the vibration from the frame directly to the sonar unit. You must mount the unit to the foam, then mount the foam to the robot's frame. This gives isolation.

DonRotolo 27-04-2006 21:01

Re: SONAR Sensor Software Driver
 
Quote:

Originally Posted by Gdeaver
Instead of a new thread I'll post here. There is a new sonar ranging sensor on the market. New sonar The interesting points as I see it are - Nice price, narrower cone of detection, and 3 ways to interface. RS232, analog voltage and the normal pulse timing. Too late for this year but may be a worthy addition to next years sensor selection.

Darn it, I went and started a new thread before I saw this post!
In my defense: Gdeaver's post didn't show up on a search.

Anyway: The code to measure the pulse is very cool, but that new sensor also gives an analog voltage at 10 mV/inch - just a simple analog input and you're done...

Don

cprogrammer 14-07-2006 19:23

Re: SONAR Sensor Software Driver
 
This may just be on one of those days again but how do you hook up the vex sonar sensor to the EDU robot.

Mark McLeod 14-07-2006 22:33

Re: SONAR Sensor Software Driver
 
Quote:

Originally Posted by cprogrammer
This may just be on one of those days again but how do you hook up the vex sonar sensor to the EDU robot.

You need to adapt the male connections on the Vex ultrasonic sensor to the male connections on the EDU. Either a female-female cable or replace the Vex ultrasonic cable ends with female connectors. You can also use those Y-cables that come in the FRC KOP each year to do the job.

Other than that you hook it up to the same digital output and interrupt input as used on the Vex.

Chermaine 19-07-2006 02:20

Re: SONAR Sensor Software Driver
 
I was compiling SONAR_0.3 using MPLAB C18 and it was not successful.

Followings are the errors detected from the codes in sonar.c.

At function initialize_sonar()

1) SONAR_OUTPUT_CONFIG = OUTPUT
-->symbol 'TRISJbits' has not been defined
-->struct or union object designator expected
-->lvalue required

2) SONAR_OUTPUT = 0
-->symbol 'LATJbits' has not been defined
-->struct or union object designator expected
-->lvalue required

At function ping_sonar ()

3) SONAR_OUTPUT = 1
-->symbol 'LATJbits' has not been defined
-->struct or union object designator expected
-->lvalue required

4) SONAR_OUTPUT = 0
-->symbol 'LATJbits' has not been defined
-->struct or union object designator expected
-->lvalue required

I thought maybe the problem lies with the definition in sonar.h for both SONAR_OUTPUT_CONFIG and SONAR_OUTPUT (see following 2 lines)

# define SONAR_OUTPUT rc_dig_out16
# define SONAR_OUTPUT_CONFIG digital_io_16

It seems to me that the define statements is referring to the hardware part or maybe the MPLAB C18 compiler is unable to read it?

Would anyone reading this can share which compiler they use and how to go about solving this problem?


pls help. Thank you. :)

Chermaine 29-09-2006 23:18

Re: SONAR Sensor Software Driver
 
I have managed to solve the previous post questions.

At present,

I have modify the software code for my project application. I am using a PIC18F452 microcontroller for the ping sensor. Everything works fine until programming the USART code. The hyper terminal characters does not change when the distance of the object changes.

Can you help me? I have a very close deadline to meet.

Follow is the code i added prior to Mike's codes:



#include <p18f452.h> // version 1.1
#include <usart.h>
#include "sonar.h"
/* Set configuration bits
* - set HS oscillator
* - disable watchdog timer
* - disable low voltage programming
*/

#pragma romdata CONFIG
_CONFIG_DECL(_CONFIG1H_DEFAULT & _OSC_HS_1H,
_CONFIG2L_DEFAULT,
_CONFIG2H_DEFAULT & _WDT_OFF_2H,
_CONFIG3H_DEFAULT,
_CONFIG4L_DEFAULT & _LVP_OFF_4L,
_CONFIG5L_DEFAULT,
_CONFIG5H_DEFAULT,
_CONFIG6L_DEFAULT,
_CONFIG6H_DEFAULT,
_CONFIG7L_DEFAULT,
_CONFIG7H_DEFAULT);
#pragma romdata

int i;
int distance;

void main(void)
{
int i=0;

Initialize_Sonar();
Ping_Sonar();
Hardware_Interrupt_Sonar();
Timer_Interrupt_Sonar();
Get_Sonar_Distance();

OpenUSART (USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH, 129); // open USART with baud of 9600

while(i<10)
{
putrsUSART("A");
putrsUSART(distance);
putrsUSART("B");
i++;
}
}

bear24rw 30-09-2006 00:01

Re: SONAR Sensor Software Driver
 
Im not sure if im right about this but try this...
I put the whole thing in an endless loop..
Code:

#include <p18f452.h> // version 1.1
#include <usart.h>
#include "sonar.h"
/* Set configuration bits
* - set HS oscillator
* - disable watchdog timer
* - disable low voltage programming
*/

#pragma romdata CONFIG
_CONFIG_DECL(_CONFIG1H_DEFAULT & _OSC_HS_1H,
_CONFIG2L_DEFAULT,
_CONFIG2H_DEFAULT & _WDT_OFF_2H,
_CONFIG3H_DEFAULT,
_CONFIG4L_DEFAULT & _LVP_OFF_4L,
_CONFIG5L_DEFAULT,
_CONFIG5H_DEFAULT,
_CONFIG6L_DEFAULT,
_CONFIG6H_DEFAULT,
_CONFIG7L_DEFAULT,
_CONFIG7H_DEFAULT);
#pragma romdata

int distance;

void main(void)
{

  Initialize_Sonar();

  while (1)  // Endless loop
  {

      Ping_Sonar();
      Hardware_Interrupt_Sonar();
      Timer_Interrupt_Sonar();
      distance = Get_Sonar_Distance();  // Get distance and update variable

      OpenUSART (USART_TX_INT_OFF &
      USART_RX_INT_ON &
      USART_ASYNCH_MODE &
      USART_EIGHT_BIT &
      USART_CONT_RX &
      USART_BRGH_HIGH, 129); // open USART with baud of 9600

      putrsUSART("A");
      putrsUSART(distance);
      putrsUSART("B");

  }
}

Try that and see if it works...

Good Luck

MikeDubreuil 30-09-2006 08:11

Re: SONAR Sensor Software Driver
 
I think you may have overlooked this section in the readme:
Quote:

Software Use:
Call Ping_Sonar() to update the distance reading. Call Get_Sonar_Distance() to return the distance between the sonar sensor and an object in inches.
The functions: Hardware_Interrupt_Sonar() and Timer_Interrupt_Sonar() are only meant to be called internally in the sonar software. You only need to call two functions: Ping_Sonar() updates the distance between the sonar sensor and an object and Get_Sonar_Distance which will return the distance in inches.

I'm not familiar with your application but give this a shot. Note that I added comments about adding a time delay. It may take up to 50mS for the sonar to find an object.
]
Code:

#include <p18f452.h>  // version 1.1
#include <usart.h>
#include "sonar.h"
/* Set configuration bits
* - set HS oscillator
* - disable watchdog timer
* - disable low voltage programming
*/

#pragma romdata CONFIG
_CONFIG_DECL(_CONFIG1H_DEFAULT & _OSC_HS_1H,\
                        _CONFIG2L_DEFAULT,\
                        _CONFIG2H_DEFAULT & _WDT_OFF_2H,\
                        _CONFIG3H_DEFAULT,\
                        _CONFIG4L_DEFAULT & _LVP_OFF_4L,\
                        _CONFIG5L_DEFAULT,\
                        _CONFIG5H_DEFAULT,\
                        _CONFIG6L_DEFAULT,\
                        _CONFIG6H_DEFAULT,\
                        _CONFIG7L_DEFAULT,\
                        _CONFIG7H_DEFAULT);
#pragma romdata

int i;
int distance;

void main(void)
{
  int i=0;

  Initialize_Sonar();

  OpenUSART (USART_TX_INT_OFF &
                    USART_RX_INT_ON &
                    USART_ASYNCH_MODE &
                    USART_EIGHT_BIT &
                    USART_CONT_RX &
                    USART_BRGH_HIGH, 129);  // open USART with baud of 9600
  Ping_Sonar();
  /* You might want to consider adding a time delay here */
  while(i<10)
  {
        distance = Get_Sonar_Distance();
        Ping_Sonar();
        putrsUSART("A");
        putrsUSART(distance);
        putrsUSART("B");
        i++;
        /* You might want to consider adding a time delay here */
  }
}


daveydaycart 03-02-2007 22:48

Re: SONAR Sensor Software Driver
 
I've been trying to get this working today on the FRC Robot Controller. I've never programmed interrupts before though, so I'm at a stand-still as to what to do. I think I have the initialization for the pin driven interrupt done correctly, but I'm at a complete loss for how to get the timer working. Any help would be appreciated.

MikeDubreuil 04-02-2007 08:04

Re: SONAR Sensor Software Driver
 
Quote:

Originally Posted by daveydaycart (Post 571250)
I think I have the initialization for the pin driven interrupt done correctly, but I'm at a complete loss for how to get the timer working. Any help would be appreciated.

I'm assuming you're using MPlab and not EasyC to program your robot. Where did you get your version of the default code? Also does the particular version you are using have a name? For instance, "2007 Default Code from IFIrobotics.com" or "Camera code version 2.0 from kevin.org". A link so I can download the default code would be helpful as well.

daveydaycart 04-02-2007 17:08

Re: SONAR Sensor Software Driver
 
Yes, I'm using MPlab to program. I got my default code from kevin.org, it is his camera code version 2.1.

Thanks for your help!

MikeDubreuil 05-02-2007 10:50

Re: SONAR Sensor Software Driver
 
Quote:

Originally Posted by daveydaycart (Post 571702)
I got my default code from kevin.org, it is his camera code version 2.1.

In the file user_routines_fast.c you have to change the function InterruptHandlerLow(). Add the following code to the IF statement.
Code:

    else if (PIR2bits.TMR3IF && PIE2bits.TMR3IE) // timer 3 interrupt?
    {
        PIR2bits.TMR3IF = 0;
        Timer_Interrupt_Sonar(); // Call SONAR Timer Interrupt Handler
    }     
    else if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) // external interrupt 1?
    {
        INTCON3bits.INT2IF = 0;
        Hardware_Interrupt_Sonar(); // Call SONAR hardware interrupt handler
    }


daveydaycart 05-02-2007 18:34

Re: SONAR Sensor Software Driver
 
oooh I think it may be that when I added your code to InterruptHandlerLow() I didn't reset the interrupt flag within the two "else if" statements. I'll add that tonight and see if it works. Thanks!

Tom Bottiglieri 14-02-2007 21:29

Re: SONAR Sensor Software Driver
 
Hey guys,

Version 0.3 of this software DOES NOT work with Kevin Watson's PWM driver.

I'm guessing its a dependancy on Timer 3.

So, dont use it, or fix it.

--Tom


All times are GMT -5. The time now is 22:14.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi