Go to Post Safety glasses may be a nice forehead protector, but thats not what they are made for. - Quatitos [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 22-11-2014, 17:22
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Parallax PING))) Java Coding

Our team bought the Ping))) sensor for distance sensing. As per this forum post, we could use a PWM Y-cable to connect it to the digital sidecar. How do we code this in Java? I believe that the WPILib Ultrasonic class is meant for those sensors with an input and output.

The Ping))) has a built-in SX microcontroller with the job of generating the pulse and patiently waiting for that pulse to make it's way back. It then sends back a pulse, with a width that translates into the distance, by the multiplication of a specific constant, 2260 for centimeters and 890 for inches.

Note that the time units are in microseconds.

How do I send 30 microsecond pulse to a digital output and read back the input pulse, probably from a different pin if I use the Y-cable method?
  #2   Spotlight this post!  
Unread 22-11-2014, 17:56
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,078
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Parallax PING))) Java Coding

Code:
DigitalOutput.set(true); //Needs to be a properly constructed DigitalOutput object.
Timer.delay(0.00003); //This is a static method.
DigitalOutput*.set(false); //Same object from above.
while {DigitalInput.get()=false} ////Needs to be a properly constructed DigitalInput object.
double starttime=Timer.getFPGATimestamp(); //This is a static method. You can use a Timer object, but I like this method better.
while{DigitalInput.get() = true} //Same object from above.
double pingtime = Timer.getFPGATimestamp() - starttime; //Same method from above.
double distance = pingtime * (appropriate scalar);
This should be separately threaded so the microsecond timing doesn't depend on the control loop and so the wait loops don't cause a loss of robot control.
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)


Last edited by cgmv123 : 22-11-2014 at 21:00.
  #3   Spotlight this post!  
Unread 22-11-2014, 20:52
Jared's Avatar
Jared Jared is offline
Registered User
no team
Team Role: Programmer
 
Join Date: Aug 2013
Rookie Year: 2012
Location: Connecticut
Posts: 602
Jared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond reputeJared has a reputation beyond repute
Re: Parallax PING))) Java Coding

Quote:
Originally Posted by cgmv123 View Post
Code:
DigitalOutput.set(true); //Needs to be a properly constructed DigitalOutput object.
Timer.delay(0.00003); //This is a static method.
DigitalOutput*.set(false); //Same object from above.
while {DigitalInput.get()=false} ////Needs to be a properly constructed DigitalInput object.
double starttime=Timer.getFPGATimestamp(); //This is a static method. You can use a Timer object, but I like this method better.
while{DigitalInput.get() = true} //Same object from above.
double pingtime = Timer.getFPGATimestamp(); //Same method from above.
double distance = pingtime * (appropriate scalar);
This should be separately threaded so the microsecond timing doesn't depend on the control loop and so the wait loops don't cause a loss of robot control.
I'm not sure this will work for a few reasons. First, I doubt that our setup with Java on the cRIO (or Java running on anything) will time the 30 microsecond pulse very accurately if you set it up the way you have it now.

Also, you'd need to run this loop really quickly to capture the pulse. If you're one inch away, your pulse is less than a millisecond away. It's possible to miss pulses entirely.

You really should use interrupts for this, or you should just add an arduino board that communicates with the cRIO with serial. I bet somebody has written an arduino library for this sensor.

Also, your timing method doesn't seem to compare the two FPGA timestamps to find the duration of the pulse. I don't think your two while loops will work the way you'd like them to.
  #4   Spotlight this post!  
Unread 22-11-2014, 21:02
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,078
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Parallax PING))) Java Coding

Quote:
Originally Posted by Jared View Post
I'm not sure this will work for a few reasons. First, I doubt that our setup with Java on the cRIO (or Java running on anything) will time the 30 microsecond pulse very accurately if you set it up the way you have it now.

Also, you'd need to run this loop really quickly to capture the pulse. If you're one inch away, your pulse is less than a millisecond away. It's possible to miss pulses entirely.

You really should use interrupts for this, or you should just add an arduino board that communicates with the cRIO with serial. I bet somebody has written an arduino library for this sensor. ... I don't think your two while loops will work the way you'd like them to.
I wasn't sure how effective this code would be. I was just trying to provide a starting point for the OP.

Quote:
Also, your timing method doesn't seem to compare the two FPGA timestamps to find the duration of the pulse.
I should have subtracted starttime. Added now.
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

  #5   Spotlight this post!  
Unread 23-11-2014, 10:17
yash101 yash101 is offline
Curiosity | I have too much of it!
AKA: null
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: devnull
Posts: 1,191
yash101 is an unknown quantity at this point
Re: Parallax PING))) Java Coding

Quote:
Originally Posted by Jared View Post
I'm not sure this will work for a few reasons. First, I doubt that our setup with Java on the cRIO (or Java running on anything) will time the 30 microsecond pulse very accurately if you set it up the way you have it now.

Also, you'd need to run this loop really quickly to capture the pulse. If you're one inch away, your pulse is less than a millisecond away. It's possible to miss pulses entirely.

You really should use interrupts for this, or you should just add an arduino board that communicates with the cRIO with serial. I bet somebody has written an arduino library for this sensor.

Also, your timing method doesn't seem to compare the two FPGA timestamps to find the duration of the pulse. I don't think your two while loops will work the way you'd like them to.
I was going to use a Parallax Propeller board. I've never used an Arduino, but have used many of Parallax products, including this sensor in the past. Parallax itself provides libraries which should be sufficient to perform this task.

Quote:
Originally Posted by cgmv123 View Post
I wasn't sure how effective this code would be. I was just trying to provide a starting point for the OP.



I should have subtracted starttime. Added now.
That was the one thing I was wondering. If you disregard the start time, the measurement would be quite wrong!
It is a good starting point and I am happy that you shared this. We are pressed for time in our team and we just got a bot ready to program using. That means that our programming team is heavily behind at this moment.

I am considering telling my team not to waste time on sonar. I am already able to make vision systems that are able to mimmic this functionality, but without the main issues such as range, accuracy and constant calibration. This sensor is also quite slow, not fast enough for powering automated movement. The main use for this is obstacle detection while moving when video stabilization is not enough to remove the motion blur.
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


All times are GMT -5. The time now is 02:40.

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