Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   [C++] Use CAN Talons in RobotDrive (http://www.chiefdelphi.com/forums/showthread.php?t=133804)

1452-Leo 31-01-2015 19:40

[C++] Use CAN Talons in RobotDrive
 
We are using CAN for the first time and after a few hours of learning how to do it, wiring, and formatting the Talons, our drive code didn't work. I tried controlling each motor individually and it works perfectly, but we would like to use RobotDrive because we are using Mecanum wheels with a gyro. Here is the non-working code:
Code:

class Robot: public SampleRobot {
        Joystick driveStick;
        CANTalon leftFront;
        CANTalon leftBack;
        CANTalon rightFront;
        CANTalon rightBack;
        RobotDrive drive;
        Gyro gyro;
public:
        Robot() :
                driveStick(1),
                leftFront(1),
                leftBack(5),
                rightFront(2),
                rightBack(6),
                drive(leftFront, leftBack, rightFront, rightBack),
                gyro(0)
{}
        void OperatorControl() {
                gyro.InitGyro();
                gyro.Reset();
                while (IsOperatorControl() && IsEnabled()) {
                        drive.MecanumDrive_Cartesian(driveStick.GetX(),driveStick.GetY(),driveStick.GetThrottle(),gyro.GetAngle());
                }
        }
};

And here is the working code (I used tank drive to make it easier):
Code:

class Robot: public SampleRobot {
        Joystick driveStick;
        CANTalon leftFront;
        CANTalon leftBack;
        CANTalon rightFront;
        CANTalon rightBack;
        Gyro gyro;
public:
        Robot() :
                driveStick(1),
                leftFront(1),
                leftBack(5),
                rightFront(2),
                rightBack(6),
                gyro(0)
{}
        void OperatorControl() {
                gyro.InitGyro();
                gyro.Reset();
                while (IsOperatorControl() && IsEnabled()) {
                        leftFront.Set(-driveStick.GetY());
                        leftBack.Set(-driveStick.GetY());
                        rightFront.Set(driveStick.GetThrottle());
                        rightBack.Set(driveStick.GetThrottle());
                }
        }
};

Does anyone know why this doesn't work? Thanks!

viggy96 31-01-2015 19:53

Re: [C++] Use CAN Talons in RobotDrive
 
Have you tried connecting the TalonSRXs via the PWM? That may alleviate your problem. Could also check if your TalonSRXs have the latest firmware.

Check here: http://crosstheroadelectronics.com/T...7s%20Guide.pdf

ozrien 31-01-2015 20:09

Re: [C++] Use CAN Talons in RobotDrive
 
Maybe grab the self test from the Rio web based configuration? Maybe its not in percent throttle mode. I don't have the implementation of robot drive in front of me but I think it just uses Set().

James Kuszmaul 31-01-2015 20:10

Re: [C++] Use CAN Talons in RobotDrive
 
What sort of problems are you encountering when you try to run the mecanum drive code? Does it simply not do anything at all, does it move the motors around but not in the way you expect, or something else? If the motors are running but the robot is responding how you expect, you should double check that everything is plugged into the right ports, that all the motors are turning the right direction, etc.

1452-Leo 31-01-2015 20:28

Re: [C++] Use CAN Talons in RobotDrive
 
Quote:

Originally Posted by viggy96 (Post 1436749)
Have you tried connecting the TalonSRXs via the PWM? That may alleviate your problem. Could also check if your TalonSRXs have the latest firmware.

Check here: http://crosstheroadelectronics.com/T...7s%20Guide.pdf

I updated all the Talons to 1.4 (the newest I think) and we're trying to use CAN instead of PWM. Using PWM would involve soldering the CAN wires which we don't want to do just yet.

Quote:

Originally Posted by ozrien (Post 1436753)
Maybe grab the self test from the Rio web based configuration? Maybe its not in percent throttle mode. I don't have the implementation of robot drive in front of me but I think it just uses Set().

I actually did do this earlier, but I had no idea what is means. When in drive, they are set to "No Drive" but otherwise set to "Throttle." This seems like it could be the problem if I knew more about it.

Quote:

Originally Posted by James Kuszmaul (Post 1436755)
What sort of problems are you encountering when you try to run the mecanum drive code? Does it simply not do anything at all, does it move the motors around but not in the way you expect, or something else? If the motors are running but the robot is responding how you expect, you should double check that everything is plugged into the right ports, that all the motors are turning the right direction, etc.

Motors are not doing anything at all, but works fine when not using RobotDrive.

James Kuszmaul 31-01-2015 20:48

Re: [C++] Use CAN Talons in RobotDrive
 
try calling
robotDrive.SetSafetyEnabled(false);
before the while loop in OperatorControl.
Edit: actually, try calling that in the Robot() constructor. It's possible that the Talons are getting disabled before you start running the robot but that they aren't getting properly re-enabled.

1452-Leo 31-01-2015 20:54

Re: [C++] Use CAN Talons in RobotDrive
 
Quote:

Originally Posted by James Kuszmaul (Post 1436767)
try calling
robotDrive.SetSafetyEnabled(false);
before the while loop in OperatorControl.

I actually tried that earlier when I had some motor controllers set up wrong, but I forgot to try it again! I'll check back tomorrow and report if it worked or not.

ozrien 31-01-2015 20:57

Re: [C++] Use CAN Talons in RobotDrive
 
If you are seeing kNoDrive then most likely set is not being called. See software reference manual for more details.

1452-Leo 31-01-2015 21:12

Re: [C++] Use CAN Talons in RobotDrive
 
Quote:

Originally Posted by ozrien (Post 1436769)
If you are seeing kNoDrive then most likely set is not being called. See software reference manual for more details.

Can I just call Set() once at the beginning of teleop or is there something I have to change in RobotDrive? Unfortunately, I can't test until Monday.

TimTheGreat 31-01-2015 22:48

Re: [C++] Use CAN Talons in RobotDrive
 
Are you calling Wait(.01) in your code? That may cause the code to do nothing.

viggy96 01-02-2015 00:09

Re: [C++] Use CAN Talons in RobotDrive
 
Could also try creating a new project. Sometimes projects get messed up. On the surface, it may not seem like it matters, but it could be worth a try.

I reccomend you switch from using the SampleRobot project to using IterativeRobot and try the code again.

viggy96 01-02-2015 00:45

Re: [C++] Use CAN Talons in RobotDrive
 
This should work, but as I don't have a bot with TalonSRXs, I can't confirm this, but you could try it. I have used the IterativeRobot class.

Code:

class Robot: public IterativeRobot
{
private:
        LiveWindow *lw;

        CANTalon leftFront = new CANTalon(1);
        CANTalon leftBack = new CANTalon(5);
        CANTalon rightFront = new CANTalon(2);
        CANTalon rightBack = new CANTalon(6);

        RobotDrive drive = new RobotDrive(leftFront, leftBack, rightFront, rightBack);

        Joystick stick = new Joystick(1);

        Gyro gyro = new gyro(0);

        void RobotInit()
        {
                lw = LiveWindow::GetInstance();
        }

        void AutonomousInit()
        {

        }

        void AutonomousPeriodic()
        {

        }

        void TeleopInit()
        {

        }

        void TeleopPeriodic()
        {
                drive.MecanumDrive_Cartesian(stick.getX(), stick.getY(), stick.getThrottle(), gyro.getAngle());
        }

        void TestPeriodic()
        {
                lw->Run();
        }
};


1452-Leo 01-02-2015 16:29

Re: [C++] Use CAN Talons in RobotDrive
 
Quote:

Originally Posted by viggy96 (Post 1436847)
This should work, but as I don't have a bot with TalonSRXs, I can't confirm this, but you could try it. I have used the IterativeRobot class.

How would this be different than the code I started with? Iterative basically just adds a function to be called at the beginning, but doesn't really change what is actually going on in the program.

virtuald 02-02-2015 01:19

Re: [C++] Use CAN Talons in RobotDrive
 
Quote:

Originally Posted by 1452-Leo (Post 1437039)
How would this be different than the code I started with? Iterative basically just adds a function to be called at the beginning, but doesn't really change what is actually going on in the program.

Iterative waits for each driver station packet for each iteration, whereas your original code runs in a tight loop without waiting for input. If you added a 20ms sleep in your loop, it would be vaguely equivalent to the iterative version.

Either way, you should add some sleep to your loop, otherwise you'll starve the rest of the threads on your system and you'll encounter problems. I'd recommend using iterative robot instead though, then you don't have to worry about things like that.

1452-Leo 03-02-2015 10:14

Re: [C++] Use CAN Talons in RobotDrive
 
Quote:

Originally Posted by virtuald (Post 1437179)
Iterative waits for each driver station packet for each iteration, whereas your original code runs in a tight loop without waiting for input. If you added a 20ms sleep in your loop, it would be vaguely equivalent to the iterative version.

Either way, you should add some sleep to your loop, otherwise you'll starve the rest of the threads on your system and you'll encounter problems. I'd recommend using iterative robot instead though, then you don't have to worry about things like that.

Thanks, I didn't realize there was an actual difference in the how the program ran for iterative, so we will probably switch over to it today.


All times are GMT -5. The time now is 01:49.

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