Programming Java help.

I realy hate asking for help,but I have no where else to turn. I am a mechanical mentor with a second year team with no programming mentors. I have been trusted into helping the kids, which is not a big deal, but I have no direction for them. Here is the situation.

We have a ruff program installed on this years robot and it turns the wrong direction when given commands. We are using the the AndyMark long chassis with two motors per gear box. Currently using ports 1,2,3,4 for the outputs from the roborio to the motor controllers. Motor 1 is the front left, motor 2 in front right, motor 3 is rear left, and motor 4 is rear right.

I really don’t want the answer if someone know, would not turn it down, but these kids need to learn as much as I do. I would like resources to help them learn to code this drive system. Any help is appreciated.

My guess is that you need to invert the outputs going to one set of motors (left or right).

For example, if you were to tell all motors to drive fwd by sending them the same signal, and they were all wired identically, they may ball rotate their output shaft in the clockwise direction. They are all traveling in the same direction, but they are mounted on the chassis in different orientations (the right motors are rotated 180 degrees from the left), so this results on one set driving fwd and the other driving backwards.

To test what needs to change in your code, take baby steps. Verify the motors on the right had side travel fwd when you press fwd on the joystick. Then do the same for the left motors. If one side is going in the wrong direction, invert the output being sent to the motor controllerscontrollers for that side of the drivetrain (multiply output value by -1).

If that doesn’t resolve the problem, providing a copy of your drivetrain code, and a description of how the turning isn’t working specifically will help us narrow it down for you guys.

If you haven’t seen it already, there’s a good collection of information on java programming here:
http://wpilib.screenstepslive.com/s/4485/m/13809

Thank you for responding. I will try to look up the info on how to invert the command. Will post after our next meeting sometime next week.

If it turns the wrong direction when given commands… like it turns left when you tell it to turn right, then this is not an inverted motor problem. If one side needed to be inverted it would turn when you told it to go straight.

Instead I suspect that it is very likely that you mixed up the PWM order when you create the RobotDrive object (presuming that you are using that class). The documentation defines the interface to the constructor as:

RobotDrive (final int frontLeftMotor, final int rearLeftMotor, final int frontRightMotor, final int rearRightMotor)
Based on the info you provided about your robot motor configuration here:

The proper way to create that object would be RobotDrive(1,3,2,4). If you have the PWM numbers in a different order it would send the wrong commands to the motors and would not drive as expected.

Of course, it could also be a combination of both the order of the PWMs and inverted motors. I would suggest that you make sure the PWM numbers are in the right order first, then if it is acting incorrectly put the robot up on blocks so that you can watch the wheels move and see which ones are turning the wrong direction when you command it to drive forward.

Hope this helps.

Something I forgot to mention, FIRST verify that your motors are all plugged into the correct PWM channels according to your code. From your description 1 and 3 are left motors and 2 and 4 are right motors. Verify this is correct in code. If left and right are swapped in code, you’ll be able to drive fwd and reverse fine, but turning will be backwards.

Also, my first post assumes that you’re using tank drive for your controls (skid steer - one joystick controls left wheels, another controls right wheels). But it’s possible that your team is using arcade drive (a single joystick - point it where you want the robot to go).

If the latter is the case, then you won’t be able to individually test each side of the chassis. You can however test everything without messing with your wiring. Test each side of the chassis individually to confirm everything is working as expected.

  • push the stick fwd
  • verify the right wheels move forward
  • push the stick backwards
  • verify the right wheel moves backwards

If fwd/reverse are backwards, invert the output (multiply by negative 1).
Then do the same procedure the left wheels

After that’s working, verify turning works correctly

  • Push the stick to the right
  • Verify the left wheels move fwd
  • Push the stick to the left
  • Verify the right wheels move fwd

if the above doesn’t work, you’ve likely got the left and right motors backwards in code or wiring. If this is the case, fix the problem, then start over from the beginning, verifying left and right motors move fwd/rev when the stick is moved fwd/rev.

If you happen to be using theRobotDrive class to handle controlling your motors, and you need to invert a motor, you can multiply your input to the respective motors by negative 1 as I described, or you can use the setInvertedMotor() method.