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:
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().
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.
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.
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.
Motors are not doing anything at all, but works fine when not using 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.
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.
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.
Please post your progress… we have the same exact need, and are hard coding our drive code currently… CAN has so many benefits, but so does using RobotDrive…
We haven’t had any time to test really, so we have just hardcoded the Mecanum drive with no gyro. I hope that we can get RobotDrive sorted out later today, but I’m not too sure. Of course I’ll post the solution here though if we find it!
There are problems with this solution though. For example, I can’t reverse the motors anymore (it doesn’t drive as soon as I add SetInvertedMotor in). I have another idea though that I will try later.
Ok I got it working! It’s kind of an unusual workaround, but it works fine for us. Basically, create 4 fake motor controllers on unused PWM ports, and pass those to RobotDrive. From there, set the values of the real motor controllers to the values of the fake ones. Here is part of the code we used:
CANTalon *leftFront = new CANTalon(1); //Real ones
CANTalon *leftBack = new CANTalon(5);
CANTalon *rightFront = new CANTalon(2);
CANTalon *rightBack = new CANTalon(6);
TalonSRX *PWMlf = new TalonSRX(0); //Fake ones
TalonSRX *PWMlb = new TalonSRX(1);
TalonSRX *PWMrf = new TalonSRX(2);
TalonSRX *PWMrb = new TalonSRX(3);
void TeleopPeriodic()
{
drive->MecanumDrive_Cartesian(driveStick->GetX(), driveStick->GetY(), driveStick->GetZ(), gyro->GetAngle());
leftFront->Set(PWMlf->Get());
leftBack->Set(PWMlb->Get());
rightFront->Set(PWMrf->Get());
rightBack->Set(PWMrb->Get());
}