Error in Tank Drive code

even tho the code seems ok, neither the 2 motors move, there is not a single problem with the joystick, or the rio, so it must be the code, any help is appreciated

#include "WPILib.h"
class Robot: public SampleRobot
	bool Piston;
	RobotDrive DriveRobot;
	Joystick leftStick;
	Joystick rightStick;
    Talon m_motor1;
	Talon m_motor2;
	Robot() :

		    DriveRobot(1, 2),


	void OperatorControl()
		while (IsOperatorControl() && IsEnabled())

			DriveRobot.TankDrive(leftStick, rightStick);



It looks like you’re trying to define PWM 1 and 2 as both drive motors and individual motors simultaneously. If you want to do that, declare and initialize your Talons first, then call DriveRobot() with the actual Talon objects instead of the PWM pin numbers. But I think if you remove every reference to m_motor1 and m_motor2 your code will work as you want it to. (Actually, I think it is likely to spin when you try to go straight and vice versa, because one of the drive motors probably needs to be inverted.)

You definitely shouldn’t be calling TankDrive() and setting the individual motors.

Thanks for the reply! it helped us a lot, but the code didnt work as epected.
we are trying to make one joystick control the Y axis movement(foward,backwards) and anothr one the X axis movment (left,right)
any ideas,comments or suggestions are appreciated

1 Like

If you want forward/reverse control on one joystick and left/right control on the other, you should be using ArcadeDrive instead of TankDrive.