Go to Post No one can deny the awesome power of FIRST. - Queen_of_Mascot [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-01-2014, 13:02
Mr.Roboto3335's Avatar
Mr.Roboto3335 Mr.Roboto3335 is offline
Wait, What?
AKA: Jimmy
FRC #3335 (Cy-Borgs)
Team Role: Programmer
 
Join Date: Nov 2011
Rookie Year: 2011
Location: Texas
Posts: 47
Mr.Roboto3335 is an unknown quantity at this point
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
    }
}
__________________
Wait, what?
Reply With Quote
  #2   Spotlight this post!  
Unread 09-01-2014, 13:06
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
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 : 09-01-2014 at 13:09.
Reply With Quote
  #3   Spotlight this post!  
Unread 09-01-2014, 13:41
Mr.Roboto3335's Avatar
Mr.Roboto3335 Mr.Roboto3335 is offline
Wait, What?
AKA: Jimmy
FRC #3335 (Cy-Borgs)
Team Role: Programmer
 
Join Date: Nov 2011
Rookie Year: 2011
Location: Texas
Posts: 47
Mr.Roboto3335 is an unknown quantity at this point
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?
__________________
Wait, what?
Reply With Quote
  #4   Spotlight this post!  
Unread 09-01-2014, 13:45
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Motor Controllers

Quote:
Originally Posted by Mr.Roboto3335 View Post
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?
One side is going to give you red and one is going to give you green when you push forward because your motors are facing opposite directions so the motor controllers need to spin the one side backwards.

All 4 are red when you push it forward?
Reply With Quote
  #5   Spotlight this post!  
Unread 09-01-2014, 13:51
Mr.Roboto3335's Avatar
Mr.Roboto3335 Mr.Roboto3335 is offline
Wait, What?
AKA: Jimmy
FRC #3335 (Cy-Borgs)
Team Role: Programmer
 
Join Date: Nov 2011
Rookie Year: 2011
Location: Texas
Posts: 47
Mr.Roboto3335 is an unknown quantity at this point
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.
__________________
Wait, what?

Last edited by Mr.Roboto3335 : 09-01-2014 at 13:57.
Reply With Quote
  #6   Spotlight this post!  
Unread 09-01-2014, 13:56
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Motor Controllers

Quote:
Originally Posted by Mr.Roboto3335 View Post
Only the front two are red.
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
Reply With Quote
  #7   Spotlight this post!  
Unread 09-01-2014, 14:01
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Motor Controllers

Quote:
Originally Posted by Mr.Roboto3335 View Post
I fixed it by pulling out the pwm cables and plugging them in until they all moved correctly.
Thank you for your help.
No problem, glad it was that easy.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:33.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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