Go to Post "Insanity: doing the same thing over and over again and expecting different results." - Albert Einstein - Edward Debler [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 25-01-2015, 20:15
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
How send ultrasonic sensor data to driver station?

Hi! We want to use some ultrasonic sensors so the driver can get an idea how close they are to the crates or other robots. My question is how can I send the data to the driver station from the RIO? Should I make a program that sends the data through TCP to the driver station computer? I am using Python and RobotPy but if you know how to do it in Java, I could try to change that to Python. Any help will be greatly appreciated!
  #2   Spotlight this post!  
Unread 25-01-2015, 20:30
cad321 cad321 is online now
Jack of all trades, Master of none
AKA: Brian Wagg
FRC #2386 (Trojans)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Burlington, Ontario
Posts: 348
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
Re: How send ultrasonic sensor data to driver station?

Although Im not familiar with python, in Java you would do this:

Code:
distance = Ultrasonic.getRangeInches();
        
SmartDashboard.putNumber("UltraSonic Distance", distance);
however you might be better off (if you can) making to have some LED's turn a certain colour on your robot when you are on target. Perhaps red for really far, yellow for partially on target and green for on target. This would allow the driver to keep his eyes on the robot apposed to him having to look down at the driver station constantly to see how far he is from the tote.
  #3   Spotlight this post!  
Unread 25-01-2015, 20:32
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: How send ultrasonic sensor data to driver station?

So there is a special kind of Driver Station called SmartDashboard. It is basically an 'application' that you can add (basically) anything to, including Ultrasonic values. To do this, create an analog input object (we'll call this ultrasonic).
Code:
self.ultrasonic = wpilib.AnalogInput(PortNumber)
Now, we must add it to SmartDashboard.
Code:
wpilib.SmartDashboard.putNumber('Ultrasonic', self.ultrasonic.getVoltage())
The reason it is getVoltage() is because thats how the ultrasonic returns its values, so it'd be best to set up a test board, then hold something in front of it at measured distances, record these values, then use them in your code.

For more SmartDashboard help check out http://robotpy.readthedocs.org/en/la...Dashboard.html
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #4   Spotlight this post!  
Unread 25-01-2015, 20:36
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: How send ultrasonic sensor data to driver station?

Quote:
Originally Posted by TimTheGreat View Post
So there is a special kind of Driver Station called SmartDashboard. It is basically an 'application' that you can add (basically) anything to, including Ultrasonic values. To do this, create an analog input object (we'll call this ultrasonic).
Code:
self.ultrasonic = wpilib.AnalogInput(PortNumber)
Now, we must add it to SmartDashboard.
Code:
wpilib.SmartDashboard.putNumber('Ultrasonic', self.ultrasonic.getVoltage())
The reason it is getVoltage() is because thats how the ultrasonic returns its values, so it'd be best to set up a test board, then hold something in front of it at measured distances, record these values, then use them in your code.

For more SmartDashboard help check out http://robotpy.readthedocs.org/en/la...Dashboard.html
So both of those lines you would put in the RIO's code? Do I have to import anything else other than wpilib? Thanks for the detailed response!
  #5   Spotlight this post!  
Unread 25-01-2015, 20:45
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: How send ultrasonic sensor data to driver station?

Quote:
Originally Posted by team-4480 View Post
So both of those lines you would put in the RIO's code? Do I have to import anything else other than wpilib? Thanks for the detailed response!
Yup. Put both of these lines in roboInit and you should be good. And do you know how to start the smart dashboard?
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #6   Spotlight this post!  
Unread 25-01-2015, 20:51
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: How send ultrasonic sensor data to driver station?

Quote:
Originally Posted by TimTheGreat View Post
Yup. Put both of these lines in roboInit and you should be good. And do you know how to start the smart dashboard?
No I don't know how to start it up. Thanks again!
  #7   Spotlight this post!  
Unread 25-01-2015, 21:01
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: How send ultrasonic sensor data to driver station?

Ok, so first you want to make sure you have this folder on the driver station http://tinyurl.com/smrtdshbd. On the DS, go to wpilib -> tools -> smartdashboard.jar when you are connected to the robot. To test your code on your own computer, make sure you have the robotpy eclipse plugins https://github.com/robotpy/robotpy-e...ster/README.md. Then, in the eclipse menu bar, click WPILib, then Run Simulation Smartdashboard. This will let you see the ultrasonic sensor change based on the value you change in the simulator.
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #8   Spotlight this post!  
Unread 25-01-2015, 21:03
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,753
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: How send ultrasonic sensor data to driver station?

The NetworkTables shared storage is implemented across all languages and all dashboards. So you can pretty easily add the display to either dashboard and publish on your robot.

Greg McKaskle
  #9   Spotlight this post!  
Unread 25-01-2015, 21:18
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: How send ultrasonic sensor data to driver station?

Quote:
Originally Posted by TimTheGreat View Post
Ok, so first you want to make sure you have this folder on the driver station http://tinyurl.com/smrtdshbd. On the DS, go to wpilib -> tools -> smartdashboard.jar when you are connected to the robot. To test your code on your own computer, make sure you have the robotpy eclipse plugins https://github.com/robotpy/robotpy-e...ster/README.md. Then, in the eclipse menu bar, click WPILib, then Run Simulation Smartdashboard. This will let you see the ultrasonic sensor change based on the value you change in the simulator.
I wrote some code that would interpret the distance and then display a red, yellow or green light on the remote machine. I saw in the link you sent me(robotpy one), you could import networktables so I was wondering if I could use that in the program I wrote, not needing to go through the smartdashboard? In summary, I just want to use the info from the sensors to input in my wxpython program. Thanks!
  #10   Spotlight this post!  
Unread 25-01-2015, 21:24
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: How send ultrasonic sensor data to driver station?

Quote:
Originally Posted by team-4480 View Post
I wrote some code that would interpret the distance and then display a red, yellow or green light on the remote machine. I saw in the link you sent me(robotpy one), you could import networktables so I was wondering if I could use that in the program I wrote, not needing to go through the smartdashboard? In summary, I just want to use the info from the sensors to input in my wxpython program. Thanks!

Ok, if you just want to use the info from the sensors, then you just need to use self.ultrasonic.getVoltage(). You don't have to go through SmartDashboard, but for getting the data of the ultrasonic (what the value is when the robot is 5 inches from the bin, for example), it would be wise to just put that value in SDB and write it down.
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #11   Spotlight this post!  
Unread 25-01-2015, 21:37
nandeeka's Avatar
nandeeka nandeeka is offline
Registered User
FRC #1868
Team Role: Programmer
 
Join Date: May 2014
Rookie Year: 2013
Location: United States
Posts: 53
nandeeka is on a distinguished road
Re: How send ultrasonic sensor data to driver station?

Quote:
Originally Posted by TimTheGreat View Post
it would be wise to just put that value in SDB and write it down.
Instead of writing down the values read by the SmartDashboard, you can just use the csv.txt file. In the preferences menu, just click the checkbox labeled "Log to CSV" before you enable a run you want to record. The file records a timestamp and a key value pair every time the putNumber function is called.
  #12   Spotlight this post!  
Unread 25-01-2015, 21:39
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: How send ultrasonic sensor data to driver station?

Quote:
Originally Posted by nandeeka View Post
Instead of writing down the values read by the SmartDashboard, you can just use the csv.txt file. In the preferences menu, just click the checkbox labeled "Log to CSV" before you enable a run you want to record. The file records a timestamp and a key value pair every time the putNumber function is called.
But that wouldn't tell you the distance of what you're measuring. So you can just write 5ft, 4.34 volts
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #13   Spotlight this post!  
Unread 25-01-2015, 21:48
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 229
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: How send ultrasonic sensor data to driver station?

Quote:
Originally Posted by TimTheGreat View Post
But that wouldn't tell you the distance of what you're measuring. So you can just write 5ft, 4.34 volts
Ok thanks, I will try to set up the SmartDashboard tomorrow. Though it does sound quite complicated to set up. Thanks so much for your help!!!

Last edited by team-4480 : 25-01-2015 at 21:50.
  #14   Spotlight this post!  
Unread 25-01-2015, 21:59
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: How send ultrasonic sensor data to driver station?

team-4480, since you have a lot of questions, it may benefit you to go to https://webchat.freenode.net/ and join the #robotpy channel. VirtualD and I are normally on there (he more than I) and it would be faster communication
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #15   Spotlight this post!  
Unread 27-01-2015, 14:48
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,086
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: How send ultrasonic sensor data to driver station?

WPILib has an ultrasonic sensor implementation that you may find useful: http://robotpy.readthedocs.org/en/la...ltrasonic.html

Once you get the distance data, you can send it to SmartDashboard as mentioned earlier -- wpilib.SmartDashboard.putNumber().

Running SmartDashboard/SFX is pretty simple, and is great for viewing the raw values that the robot sends back. However, if you want to do something with the values, you shouldn't use SmartDashboard/SFX (unless you want to write a SmartDashboard/SFX extension in java).

If you want to write your own networktables client (for example, your wxpython program) to talk to the robot, and receive values from the robot, check out pynetworktables. What you would do is import networktables, get the SmartDashboard table, and ask for the values. You can also get notifications when new data values are sent by the robot, for easier usage.

There's an example here and here.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff

Last edited by virtuald : 27-01-2015 at 14:50.
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 21:05.

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