Go to Post Please look around the forum, I believe this clue is already under discussion and has been overly dissected. - ttldomination [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 02-12-2016, 09:09 AM
nlt5 nlt5 is offline
Registered User
FRC #5676
 
Join Date: Feb 2016
Location: Michigan
Posts: 23
nlt5 is an unknown quantity at this point
Help with Code

Thanks to all on this sight for the guidance offered to all teams. We are working hard trying to figure out how to write code and we need some help. below is the code we have written so far. What we want to have happen is for our drive system to be arcade and we are using the left joystick on our xbox controller and we have two shooter motors. Ideally I would like to have the shooter motors turn on and off with one button but I am not sure how to write that so I attempted to start the motors with the press of one button and turn them off with another button. So far nothing works. The drive motors turn in opposite directions, so I attempted to invert the motors. This allowed us to drive forward and reverse but we could not turn. I am not concerned with autonomous at this time just teleop. I would appreciate any insight into problems with this code and suggestions on how to make it work. Thank you in advance. (sorry i'm not sure the best way to attache my code.)

Code:
package org.usfirst.frc.team5676.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.*;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;

/**
 * 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 {
    RobotDrive DriveTrain41;
    SpeedController victorsp1;
    SpeedController victorsp2;
    SpeedController victorsp3;
    SpeedController victorsp4;
    SpeedController victorsp5;
    SpeedController victorsp6;
    RobotDrive shootermotors;
    Joystick xboxcontroller;
    JoystickButton Leftjoystick;
    JoystickButton xbutton;
    JoystickButton ybutton;
    int autoLoopCounter;
    
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
        DriveTrain41 = new RobotDrive(victorsp1,victorsp2,victorsp3, victorsp4);
        shootermotors = new RobotDrive(victorsp5,victorsp6);
        xboxcontroller = new Joystick(0);
        xbutton = new JoystickButton(xboxcontroller,8);
        ybutton = new JoystickButton(xboxcontroller, 9);
        
    }
    
    /**
     * This function is run once each time the robot enters autonomous mode
     */
    public void autonomousInit() {
        autoLoopCounter = 0;
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
        if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds)
        {
            DriveTrain41.drive(-0.5, 0.0);     // drive forwards half speed
            autoLoopCounter++;
            } else {
            DriveTrain41.drive(0.0, 0.0);     // stop robot
        }
    }
    
    /**
     * This function is called once each time the robot enters tele-operated mode
     */
    public void teleopInit(){
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        DriveTrain41.arcadeDrive(xboxcontroller);
        shootermotors.setInvertedMotor(RobotDrive.MotorType.kFrontLeft, true);
        
        if(xboxcontroller.getRawButton(8)){
            shootermotors.drive(1,0);
        }
        else if (xboxcontroller.getRawButton(9)){
            shootermotors.drive(0, 0);
        }
   
     
        
        
    }
    
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
        LiveWindow.run();
    }
    
}

Last edited by nlt5 : 02-12-2016 at 10:16 AM.
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 08:03 AM.

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