Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Can't get motors to spin correct way. (http://www.chiefdelphi.com/forums/showthread.php?t=124973)

Wzup4021 20-01-2014 17:02

Can't get motors to spin correct way.
 
We have successfully gotten our robot wheels (6 wheel tank drive, 2 motors on each side) to spin, however they are going the wrong way. We have tried inserting a negative in many places in our code, we have tried multiplying by -1 and nothing seems to work. With everything we tried, the wheels will still spin the wrong way (they will spin either way, but the joystick/spin is reversed). Here is that part of the code:

public void operatorControl() {
chassis.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {
Joystick1 = leftStick.getAxis(Joystick.AxisType.kY);
Joystick2 = rightStick.getAxis(Joystick.AxisType.kY);

Originally we had this, but changed it to the above:
Joystick1 = leftStick.getY();
Joystick2 = rightStick.getY();


//Left Side Motor Code, controlled by the left joystick(might need to switch direction)
if ((Joystick1 < 0.1)&&(Joystick1 > -0.1)) {
LeftMotors.set(0);
}

else {
LeftMotors.set (Joystick1);
}

//Right Side Motor Code, controlled by the right joystick(might need to switch direction)
if ((Joystick2 < 0.1)&&(Joystick2 > -0.1)) {
RightMotors.set(0);
}

else {
RightMotors.set(Joystick2);
}


}
}

Racer26 20-01-2014 17:09

Re: Can't get motors to spin correct way.
 
Personally: I've always found this to be the way to go.

Code:

value = leftStick.getRawAxis(1);
getAxis returns a object of type Axis. getRawAxis returns the value of the axis. Multiply by -1 accordingly.

note that the 1 in my code is the axis number. Usually, joysticks return the "x" axis as axis 0, the "y" axis as axis 1, and additional analog axes (thumb wheels, xbox controller triggers, etc) as 2, 3, 4, etc.

jee7s 20-01-2014 17:10

Re: Can't get motors to spin correct way.
 
I think most of us reading that need a bit more context, namely what types all of those variables are and where you tried to make your changes that didn't work.

Particularly:
1. What is the type of LeftMotors and RightMotors?
2. What is the type of Joystick1 and Joystick2?

If LeftMotors and RightMotors are a variant of a speed controller, and Joystick1 and Joystick2 are Joysticks, then code like this would work:

LeftMotors.Set(Joystick1.GetY());
RightMotors.Set(Joystick2.GetY());

And if you needed to reverse the right motors you would replace with this:
LeftMotors.Set(Joystick1.GetY());
RightMotors.Set(-1.0 * Joystick2.GetY());

But, like I said, a bit more context to your question would be helpful.

Wzup4021 20-01-2014 17:10

Re: Can't get motors to spin correct way.
 
So is "value" just a variable in this? And what does the (1) do at the end?

ArchosR4 20-01-2014 17:11

Re: Can't get motors to spin correct way.
 
Have you tried looking for a generic drive function in your library. Such as tank or arcade drive? If you dont have these functions set one set of motors to a negative out put and leaving the other to a positive. Your function to remove the deadband of the controller looks good. however i would take it out until you get the motors to run in the right direction.

Wzup4021 20-01-2014 17:13

Re: Can't get motors to spin correct way.
 
I'm not sure if I get your question, but "Leftmotors" means 2 cim motors, controlled by Talons. Right, the opposite. I'm not sure what you mean by joystick type. Basically we have 2 joysticks, one for each side. We have the joysticks matched up to the right side, but getting them to go the right way is what we are having issues with.

Wzup4021 20-01-2014 17:15

Re: Can't get motors to spin correct way.
 
We used the tank drive template. We have tried inserting negatives everywhere we can think of (one at a time ofc) and also tried multiplying by -1. They still spin the same way regardless. Also, why should we remove the deadpan code, any reason?

jee7s 20-01-2014 17:19

Re: Can't get motors to spin correct way.
 
Quote:

Originally Posted by Wzup4021 (Post 1329861)
We used the tank drive template. We have tried inserting negatives everywhere we can think of (one at a time ofc) and also tried multiplying by -1. They still spin the same way regardless. Also, why should we remove the deadpan code, any reason?

At this point, remove the deadband code to simplify your debugging.

Regarding the type, somewhere in your code you should have a block of declarations that look like this:

Joystick Joystick1;
Joystick Joystick2;
Jaguar LeftMotors;
Jaguar RightMotors;

...Or some such thing. Can you show us the declarations of those objects? Or, post your code so we can get a better picture.

Racer26 20-01-2014 17:20

Re: Can't get motors to spin correct way.
 
Does this not work?

Code:

class Robot() extends SimpleRobot{
RobotDrive myRobot = new RobotDrive(1,2,3,4);
Joystick leftStick = new Joystick(1);
Joystick rightStick = new Joystick(2);
...
public void OperatorControl(){
while( isOperatorControl() && isEnabled() ){
myRobot.TankDrive(leftStick,rightStick);
}
}

}


Wzup4021 20-01-2014 17:21

Re: Can't get motors to spin correct way.
 
obotDrive chassis = new RobotDrive(1, 2);
private final Joystick leftStick = new Joystick(1);
private final Joystick rightStick = new Joystick(2);
Talon LeftMotors = new Talon(1);
Talon RightMotors = new Talon(2);
private double Joystick1;
private double Joystick2;

Racer26 20-01-2014 17:24

Re: Can't get motors to spin correct way.
 
Quote:

Originally Posted by Wzup4021 (Post 1329865)
obotDrive chassis = new RobotDrive(1, 2);
private final Joystick leftStick = new Joystick(1);
private final Joystick rightStick = new Joystick(2);
Talon LeftMotors = new Talon(1);
Talon RightMotors = new Talon(2);
private double Joystick1;
private double Joystick2;

Yes, so simply putting:

Code:

chassis.TankDrive(leftStick,rightStick);
in your OperatorControl() function ought to take care of it. If motors spin the wrong direction at that point, flip the wires at the speed controller output.

jee7s 20-01-2014 17:24

Re: Can't get motors to spin correct way.
 
Quote:

Originally Posted by Wzup4021 (Post 1329865)
obotDrive chassis = new RobotDrive(1, 2);
private final Joystick leftStick = new Joystick(1);
private final Joystick rightStick = new Joystick(2);
Talon LeftMotors = new Talon(1);
Talon RightMotors = new Talon(2);
private double Joystick1;
private double Joystick2;

Ah, now that looks like you are stepping on your own code. Does the RobotDrive class declare and instantiate the joysticks and talons? If it does, then you are trying to set values from two different places. That might be causing your complication.

From the other poster's comment, I think all you need is that first line where you instantiate a new RobotDrive.

Racer26 20-01-2014 17:27

Re: Can't get motors to spin correct way.
 
Quote:

Originally Posted by jee7s (Post 1329868)
Ah, now that looks like you are stepping on your own code. Does the RobotDrive class declare and instantiate the joysticks and talons? If it does, then you are trying to set values from two different places. That might be causing your complication.

From the other poster's comment, I think all you need is that first line where you instantiate a new RobotDrive.

First 3. RobotDrive instantiates the motors on its own but does not instantiate the Joysticks. (though stop to think of it, I'm not sure what it instantiates them as... Talon, Jaguar, and Victor all extend the SpeedController class...)

EDIT: Looking at the WPIlib reference, they're instantiated as Victors. you can also pass SpeedController objects to the RobotDrive constructor if you want something other than Victors.

In this case, they could go:

Code:

Talon leftDrive = new Talon(1);
Talon rightDrive = new Talon(2);
RobotDrive chassis = new RobotDrive(leftDrive, rightDrive);


Wzup4021 20-01-2014 17:30

Re: Can't get motors to spin correct way.
 
While I see what you're saying, I don't think that's the issue. We can control the speed and on/off of the motors fine, and the direction. Forward on the joystick is moving the wheels backwards, and backwards on the JS is moving the wheels forwards.

Matt C 20-01-2014 17:31

Re: Can't get motors to spin correct way.
 
Have you verified the wiring?

jee7s 20-01-2014 17:31

Re: Can't get motors to spin correct way.
 
Quote:

Originally Posted by Racer26 (Post 1329870)
First 3. RobotDrive instantiates the motors on its own but does not instantiate the Joysticks. (though stop to think of it, I'm not sure what it instantiates them as... Talon, Jaguar, and Victor all extend the MotorController class...)

For total clarity, that means you need to declare these:
RobotDrive chassis = new RobotDrive(1, 2);
private final Joystick leftStick = new Joystick(1);
private final Joystick rightStick = new Joystick(2);

And then call this:
chassis.TankDrive(leftStick, rightStick);

If you then have a side spinning in the wrong direction, swap the MOTOR wiring on the Talon OUTPUT. (Don't swap the input wiring, as you'll fry the talon.)

Racer26 20-01-2014 17:31

Re: Can't get motors to spin correct way.
 
Quote:

Originally Posted by Wzup4021 (Post 1329871)
While I see what you're saying, I don't think that's the issue. We can control the speed and on/off of the motors fine, and the direction. Forward on the joystick is moving the wheels backwards, and backwards on the JS is moving the wheels forwards.

...so flip the polarity of the wires at the output of the speed controllers.

Wzup4021 20-01-2014 17:44

Re: Can't get motors to spin correct way.
 
Okay, we discussed reversing the output wires on the Talons, but our team members are worried that in inspection they will tell us we can't have red to negative and black to positive. Has anybody had to reverse hot/cold wires and gotten in trouble for it, or were inspectors okay with it?

jee7s 20-01-2014 17:47

Re: Can't get motors to spin correct way.
 
Quote:

Originally Posted by Wzup4021 (Post 1329882)
Okay, we discussed reversing the output wires on the Talons, but our team members are worried that in inspection they will tell us we can't have red to negative and black to positive. Has anybody had to reverse hot/cold wires and gotten in trouble for it, or were inspectors okay with it?

Speaking as an inspector, we don't mind which color wire goes to which output terminal of the talon or any other speed controller to a motor. Strictly speaking, those don't have a polarity since the talon can reverse it based on the PWM signal it receives. It's only the input side we worry about, and as I said before, if you hook that up backwards you destroy the talon.

MANY teams have the speed controller output polarities flipped on one side of the robot.

Joe Ross 20-01-2014 17:54

Re: Can't get motors to spin correct way.
 
Quote:

Originally Posted by Wzup4021 (Post 1329882)
Okay, we discussed reversing the output wires on the Talons, but our team members are worried that in inspection they will tell us we can't have red to negative and black to positive. Has anybody had to reverse hot/cold wires and gotten in trouble for it, or were inspectors okay with it?

If anyone does have a problem, show them R49.

However, I do recommend getting to the bottom of the software issue. It may be important for some other system in the near future.

Gregor 20-01-2014 18:27

Re: Can't get motors to spin correct way.
 
Before this turns into another thread discussing the merits of inverting the motors physically or in code, it's already been done.

http://www.chiefdelphi.com/forums/sh...d.php?t=122186

Racer26 20-01-2014 20:31

Re: Can't get motors to spin correct way.
 
For what its worth, IIRC the TankDrive() method of the RobotDrive class automatically takes into account that you have to turn one side backwards.

Wzup4021 21-01-2014 16:54

Re: Can't get motors to spin correct way.
 
Thanks for the help, we ended up just flipping around the 2 PWM cables that are going out the the 4 talons and that fixed out problem. Side question: I know we need a different talon for each motor, but do we need a different PWM cable for each talon, or can we use PWM splitters?

cgmv123 21-01-2014 17:13

Re: Can't get motors to spin correct way.
 
Quote:

Originally Posted by Wzup4021 (Post 1330353)
Side question: I know we need a different talon for each motor, but do we need a different PWM cable for each talon, or can we use PWM splitters?

PWM splitters are legal, and in many cases, recommended.


All times are GMT -5. The time now is 22:05.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi