Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   New to 2CAN and Jaguar (http://www.chiefdelphi.com/forums/showthread.php?t=99685)

mikets 17-01-2012 19:17

Re: New to 2CAN and Jaguar
 
So does it mean I can only call SetPID after I call ChangeControlMode to a close-loop mode? And I assume I have to call SetPID every time after I change to a close-loop mode. In other words, the PID constants will be cleared on every mode change?
Hmm, thinking about it some more, it makes sense. Since the PID constants are different for different close-loop mode, it makes sense to set them after a close-loop mode is set.
Thanks for the info. Learn something today :-)

jhersh 17-01-2012 19:20

Re: New to 2CAN and Jaguar
 
Quote:

Originally Posted by mikets (Post 1107940)
So does it mean I can only call SetPID after I call ChangeControlMode to a close-loop mode? And I assume I have to call SetPID every time after I change to a close-loop mode. In other words, the PID constants will be cleared on every mode change?

The Jaguar has separate messages for setting each control mode's PID constants, so the CANJaguar class has no message ID that it can use to send those PID constants if you are not in a closed-loop mode.

I don't believe they are cleared... they are stored as separate variables in the Jaguar. That could be easily tested by setting one mode, calling SetPID, changing modes, calling SetPID again, then switching modes back and calling GetPID.

mikets 17-01-2012 19:23

Re: New to 2CAN and Jaguar
 
Yes, I remember now. I saw that behavior in bdc-comm tool.

mikets 17-01-2012 20:02

Re: New to 2CAN and Jaguar
 
I have another issue. I am also experimenting with kSpeed mode. No code this time. I am playing with the bdc-comm tool.
- I set one of the Jags to kSpeed mode
- Set the speed to 30 rpm.
- I kept Ki and Kd zero and was playing with Kp only.
- The wheel moved very jerkily (i.e. jerk forward, stop, jerk forward stop, ...) so it is making a loud clunging noise.
- I tried Kp = 1.0 and up. The larger Kp, the louder is the clunging noise.
My theory was that the Kp was too strong. It started too strong and because of the "brake" mode, it also stopped too suddenly. Basically, the "speed" was oscillating. So I cranked down Kp. Eventually, when Kp is 0.35, the wheel seems to turn smoothly. But when looking at the speed, it was very far from the target. For example if I set target to 70 rpm, it comes back with 30. When I set it to 60 rpm, it came back at 25. Am I interpreting this correctly? I am not sure about the units because the bdc-comm tool does not show me the units in Speed mode. It looks like the target value box can only accept a maximum value of 100 (may be it's a percentage? But percentage of what?).

jwakeman 17-01-2012 20:10

Re: New to 2CAN and Jaguar
 
Quote:

Originally Posted by jhersh (Post 1107933)
If you get an error that is not "Time-out", the CANJaguar object will stop trying to talk to the device, since the calling code is clearly broken.


Is this still true with v101 of the firmware? I think this version of the firmware will bring the Jaguar back online after such a fault? Or is this a different set of circumstances?


Quote:

Originally Posted by jhersh (Post 1107933)
I clearly need to write some examples for using CANJaguar in C++. Feel free to contribute some if you like.

I did spend an hour last night figuring out that I needed to call EnableControl() before it would respond to my Set() commands.

This is the code I was playing with last night to get familiar with the Jaguar closed loop current control. Basically a tank drive that commands current:

Code:

#include "testBot.h"
#include "CANJaguar.h"
#include "Joystick.h"


testBot::testBot()
{
}

testBot::~testBot()
{
}       

void testBot::OperatorControl()
{
        printf("Entering Operator Control\n");

        GetWatchdog().SetEnabled(true);       

        CANJaguar* pJag2 = new CANJaguar(2,CANJaguar::kCurrent);
        CANJaguar* pJag3 = new CANJaguar(3,CANJaguar::kCurrent);
        CANJaguar* pJag4 = new CANJaguar(4,CANJaguar::kCurrent);
        CANJaguar* pJag5 = new CANJaguar(5,CANJaguar::kCurrent);
       
        Joystick* pDriveStick1 = new Joystick(1);
        Joystick* pDriveStick2 = new Joystick(2);

        pJag2->SetPID(0.01,0.05,0);
        pJag3->SetPID(0.01,0.05,0);
        pJag4->SetPID(0.01,0.05,0);
        pJag5->SetPID(0.01,0.05,0);
       
        pJag2->ConfigNeutralMode(CANJaguar::kNeutralMode_Coast);
        pJag3->ConfigNeutralMode(CANJaguar::kNeutralMode_Coast);
        pJag4->ConfigNeutralMode(CANJaguar::kNeutralMode_Coast);
        pJag5->ConfigNeutralMode(CANJaguar::kNeutralMode_Coast);

        pJag2->EnableControl();
        pJag3->EnableControl();
        pJag4->EnableControl();
        pJag5->EnableControl();
               
        pJag2->Set(0, 0);
        pJag3->Set(0, 0);
        pJag4->Set(0, 0);
        pJag5->Set(0, 0);
       
        while(IsOperatorControl() && IsEnabled())
        {
                GetWatchdog().Feed();
                pJag2->Set(pDriveStick1->GetY() * 50);
                pJag4->Set(pDriveStick1->GetY() * 50);
                pJag5->Set(pDriveStick2->GetY() * -1 * 50);
                pJag3->Set(pDriveStick2->GetY() * -1 * 50);
        }
       

        printf("Leaving Operator Control\n");
}

void testBot::Autonomous()
{
        GetWatchdog().SetEnabled(false);
       
        while(IsAutonomous() && IsEnabled())
        {
        }
}

START_ROBOT_CLASS(testBot);


mikets 17-01-2012 20:45

Re: New to 2CAN and Jaguar
 
Quote:

Originally Posted by mikets (Post 1107982)
For example if I set target to 70 rpm, it comes back with 30. When I set it to 60 rpm, it came back at 25. Am I interpreting this correctly? I am not sure about the units because the bdc-comm tool does not show me the units in Speed mode. It looks like the target value box can only accept a maximum value of 100 (may be it's a percentage? But percentage of what?).

Since I don't know what are the units in the bdc-comm tool, I started to play with code again setting the Jags to Speed mode and calling jag.Set(300.0) for setting 300 rpm (I think... since that's what the documentation said the unit is). But I also call jag.GetSpeed() and it came back about half. So if the set was 300, I got the speed back 150. If I set 120.0, I got back about 60.0. Is this expected?

jhersh 18-01-2012 01:49

Re: New to 2CAN and Jaguar
 
Quote:

Originally Posted by mikets (Post 1107982)
I have another issue. I am also experimenting with kSpeed mode. No code this time. I am playing with the bdc-comm tool.
- I set one of the Jags to kSpeed mode
- Set the speed to 30 rpm.
- I kept Ki and Kd zero and was playing with Kp only.
- The wheel moved very jerkily (i.e. jerk forward, stop, jerk forward stop, ...) so it is making a loud clunging noise.
- I tried Kp = 1.0 and up. The larger Kp, the louder is the clunging noise.
My theory was that the Kp was too strong. It started too strong and because of the "brake" mode, it also stopped too suddenly. Basically, the "speed" was oscillating. So I cranked down Kp. Eventually, when Kp is 0.35, the wheel seems to turn smoothly. But when looking at the speed, it was very far from the target. For example if I set target to 70 rpm, it comes back with 30. When I set it to 60 rpm, it came back at 25. Am I interpreting this correctly? I am not sure about the units because the bdc-comm tool does not show me the units in Speed mode. It looks like the target value box can only accept a maximum value of 100 (may be it's a percentage? But percentage of what?).

You should probably look at these threads:

http://www.chiefdelphi.com/forums/sh...d.php?t=100135
http://www.chiefdelphi.com/forums/sh...ad.php?t=90508

dsirovica 15-02-2012 17:49

Re: New to 2CAN and Jaguar
 
We have the same issue on jerkyness at low speed. Still trying to figure that one out... see other threads on CANbus Control. We wrote our own PID code, but may move to the Jag intrenal PID to offload cRio.

But on the Kp we had the same result as others. Kp alone will always yields a top speed of approx 1/2 setpoint. Ki however, does a beatiful job at reaching setpoint and (in our configuration) became the dominant control force.

mikets 15-02-2012 19:11

Re: New to 2CAN and Jaguar
 
In order to get a stable speed control using PID, you need to integrate the PID controller. That's why we can't use the Jaguar's built-in PID. There shouldn't be any problem with the cRIO. It would just be an extra PID calculation in the main robot loop.


All times are GMT -5. The time now is 12:17.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi