Go to Post this has Bugs Bunny/Road Runner physics written all over it! - KenWittlief [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 11:39.

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