![]() |
Re: Programming ultrasonic rangefinders
I tried using the code you provided, and it compiled. My next problem is printing the distance to the Driver Station in real time to prove the code and/or our sensor works. We copied and pasted the .cpp ad .h file into the BuiltInDefaultCode, then copied your code into the main .cpp file. We made sure the robot was correctly wired. We tried changing the code a little to get data prited, but couldn't print any data (or at least not the right data).
Code:
#include "AnalogRangeFinder.h" |
Re: Programming ultrasonic rangefinders
In the code you posted here, you only read the distance once, then constantly send it to the driver station, this could cause some odd behavior (assuming the sonar has a bit of turn on transient).
Also, if you are using iterative robot, I would suggest using it's Disabled/Autonomous/Teleop functions, instead of the ones used by simple robot (which may not even work). This code should do what you want to do, and uses IterativeRobot functions: Code:
#include "WPILib.h" |
Re: Programming ultrasonic rangefinders
Is there a benefit to using IterativeRobot instead of SimpleRobot? I'm just wondering. We've been writing all of our simple programs using SimpleRobot to demonstrate the various functions of the robot. Thanks for this, by the way! Our primary problem was a bad PWM cable. We'll be testing to see if we can get the new sensor working today.
|
Re: Programming ultrasonic rangefinders
With the recently posted build of WPILib you should be able to see the AnalogChannel show up on the SmartDashboard in Test mode. From there you'll see the voltages that correspond to distances and it will verify that the sensor is working.
See this page for more information about viewing the Test mode values: http://wpilib.screenstepslive.com/s/...ode-livewindow As it shows, you can either explicitly set up the test mode values yourself and get meaningful names for the sensors or you can let WPILib automatically add them. There are examples of each case on that page. Hope this helps. Brad |
Re: Programming ultrasonic rangefinders
Quote:
It makes it easier to add all of your code to the periodic functions, and if you need to add some time sensitive code, it can be added into continuous without restructuring your code. By removing while loops (or hiding them in the base class), it helps prevent getting stuck in auton mode and never getting to teleop, and in general it encourages writing non-blocking code. |
| All times are GMT -5. The time now is 14:24. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi