|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Motor Controllers
I would like to know how to set a motor controller to a joystick. This year we are using tank drive with four motors. When I push on a joystick the front two motors move and one is moving backwards. I really need help.
(Ignore the Mecanum code) Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
/* Written by 2T's */
/* PizzaLovers007 and Lordninjaassassin */
/* (c) 2014 */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.DriverStationLCD;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.camera.AxisCameraException;
import edu.wpi.first.wpilibj.image.BinaryImage;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.CriteriaCollection;
import edu.wpi.first.wpilibj.image.NIVision;
import edu.wpi.first.wpilibj.image.NIVisionException;
import edu.wpi.first.wpilibj.image.ParticleAnalysisReport;
public class Robot2014 extends IterativeRobot {
private Joystick leftStick;
private Joystick rightStick;
private RobotDrive drive;
private AxisCamera camera;
private DriverStationLCD lcd = DriverStationLCD.getInstance();
private SpeedController m_FrontLeft;
private SpeedController m_FrontRight;
private SpeedController m_BackLeft;
private SpeedController m_BackRight;
private CriteriaCollection cc;
public void robotInit() {
joystickInit();
talonInit();
robotDriveInit();
camera = AxisCamera.getInstance();
camera.writeCompression(0);
camera.writeResolution(AxisCamera.ResolutionT.k320x240);
camera.writeBrightness(10);
getWatchdog().setExpiration(3);
getWatchdog().feed();
lcd.println(DriverStationLCD.Line.kUser2, 1, "Enabled!");
lcd.updateLCD();
cc = new CriteriaCollection();
cc.addCriteria(NIVision.MeasurementType.IMAQ_MT_AREA, 500, 65535, false);
}
public void joystickInit() {
leftStick = new Joystick(1);
rightStick = new Joystick(2);
}
public void robotDriveInit() {
drive = new RobotDrive(m_FrontLeft, m_BackLeft, m_FrontRight, m_BackRight);
}
public void talonInit() {
m_FrontLeft = new Talon(1);
m_FrontRight = new Talon(2);
m_BackLeft = new Talon(3);
m_BackRight = new Talon(4);
}
public void disabledContinuous() {
}
public void disabledInit() {
lcd.println(DriverStationLCD.Line.kUser2, 1, "Disabled!");
lcd.updateLCD();
}
public void disabledPeriodic() {
}
public void autonomousInit() {
getWatchdog().setEnabled(false);
lcd.println(DriverStationLCD.Line.kUser2, 1, "Autonomous!");
lcd.updateLCD();
boolean hotGoalLeft = false;
//Calculate hot goal (may suck)
try {
ColorImage image = camera.getImage();
BinaryImage thresholdImage = image.thresholdRGB(0, 45, 25, 255, 0, 47);
BinaryImage convexHullImage = thresholdImage.convexHull(false);
BinaryImage filteredImage = convexHullImage.particleFilter(cc);
ParticleAnalysisReport[] reports = filteredImage.getOrderedParticleAnalysisReports();
for (int i = 0; i < reports.length; i++) {
ParticleAnalysisReport rep = reports[i];
if (rep.boundingRectWidth > rep.boundingRectHeight && rep.boundingRectHeight > 5) {
hotGoalLeft = (rep.center_mass_x_normalized < 0) ? true : false;
}
}
image.free();
thresholdImage.free();
convexHullImage.free();
filteredImage.free();
} catch (NIVisionException ex) {
} catch (AxisCameraException ex) {
}
//Turn towards hot goal
if (hotGoalLeft) {
drive.mecanumDrive_Polar(0, 0, -1);
Timer.delay(0.8);
} else {
drive.mecanumDrive_Polar(0, 0, 1);
Timer.delay(0.8);
}
//TODO shoot or something...
//Turn back forward
if (hotGoalLeft) {
drive.mecanumDrive_Polar(0, 0, 1);
Timer.delay(0.8);
} else {
drive.mecanumDrive_Polar(0, 0, -1);
Timer.delay(0.8);
}
//Move forward
drive.mecanumDrive_Cartesian(0, 0.5, 0, 0);
Timer.delay(1.2);
//Stop and wait
drive.mecanumDrive_Cartesian(0, 0, 0, 0);
}
public void autonomousPeriodic() {
}
public void teleopInit() {
getWatchdog().setEnabled(true);
lcd.println(DriverStationLCD.Line.kUser2, 1, "Teleop!");
lcd.updateLCD();
}
public void teleopPeriodic() {
// drive.mecanumDrive_Polar(leftStick.getMagnitude(), leftStick.getDirectionDegrees(), rightStick.getX());
// drive.mecanumDrive_Cartesian(leftStick.getAxis(Joystick.AxisType.kX),
// leftStick.getAxis(Joystick.AxisType.kY),
// rightStick.getAxis(Joystick.AxisType.kX), 0);
drive.tankDrive(leftStick.getY(), rightStick.getY());
// drive.mecanumDrive_Polar(leftStick.getY(), leftStick.getX(), rightStick.getTwist());
//TODO add ball manipulation device operations
}
}
|
|
#2
|
|||||
|
|||||
|
Re: Motor Controllers
At a quick glance, the code looks fine. Check to make sure that the 4 talons are plugged into the correct ports and are plugged in correctly. Also check in the driver station that the joysticks are in the first 2 slots in the setup tab.
Additional information, when you enable are the lights on all 4 Talons going solid to show that they have communication? When you move the joysticks, are all 4 Talons flashing red or green to show they are trying to move? Last edited by notmattlythgoe : 01-09-2014 at 01:09 PM. |
|
#3
|
||||
|
||||
|
Re: Motor Controllers
I checked everything. The talons are a solid yellow when not used and the joysticks are in ports one and two. When I push the joysticks forward the talons are a solid red and backwards a solid green. Is it supposed to be green forward?
|
|
#4
|
|||||
|
|||||
|
Re: Motor Controllers
Quote:
All 4 are red when you push it forward? |
|
#5
|
||||
|
||||
|
Re: Motor Controllers
I fixed it by pulling out the pwm cables and plugging them in until they all moved correctly.
Thank you for your help. Last edited by Mr.Roboto3335 : 01-09-2014 at 01:57 PM. |
|
#6
|
|||||
|
|||||
|
Re: Motor Controllers
What are the back 2 doing? Green? If this is the case it seems like maybe your The ports that your Talons are plugged into might be swapped. According to your code you should have these Talons plugged into the following ports:
Front Left - 1 Front Right - 2 Rear Left - 3 Rear Right - 4 |
|
#7
|
|||||
|
|||||
|
Re: Motor Controllers
No problem, glad it was that easy.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|