Go to Post I have a feeling that we're about to deprive the world of Poof balls for a while. - DCA Fan [more]
Home
Go Back   Chief Delphi > Technical > Programming
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
  #1   Spotlight this post!  
Unread 18-03-2011, 18:38
duffany1 duffany1 is offline
Registered User
AKA: Brandon
FRC #0195 (The Cyberknights)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2006
Location: Southington, CT
Posts: 17
duffany1 is an unknown quantity at this point
PID ... Iterative Robot Question (C++)

Hi, so I am having a bunch of trouble. (C++)

We didn't really feel like using the PIDController on this year's bot. So, we decided to create a PID loop ourselves. And, it works extremely nicely. We have everything tuned properly, and we even got first place at the WPI Regional with this PID code. So really, nothing is wrong with the PID loop itself.

However, we have a problem. As I am trying just now to get autonomous working, I realized that the timing on the PID loop is not quite right.

We are using the IterativeRobot class in order to call the PID loop periodically (and according to the documentation, the period is 1/10000 of a second, shown here: wpi.edu > WPI Robotics Library: IterativeRobot Class Reference).

We have taken advantage of the fact that PID gets called periodically and we have just added a simple timer to that loop that we can set at any time and have it automatically decrement.

However, this timer appears to be roughly twice as slow as it should be! We printed it to the display and every two seconds the value of dly_tmr appeared to be decrementing by one.

Can anyone help?
At this point I am unsure as to whether I am even calling pid() in the correct manner. Should I even be using the IterativeRobot class for this?

Thanks in advance!!

Here's the code (massively wittled down, of course)

Code:
#include "WPILib.h"
#include <math.h>
#include "Utilities.h"
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


// IRQ
const double IRQ_RATE = 10000.0; // period in microseconds
const float irq_rate_ms = IRQ_RATE / 1000; // period in milliseconds
const float irq_rate_sec = IRQ_RATE / 1000000; // period in milliseconds

class Team195Robot2011 : public IterativeRobot
{
       
public:
	
	Team195Robot2011(void):
		
		// Construction
		
	{
		GetWatchdog().SetExpiration(0.1);
	}
	
	void pid(void) //PID_IRQ
	{
		
		// Getting pot values, PID calculations, setting motor positions, etc.
		
		dly_tmr -= irq_rate_sec;

	}
	
	
	void RobotInit(void)
	{
		// Functions
	}

	// @AUTONOMOUS

	void AutonomousInit(void)
	{
		GetWatchdog().SetEnabled(false);
	}
	
	void AutonomousPeriodic(void)
	{
		pid();
	}

    void AutonomousContinuous(void)
	{
    	// Code
	}
	
	// @TELEOPERATED

	void TeleopInit(void)
	{
		GetWatchdog().SetEnabled(false);
	}
	
	void TeleopPeriodic(void)
	{
		pid();
	}

	// @MAIN 
	
	void TeleopContinuous(void)
	{
		
		// Super secret codez.
		// Print dly_tmr to the display.
	}

	// @DISABLED FUNCTIONS 
	
	void DisabledInit(void)
	{
	}
	
	void DisabledPeriodic(void)
	{
	}

	void DisabledContinuous(void)
	{
	}
	
};

START_ROBOT_CLASS(Team195Robot2011);
 


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 03:52.

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