View Single Post
  #12   Spotlight this post!  
Unread 02-03-2009, 08:03 AM
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,069
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: WPILib PID controller object

Quote:
Originally Posted by sircedric4 View Post
I have been trying to get the PIDController to work with my robot the last few days without any luck. What we want to do is exactly like the example above. We have a turret and a potentiometer that we want to use and everytime I include the PIDController calls in my program, the cRIO just locks up and goes to its disabled mode. (All my Jaguars and Victors flashing)

I have an error message that was outputted when it crashes, does anyone know what is going on, or what this means?

---------------------------------------------------------------------
eclipse.buildId=20080514-1211
java.version=1.5.0_11
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Command-line arguments: -os win32 -ws win32 -arch x86

Info
Mon Feb 02 17:19:12 CST 2009
Target Exception: Vector 0x600 : Alignment Exception status=0x134CE7C on VxWorks6x_10.29.92.2 in Kernel Task FRC_RobotTask:0xc7b6c8
at pc=0x134CE98 in SetSetpoint()
---------------------------------------------------------------------

For further information I am using the Iterative Robot example and here is the pertinant code: I already have a bunch of code written and like the Iterative over the Simple Robot so any changes from the example code you see, I had to do to get the program to compile.

************************************************** ****
In my .h file:
Jaguar *TurretPIDMotor;
AnalogChannel *TurretPIDPot;
PIDController *turretControl;

In my .cpp file:

In TeleopInit()
Jaguar TurretPIDMotor(3);
AnalogChannel TurretPIDPot(1);
PIDController turretControl(0.1,0.001,0.0, &TurretPIDPot, &TurretPIDMotor);
turretControl.Enable();

In TeleopPeriodic()
TurretGoto is being set from 0-5 using an equation and it is float defined
turretControl->SetSetPoint(TurretGoto);

************************************************** **

I tried putting the stuff in TeleopInit up in the top of the code before any functions are called and where most of my other variables are set or initalized but it wouldn't compile. The code compiles with everything above. I also tried using "turretControl.SetSetPoint" as was shown in the example, but I had to use "->" to get it to compile. (This is an issue I am always having, I don't know what all the ".", "->", "&", "*" and stuff means or why some times one works and one doesn't)

I am almost to the point where I am thinking of just writing my own subroutine so that I can at least know what the code I am using is doing. The PIDController looks like an awesome shortcut though so I would rather try to get it to work first. The above code compiles fine but when I run the robot it doesn't work.

I am using a 10-turn potentiometer as the sensor and a window motor as the motor driving the sensor.

Can anyone give me some pointers or have you already solved this problem and can tell me how you fixed it?
This looks to be a scope issue. You have declared your variables as types "Jaguar *", "AnalogChannel *", and "PIDController *". These are POINTERS to objects of the given class types. Then, in TeleopInit(), you declare NEW variables of type "Jaguar", "AnalogChannel", and "PIDController". These are not pointers, but rather the objects themselves. Since the types are different, you are actually declaring completely different variables in TeleopInit(). And, since they are declared in a function, after the function is done the variables are out of scope and can no longer be used.

In order to have everything work properly, you need to reconcile the differences. Try putting this in TeleopInit():

Code:
In TeleopInit()
TurretPIDMotor = new Jaguar(3);
TurretPIDPot = new AnalogChannel(1);
turretControl = new PIDController(0.1,0.001,0.0, TurretPIDPot, TurretPIDMotor);
turretControl->Enable();
When you have variables of type "class_name *", they are pointers and you must create something for them to point to. Hence, the "new" operator. Now, actual objects (without the *) can have their members referenced with the dot (.) operator. But class pointers have their members referenced with the arrow (->) operator. You have pointers, so we use the arrow.

Also, since everything is now a pointer, you don't need the "&" in front of the two variables you pass to the PIDController constructor. The "&" is like an "anti-pointer". If something is a pointer, putting "&" in front of it will get you the actual object.

Example:

Code:
MyClass* myPointer = new MyClass();
myPointer->SomeFunction(); // Legal
myPointer.SomeFunction(); // Illegal!

MyClass myObject();
myObject->SomeFunction(); // Illegal!
myObject.SomeFunction(); // Legal

(&myPointer).SomeFunction(); // Legal, since (&myPointer) is now an object
Now in TeleopPeriodic, you can use the pointers from the header file to do the following:

Code:
In TeleopPeriodic()
TurretGoto is being set from 0-5 using an equation and it is float defined
turretControl->SetSetpoint(TurretGoto);
Let me know if you have any more problems. Yes, the differences between values, pointers, and references can be very tricky to understand. Try this page for a brief explanation - but know that understanding these sometimes subtle differences takes time!
Reply With Quote