View Single Post
  #5   Spotlight this post!  
Unread 18-02-2012, 16:06
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
Re: Freebie LV-MaxSonar-EZ1 Code (Sonar Range Finder)

So, I made some fixes to the code, the primary change is that it now (properly) uses an inches/volt conversion factor instead of millivolts (which the analog channel is not providing).

Our range finder isn't fully working yet, but we think we're down to an issue with the frame of the robot being slightly within the cone of the audio pulse, and causing some erratic responses.

If you end up using this code, please let me know (if nobody finds it helpful, I'll be alot less likely to make the effort to post this stuff in the future )

Here's the C file for those who just want to peak:

Code:
#include "AnalogRangeFinder.h"
#include "AnalogModule.h"
#include "AnalogChannel.h"

void AnalogRangeFinder::InitAnalogRangeFinder(void)
{
	inchesPerVolt = ANALOG_RANGE_FINDER_DEFAULT_INCHES_PER_VOLT;
}

AnalogRangeFinder::AnalogRangeFinder(UINT8 moduleNumber, UINT32 channel)
{
	m_analogChannel = new AnalogChannel(moduleNumber,channel);
	m_allocatedChannel = true;
	InitAnalogRangeFinder();
}

AnalogRangeFinder::AnalogRangeFinder(UINT32 channel)
{
	m_analogChannel = new AnalogChannel(channel);
	m_allocatedChannel = true;
	InitAnalogRangeFinder();
}

AnalogRangeFinder::AnalogRangeFinder(AnalogChannel *channel)
{
	if (channel != NULL)
	{
		m_analogChannel = channel;
		InitAnalogRangeFinder();
		m_allocatedChannel = false;
	}
}

AnalogRangeFinder::AnalogRangeFinder(AnalogChannel &channel)
{
	m_analogChannel = &channel;
	m_allocatedChannel = false;
	InitAnalogRangeFinder();
}

AnalogRangeFinder::~AnalogRangeFinder()
{
	if (m_allocatedChannel)
	{
		delete m_analogChannel;
	}
}

float AnalogRangeFinder::GetRangeInches()
{
	return m_analogChannel->GetVoltage() * inchesPerVolt;
}

float AnalogRangeFinder::GetVoltage()
{
	return m_analogChannel->GetVoltage();
}

void AnalogRangeFinder::SetSensitivity(float inches_per_volt)
{
	inchesPerVolt = inches_per_volt;
}


// PIDSource interface
double AnalogRangeFinder::PIDGet()
{
	return GetRangeInches();
}
Attached Files
File Type: cpp AnalogRangeFinder.cpp (1.4 KB, 41 views)
File Type: h AnalogRangeFinder.h (1,020 Bytes, 42 views)
Reply With Quote