Go to Post By the looks, 1114 has already figured out both #1 and #2. They're still behind 71, who is just about done with their robot for the 2012 season, is getting driver practice for 2011, and is working on their robot designs for the 2013 water game. You're still way behind. - EricH [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 Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 16-02-2012, 20:10
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)

Disclaimer!! Currently this isn't tested!

So, apparantly this code wasn't included in WPILib, so I wrote one myself. I haven't tested it yet so please use with caution, but it's primarily copy-pasted from a mashup of gyroscope and accellerometer classes.

Reviews and corrections are welcome. This weekend when we get the thing actually wired I'll post with any updates if needed.

(this is the h file)

Code:
#ifndef ANALOGRANGEFINDER_H
#define ANALOGRANGEFINDER_H

#include "SensorBase.h"
#include "PIDSource.h"

class AnalogChannel;
class AnalogModule;

#define ANALOG_RANGE_FINDER_DEFAULT_INCHES_PER_MV  0.1024F

//Designed for the MaxBotix LV-MaxSonarŽ-EZ1, but should work for any analog output sonar module
class AnalogRangeFinder : public SensorBase, public PIDSource
{
private:
	float inchesPerMillivolt;
	AnalogChannel *m_analogChannel;
	bool m_allocatedChannel;
	
	void InitAnalogRangeFinder(void)
	{
		inchesPerMillivolt = ANALOG_RANGE_FINDER_DEFAULT_INCHES_PER_MV;
	}
	
public:
	AnalogRangeFinder(UINT8 moduleNumber, UINT32 channel);
	explicit AnalogRangeFinder(UINT32 channel)
	{

		m_analogChannel = new AnalogChannel(channel);
		m_allocatedChannel = true;
		InitAnalogRangeFinder();
	}
	explicit AnalogRangeFinder(AnalogChannel *channel)
	{
		if (channel != NULL)
		{
			m_analogChannel = channel;
			InitAnalogRangeFinder();
			m_allocatedChannel = false;
		}
	}
	explicit AnalogRangeFinder(AnalogChannel &channel)
	{
		m_analogChannel = &channel;
		m_allocatedChannel = false;
		InitAnalogRangeFinder();
	}
	
	virtual ~AnalogRangeFinder()
	{
		if (m_allocatedChannel)
		{
			delete m_analogChannel;
		}
	}
	
	virtual float GetRangeInches()
	{
		return m_analogChannel->GetVoltage() * inchesPerMillivolt;
	}
	void SetSensitivity(float inches_per_millivolt)
	{
		inchesPerMillivolt = inches_per_millivolt;
	}
	
	// PIDSource interface
	double PIDGet()
	{
		return GetRangeInches();
	}
	
};


	
#endif
I would rather have tested this before putting it out here, but seeing as everyones at a crunch for time, I'd rather give someone hope. If this thing happens to be buggy, check back here saturday afternoon/evening and I should have it fixed.
Attached Files
File Type: h AnalogRangeFinder.h (1.5 KB, 11 views)

Last edited by DjScribbles : 16-02-2012 at 20:14. Reason: Added code
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 09:47.

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