Hi,
I am trying to write code for our elevator mechanism. Basically, it uses two motors that we are controlling with 2 VictorSPXs wired in a CAN bus. They need to spin in the same direction, and they will drive a belt or something else(TBD) to lift it or drop it. However, I don’t know how to program them. I have tried using arcadeDrive, but I don’t need a z axis, since I don’t need the motors to turn, just go one direction or another, together. Should I make one of the motors a slave of the other one?
Also, I would like to control it using either the buttons or the bumpers on the 360 controller. How would I do that? I only know how to use the joysticks like what I did for our main drivetrain.
You didn’t say what language you are using. Assuming Java or C++, you can drive motors directly by using the set() method. It’s a good idea to make one a follower if they are mechanically coupled, that way you never forget to drive both.
Basically if you want to use the joystick Y axis to drive the motors, without using followers, you can do something like (Java):
VictorSPX m1 = new VictorSPX(1);
VictorSPX m2 = new VictorSPX(2);
Joystick j = new Joystick(1);
...
double val = j.getY();
m1.set(ControlMode.PercentOutput, val);
m2.set(ControlMode.PercentOutput, val);
With followers:
VictorSPX m1 = new VictorSPX(1);
VictorSPX m2 = new VictorSPX(2);
Joystick j = new Joystick(1);
m2.follow(m1);
...
double val = j.getY();
m1.set(ControlMode.PercentOutput, val);
Driving with buttons means you need to have an if conditional on the joystick button (1=pressed, 0=not pressed) and drive the motors with a fixed value based on the button value.
Note: this is just manual driving, you probably will ultimately want closed loop control which will require sensor feedback.
Make sure you add a constant “float voltage” to the elevator to counteract gravity. For us last year, it was around 0.15 to make our elevator stay in place. You will, however, want to use an encoder and PID if at all possible to control your elevator. Versaplanetary encoders work well.