View Single Post
  #13   Spotlight this post!  
Unread 13-04-2010, 00:42
Bigcheese Bigcheese is offline
C++0x FTW!
AKA: Michael Spencer
FRC #1771
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: GA
Posts: 36
Bigcheese is a jewel in the roughBigcheese is a jewel in the roughBigcheese is a jewel in the roughBigcheese is a jewel in the rough
Re: Unexpected results from Encoder::GetRate()

Here's 4x decoding data with the same changes to Encoder.cpp as listed above.

http://spreadsheets.google.com/ccc?k...E1zX 2c&hl=en

And here's the relevant code for getting the data.

Code:
void  updateCSV(void* stream)
{
	CompetitionRobot1771* r = CompetitionRobot1771::GetInstance();
	std::ofstream& s = *reinterpret_cast<std::ofstream*>(stream);

	static double left_previous_distance = r->m_PMU.m_leftEncoder.GetDistance();
	static double right_previous_distance = r->m_PMU.m_rightEncoder.GetDistance();
	static double previous_time = static_cast<double>(GetFPGATime() - r->m_BumpTestStartTime) * 1e-6;

	double current_time = static_cast<double>(GetFPGATime() - r->m_BumpTestStartTime) * 1e-6;

	double left_distance = r->m_PMU.m_leftEncoder.GetDistance();
	double right_distance = r->m_PMU.m_rightEncoder.GetDistance();

	double left_derived_rate = (left_distance - left_previous_distance) / (current_time - previous_time);

	double right_derived_rate = (right_distance - right_previous_distance) / (current_time - previous_time);

	double left_rate = r->m_PMU.m_leftEncoder.GetRate();
	double right_rate = r->m_PMU.m_rightEncoder.GetRate();

	s << current_time << "," << r->m_CO << ","
	  << left_distance << "," << left_rate << "," << left_derived_rate << ","
	  << right_distance << "," << right_rate << "," << right_derived_rate << std::endl;

	left_previous_distance = left_distance;
	right_previous_distance = right_distance;
	previous_time = current_time;

	r->GetWatchdog().Feed();
}

void CompetitionRobot1771::Autonomous(void) 
{
	GetWatchdog().SetEnabled(true);
	while(IsAutonomous() && IsEnabled())
	{
		GetWatchdog().Feed();
		std::ofstream csv("bump_test.csv", std::ios::trunc);
		Notifier csv_update(updateCSV, &csv);

		csv << "Time,CO,Left Distance,Left PV,Left Derived PV,Right Distance,Right PV,Right Derived PV\n";
		m_CO = 0;
		m_BumpTestStartTime = GetFPGATime();

		m_PMU.m_leftEncoder.Reset();
		m_PMU.m_rightEncoder.Reset();
		
		csv_update.StartPeriodic(0.005);

		foreach(CANJaguar* c, m_LeftJags)
		{
			c->Set(-m_CO);
		}
		foreach(CANJaguar* c, m_RightJags)
		{
			c->Set(m_CO);
		}
		Wait(0.1);
		
		m_CO = m_BumpTestCO;
		foreach(CANJaguar* c, m_LeftJags)
		{
			c->Set(-m_CO);
		}
		foreach(CANJaguar* c, m_RightJags)
		{
			c->Set(m_CO);
		}
		Wait(m_BumpTestTime);
		
		m_CO  = 0;
		foreach(CANJaguar* c, m_LeftJags)
		{
			c->Set(-m_CO);
		}
		foreach(CANJaguar* c, m_RightJags)
		{
			c->Set(m_CO);
		}
		Wait(m_BumpTestTime);

		csv_update.Stop();
	}
}
I agree that the problem is with the period returned by the FPGA.
Reply With Quote