Log in

View Full Version : Unable to invert motor


christheman200
18-01-2016, 21:02
Hi all!
I have the following code in my main robot class, and it is giving me a number of exceptions which I can't conquer:
MainDrive.setInvertedMotor(Talon.kRearLeft, true);
MainDrive.setInvertedMotor(Talon.kRearRight, true);
Exceptions:
First line:
- Syntax error on tokens, delete these tokens
- Syntax error on token "(", < expected
Second line:
- Syntax error on tokens, TypeArgument1 expected instead
- Syntax error on token "(", , expected

Any and all help is appreciated!
Thanks, Chris

Arhowk
18-01-2016, 21:16
The errors themselves make no sense but theres some issues


Why is MainDrive capitalized? variables should be lowerCamelCase
You mean RobotDrive.MotorType.kRearLeft, not Talon.


There may be other syntax errors in the code as well.. post the entire file

Tparbotmail
18-01-2016, 22:55
robotDrive.setInvertedMotor(RobotDrive.MotorType.k FrontRight, true);

christheman200
19-01-2016, 07:26
Here's the rest of the code. I've tried the fixes mentioned above, but they haven't seemed to help.

package org.usfirst.frc.team854.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Talon;

/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class Robot extends IterativeRobot {

Joystick driveStick1 = new Joystick(1);
Joystick driveStick2 = new Joystick(2);
RobotDrive MainDrive = new RobotDrive(0,1);

MainDrive.setInvertedMotor(Talon.kRearLeft, true);
MainDrive.setInvertedMotor(Talon.kRearRight, true);

Talon lifter = new Talon(3);

float lifterSpeed = 1.0f; //f for float (to have decimals!)

/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {

}

/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {

}

/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
MainDrive.tankDrive(driveStick1, driveStick2);


if(driveStick2.getRawButton(3))
lifter.set(lifterSpeed);
else if(driveStick2.getRawButton(5))
lifter.set(-lifterSpeed);
else
lifter.set(0.0);

}

/**
* This function is called periodically during test mode
*/
public void testPeriodic() {

}

}

Arhowk
19-01-2016, 08:51
you put it inside of the class declaration.

Move those calls to robotInit()

You can only declare functions and variables in that space you put the two calls, you can't do anything else like call functions

electronicsdude
19-01-2016, 09:45
Hi all!
I have the following code in my main robot class, and it is giving me a number of exceptions which I can't conquer:
MainDrive.setInvertedMotor(Talon.kRearLeft, true);
MainDrive.setInvertedMotor(Talon.kRearRight, true);
Exceptions:
First line:
- Syntax error on tokens, delete these tokens
- Syntax error on token "(", < expected
Second line:
- Syntax error on tokens, TypeArgument1 expected instead
- Syntax error on token "(", , expected

Any and all help is appreciated!
Thanks, Chris

Just flip the polarity on the motor side of your motor controller. its legal as long as you label it and it works like a dream.

christheman200
19-01-2016, 11:40
Thanks guys!
I managed to work it out through trial and error, but thanks for clearing up why it works.

Chris

JacobD
23-01-2016, 19:43
For future reference, I believe there is a method to invert your speed controller.

In the class SpeedController:

SpeedController.setInverted();

Correct me if I'm wrong.

Arhowk
24-01-2016, 17:41
For future reference, I believe there is a method to invert your speed controller.

In the class SpeedController:

SpeedController.setInverted();

Correct me if I'm wrong.

You can't invert object within RobotDrive unless they are fed to robot drive which is a bit of work