Go to Post When I got home from work my facebook wall had exploded with people chanting the names of dead scientists. Did someone say culture change? :cool: - Ian Curtis [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 26-01-2006, 20:21
MikeDubreuil's Avatar
MikeDubreuil MikeDubreuil is offline
Carpe diem
FRC #0125 (Nu-Trons)
Team Role: Engineer
 
Join Date: Jan 2003
Rookie Year: 1999
Location: Boston, MA
Posts: 967
MikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond repute
Send a message via AIM to MikeDubreuil
SONAR Sensor Software Driver

For anyone interested in using a SONAR sensor I have completed a software driver for it. If anyone has any questions feel free to post in this thread.

Once I develop a personal website I will post the software there. Until that time it can be found by using the link in this thread. SONAR_0.1.zip


The introduction from the readme:
Code:
Introduction:
This source code in sonar.c and sonar.h are a driver for several consumer
available sonar ultrasonic range finder sensors. Tested to work with this
software is the Parallax Inc. PING)) Ultrasonic Rangefinder and the Vex
Robotics Ultrasonic Range Finder.

 This software was written for the Innovation First Inc. Mini Robot Controller.
Unmodified this software utilizes Interrupt 1 and Timer 3. Other controllers
may be used including Innovation First Inc.'s full size robot controller as 
well as other PIC microcontrollers with modifications. The documentation refers
to the controlling microcontroller simply as the controller.

 This software works by triggering the sonar sensor causing it to send an
acoustic ping. Once the ping hits an object it will reflect back towards the
sensor. The sonar sensor represents the distance to the object with a pulse 
width equal to the time it took for the ping to hit the object and return back.
This software measures the pulse width and converts the time to a distance in
inches.
__________________
"FIRST is like bling bling for the brain." - Woodie Flowers
  #2   Spotlight this post!  
Unread 29-01-2006, 14:16
Eldarion's Avatar
Eldarion Eldarion is offline
Electrical Engineer / Computer Geek
AKA: Eldarion Telcontar
no team (Teamless Orphan)
Team Role: Alumni
 
Join Date: Nov 2005
Rookie Year: 2005
Location: Númenor
Posts: 558
Eldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond repute
Send a message via AIM to Eldarion Send a message via Yahoo to Eldarion
Re: SONAR Sensor Software Driver

Thanks for posting the driver code. I had to finnagle the timer interrupt routine a tad to get it to work on the full-size FRC, but otherwise it has made my job much easier!

Thanks!
__________________
CMUCam not working? Tracks sporadically? Try this instead: http://www.falconir.com!
PM me for more information if you are interested (it's open source!).

Want the FIRST Email blasts? See here: http://www.chiefdelphi.com/forums/sh...ad.php?t=50809

"The harder the conflict, the more glorious the triumph. What we obtain too cheaply, we esteem too lightly; it is dearness only that gives everything its value."
-- Thomas Paine

If it's falling apart it's a mechanical problem. If it's spewing smoke it's a electrical problem.
If it's rampaging around destroying things it's a programming problem.

"All technology is run on 'Magic Smoke' contained within the device. As everyone knows, whenever the magic smoke is released, the device ceases to function."
-- Anonymous

I currently speak: English, some German, Verilog, x86 and 8051 Assembler, C, C++, VB, VB.NET, ASP, PHP, HTML, UNIX and SQL
  #3   Spotlight this post!  
Unread 29-01-2006, 17:44
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,187
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: SONAR Sensor Software Driver

Yeah, thanks alot Mike. It works perfectly.

This saved me hours of coding, and I'm sure it will do the same for many others.
  #4   Spotlight this post!  
Unread 08-02-2006, 21:07
CronosPrime1 CronosPrime1 is offline
Registered User
FRC #0321
 
Join Date: Jan 2006
Location: Hyperspace
Posts: 53
CronosPrime1 is an unknown quantity at this point
Re: SONAR Sensor Software Driver

Why is this code so complicated? I really don't see why you need all of this. I don't know anything about programming the range finder, but it seems to me that you should just be able to send the range finder a 0 or a 1 to trigger it and then measure with a timer the time it takes for the pulse to come back. Why is there all this complicated stuff? Is it really needed? I'm not criticizing, I just want to know for my own sake.
__________________
  #5   Spotlight this post!  
Unread 08-02-2006, 22:03
scitobor 617's Avatar
scitobor 617 scitobor 617 is offline
More nerd than you can handle!
AKA: Alan Meekins
FRC #0617 (HSHS 617 "DUKE")
Team Role: Programmer
 
Join Date: Nov 2003
Rookie Year: 2003
Location: Richmond, VA
Posts: 153
scitobor 617 will become famous soon enoughscitobor 617 will become famous soon enough
Send a message via AIM to scitobor 617
Re: SONAR Sensor Software Driver

Quote:
Originally Posted by CronosPrime1
Why is this code so complicated? I really don't see why you need all of this. I don't know anything about programming the range finder, but it seems to me that you should just be able to send the range finder a 0 or a 1 to trigger it and then measure with a timer the time it takes for the pulse to come back. Why is there all this complicated stuff? Is it really needed? I'm not criticizing, I just want to know for my own sake.
I did not write the code but I have read it and it does not seem to have any unnecessary parts. In my opinion it is written very cleanly and only contains the minimum amount of code needed to correctly use an ultrasonic range finder. You are right on target about what must be done to use a range finder, however I believe once you start coding it you will have a very similar solution. The only thing that I see that can be taken out of this code is some of the error checking but error checking is good practice since it means that you have thought of and prepared for things that can go wrong.
__________________
Beta testers needed!
http://www.nullagent.no-ip.com

Your kidding, there are other operating systems besides Linux?!
  #6   Spotlight this post!  
Unread 09-02-2006, 09:53
MikeDubreuil's Avatar
MikeDubreuil MikeDubreuil is offline
Carpe diem
FRC #0125 (Nu-Trons)
Team Role: Engineer
 
Join Date: Jan 2003
Rookie Year: 1999
Location: Boston, MA
Posts: 967
MikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond repute
Send a message via AIM to MikeDubreuil
Re: SONAR Sensor Software Driver

Quote:
Originally Posted by CronosPrime1
Why is this code so complicated? I really don't see why you need all of this. I don't know anything about programming the range finder, but it seems to me that you should just be able to send the range finder a 0 or a 1 to trigger it and then measure with a timer the time it takes for the pulse to come back. Why is there all this complicated stuff? Is it really needed? I'm not criticizing, I just want to know for my own sake.
Since I wrote it I can answer most questions you have on it. For the most part as Alan said the driver does not have any unnecessary lines of code. However, I can address some of the issues that make it a little more complicated than most pieces of software.
  • Two I/O pins being used- this was a necessary evil that I found while writing the software for the Parallax PING))) sensor. I just couldn't get a single I/O pin to change between an output to an input with an interrupt fast enough. I would lose the sonar sensors signal. I didn't know about the Vex Robotics range finder until after originally writing the software. The VEX and Parallax units are very similar if not identical. I think the Vex engineers may have ran into the same problem I did and decided to use two cables.
  • Design- There's a variable that holds the current state of the sonar and functions in the source code file to handle a hardware interrupt and a timer interrupt. The other option would have been one function which triggers the sonar sensor and then loops until the sonar sensor is finished responding. The problem with that design would be that you would be wasting processor time for around 20 mS waiting. This means no other code could be running, the input/output might not happen and the Master uP could think your user program has gone haywire and shut it down.
Any other questions, feel free to ask
__________________
"FIRST is like bling bling for the brain." - Woodie Flowers
  #7   Spotlight this post!  
Unread 18-02-2006, 23:35
MikeDubreuil's Avatar
MikeDubreuil MikeDubreuil is offline
Carpe diem
FRC #0125 (Nu-Trons)
Team Role: Engineer
 
Join Date: Jan 2003
Rookie Year: 1999
Location: Boston, MA
Posts: 967
MikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond repute
Send a message via AIM to MikeDubreuil
Re: SONAR Sensor Software Driver

I have an updated version of the SONAR software driver that supports the 2006 Robot Controller. Get it here: SONAR_0.3.zip
__________________
"FIRST is like bling bling for the brain." - Woodie Flowers
  #8   Spotlight this post!  
Unread 08-03-2006, 13:21
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: SONAR Sensor Software Driver

Quote:
Originally Posted by MikeDubreuil
I have an updated version of the SONAR software driver that supports the 2006 Robot Controller. Get it here: SONAR_0.3.zip
Thank you, thank you, thank you! for writing this code. I'm planning to try it soon (I found a VEX sonar unit at RadioShack last night).

I've been scanning the code to understand it a little. And I found something strange: at one point sonar_status is set to SONAR_REST, but there is no case statement looking for SONAR_REST. In fact, SONAR_REST appears nowhere else in the code except in the .h file where it is created.

Is SONAR_REST a remnant from a previous version? Won't the code get lost if sonar_status is set to SONAR_REST?

-Norm
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #9   Spotlight this post!  
Unread 08-03-2006, 14:34
MikeDubreuil's Avatar
MikeDubreuil MikeDubreuil is offline
Carpe diem
FRC #0125 (Nu-Trons)
Team Role: Engineer
 
Join Date: Jan 2003
Rookie Year: 1999
Location: Boston, MA
Posts: 967
MikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond repute
Send a message via AIM to MikeDubreuil
Re: SONAR Sensor Software Driver

Quote:
Originally Posted by gnormhurst
Is SONAR_REST a remnant from a previous version? Won't the code get lost if sonar_status is set to SONAR_REST?
The code doesn't get lost when the status is set to SONAR_REST. Shortly after the status is set to rest on line 206 the timer is started. In the timer interrupt service routine the status is set to SONAR_OFF. After that occurs, the sonar can be pulsed again with Ping_Sonar(). I found the rest was necessary to allow the sensor to work correctly.

I'm glad you like the software. Please let us know how your testing turns out.
__________________
"FIRST is like bling bling for the brain." - Woodie Flowers
  #10   Spotlight this post!  
Unread 08-03-2006, 18:50
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: SONAR Sensor Software Driver

Quote:
Originally Posted by MikeDubreuil
I'm glad you like the software. Please let us know how your testing turns out.
A couple of quick questions. I'm installing the code without the benefit of hardware to try it on (that will be in a couple of days).

In your README it says
Quote:
4. Add the following code to the if block in user_routines_fast.c/InterruptHandlerLow()

else if (PIR2bits.TMR3IF && PIE2bits.TMR3IE)
{
Timer_Interrupt_Sonar();
}
I did, and I think I did it correctly (code is below).

But step 3 puzzles me.
Quote:
3.) Add Hardware_Interrupt_Sonar() to the if statement that handles the INT2 pin
in user_routines_fast.c/InterruptHandlerLow()
My attempt to interpret step three also appears in the code below.

Here is my modified InterruptHandlerLow (). The mods are in color.
Code:
#pragma code
#pragma interruptlow InterruptHandlerLow save=PROD /* You may want to save additional symbols. */

void InterruptHandlerLow ()     
{                               
  unsigned char int_byte;       
  if (INTCON3bits.INT2IF && INTCON3bits.INT2IE)       /* The INT2 pin is RB2/DIG I/O 1. */
  { 
    Hardware_Interrupt_Sonar();  ////// <--- added to support sonar
    INTCON3bits.INT2IF = 0;
  }
  else if (INTCON3bits.INT3IF && INTCON3bits.INT3IE)  /* The INT3 pin is RB3/DIG I/O 2. */
  {
    INTCON3bits.INT3IF = 0;
  }
  else if (INTCONbits.RBIF && INTCONbits.RBIE)  /* DIG I/O 3-6 (RB4, RB5, RB6, or RB7) changed. */
  {
    int_byte = PORTB;          /* You must read or write to PORTB */
    INTCONbits.RBIF = 0;     /*     and clear the interrupt flag         */
  }                                        /*     to clear the interrupt condition.  */
  
  // the following added to support sonar:
  //
  else if ( PIR2bits.TMR3IF && PIE2bits.TMR3IE )
  {
      Timer_Interrupt_Sonar();
  }
  else
  { 
    CheckUartInts();    /* For Dynamic Debug Tool or buffered printf features. */
  }
}
Comments appreciated.... including comments on i/o pin conflicts that I'm not noticing... Thanks!
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #11   Spotlight this post!  
Unread 08-03-2006, 20:38
Gdeaver Gdeaver is offline
Registered User
FRC #1640
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 2001
Location: West Chester, Pa.
Posts: 1,367
Gdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond repute
Re: SONAR Sensor Software Driver

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.
  #12   Spotlight this post!  
Unread 10-03-2006, 13:39
MikeDubreuil's Avatar
MikeDubreuil MikeDubreuil is offline
Carpe diem
FRC #0125 (Nu-Trons)
Team Role: Engineer
 
Join Date: Jan 2003
Rookie Year: 1999
Location: Boston, MA
Posts: 967
MikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond reputeMikeDubreuil has a reputation beyond repute
Send a message via AIM to MikeDubreuil
Re: SONAR Sensor Software Driver

Quote:
Originally Posted by gnormhurst
Comments appreciated.... including comments on i/o pin conflicts that I'm not noticing... Thanks!
Perfect
__________________
"FIRST is like bling bling for the brain." - Woodie Flowers
  #13   Spotlight this post!  
Unread 10-03-2006, 15:52
jeffmorris jeffmorris is offline
Registered User
no team
 
Join Date: Sep 2005
Location: staten island, ny
Posts: 62
jeffmorris is on a distinguished road
Re: SONAR Sensor Software Driver

How do I connect the PING))) sensor made for Parallex robots to the VEX Micro Controller and program the sensor in EasyC 2.0?
  #14   Spotlight this post!  
Unread 16-03-2006, 16:34
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: SONAR Sensor Software Driver

Quote:
Originally Posted by MikeDubreuil
Perfect
IT WORKS! Cool. Thanks so much for the code.

NOTE: ERROR IN VEX SONAR DATA SHEET! The data sheet that comes with the VEX sonar kit has an error. It says,
Quote:
The connector labelled "OUTPUT" is the trigger output of the Vex microcontroller;...
and
Quote:
The connector Labelled "INPUT" is the echo response from the ultrasonic detector; this is the line through which the Vex microcontroller receives output from the detector, ...
Well, that seemed backwards to me, but I carefully hooked up the "OUTPUT" to the digital_io_16 port on the FRC, which your code uses to signal the unit to ping, and hooked the "INPUT" to the INT2 (digital_io_1) port on the FRC. It didn't work. I checked everything else, then switched the two wires. Then it worked. THE VEX DOCUMENTATION IS BACKWARDS. The device's wire marked "output" is indeed the output of the device.

One way to tell that it's hooked up right and the software is pinging it is to hold the device up to your ear and listen to it. When I got it working I could hear a faint "tictictictic..." coming from the device. I did not hear that before I switched the wires.

Thanks again. Now I have to write new autonomous code that I can't test on the robot until we get to the next regional.
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #15   Spotlight this post!  
Unread 06-04-2006, 15:52
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: SONAR Sensor Software Driver

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.


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
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Toshiba Cardbus Problem? jpsaul7usa Chit-Chat 12 01-01-2006 02:37
Introducing the Driver Strategy Database's Online Database impulse3D Rules/Strategy 17 17-03-2005 03:04
Updated: Serial Port Driver Code Kevin Watson Programming 4 05-02-2005 18:39
New Serial Port Driver Kevin Watson Programming 16 09-01-2005 01:56
Middle School Drivers ram General Forum 40 26-02-2003 17:01


All times are GMT -5. The time now is 21:12.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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