Go to Post We live for those eureka moments. Whether we win or lose competitions, it's those moments when a student's idea makes something just "click" that will stick with them and influence them to become engineers. - ToddF [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #16   Spotlight this post!  
Unread 16-01-2013, 20:11
mrklempae mrklempae is offline
Registered User
no team
 
Join Date: Jan 2013
Location: Montana
Posts: 19
mrklempae is an unknown quantity at this point
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"
#include <WPILib.h>
#define ANALOG_CHANNEL_FOR_SONAR 1

class Robot2012 : public IterativeRobot
{
   AnalogRangeFinder sonar;
   public:
   Robot2012(void):sonar(ANALOG_CHANNEL_FOR_SONAR)
   {
   }

   void AutonomousPeriodic(void)
   {
   }
	void OperatorControl(void)
	{
		DriverStationLCD *dsLCD = DriverStationLCD::GetInstance();
		float distance = sonar.GetRangeInches();
		while (IsOperatorControl())
		{
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line1, "My Value is: %d", distance);
			dsLCD->UpdateLCD();
			Wait(0.1);
		}}}
}

START_ROBOT_CLASS(Robot2012);
I'm really sorry about this, but I just threw together the code, untested. I don't currently have access to the code we used. Does anyone know how to do this? We tried different things for two hours or so to no avail. We returned data one time (something like 22354698), which I'm pretty sure is WAY out of the sensors range. P.S, ScottW, THANKS! Once we get this part working, that information will be perfect!
Reply With Quote
 


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 14:26.

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