Go to Post The best we can all do for our kids as parents, mentors and world citizens, is to model [Gracious Professionalism] always: not to win an award, but because it is the right thing to do. - chapman1 [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 17-03-2014, 22:38
cad321 cad321 is online now
Jack of all trades, Master of none
AKA: Brian Wagg
FRC #2386 (Trojans)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Burlington, Ontario
Posts: 319
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
trying to get encoders working

I am currently trying to get encoders on my teams test bot working so we can then port it over to our competition bot, however I am having so difficulties along the way. Every time I download my code to the bot and enable, I get the message, "Robot Drive... Output not updated often enough." I have looked over my code several times and had others on my team look it over not finding the cause. We are not sure if we are just missing something rather obvious (we're all quite tired), or if theyre might be something wrong with my version of netbeans. I am currently leaning more towards the issue with netbeans because when I re-wrote the code on another laptop, the error went away.

I have attached my current code below. If you could take a look over it and point out any issue that may be causing this or something that will be an issue in the near future, that would be much appreciated.
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.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;

/**
 * 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 RobotTemplate extends IterativeRobot {
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
        Joystick driveStick;      
        RobotDrive mainDrive;
        
        Encoder rightEncoder;
        Encoder leftEncoder;
        double RDistance, LDistance;
                
        //AutoConfig
        double AutoDistance = 60;
        double AutoSpeed = 0.5;
        int AutoTolerance = 6;
        double RSpeed, LSpeed;
        
        boolean DB1;
        
    public void robotInit() {
        leftEncoder.setDistancePerPulse(0.000623);
        rightEncoder.setDistancePerPulse(0.000623);  
        
        driveStick  = new Joystick(1);
        mainDrive = new RobotDrive(1,2,3,4);
        
        rightEncoder = new Encoder(1,2);
        leftEncoder = new Encoder(3,4);
        
        RDistance = rightEncoder.getDistance();
        LDistance = leftEncoder.getDistance();
        
        DB1 = driveStick.getRawButton(1);
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
        rightEncoder.start();
        leftEncoder.start();
        
        if(LDistance < AutoDistance){
            LSpeed = AutoSpeed;
        }else if(LDistance > AutoDistance+AutoTolerance){
            LSpeed = -AutoSpeed;
        }else{
            RSpeed = 0.0;
        }
        
        if(RDistance < AutoDistance){
            RSpeed = AutoSpeed;
        }else if(LDistance > AutoDistance+AutoTolerance){
            LSpeed = -AutoSpeed;
        }else{
            RSpeed = 0.0;
        }
        
        mainDrive.tankDrive(LSpeed, RSpeed);
        
        

    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        mainDrive.arcadeDrive(driveStick);
        
        rightEncoder.start();
        leftEncoder.start();
        
        System.out.println("Right Distance: " + RDistance);
        System.out.println("Left Distance: " + LDistance);
        
        if(DB1 = true){
            rightEncoder.reset();
            leftEncoder.reset();
        }
    }
    
    
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
    
    }
    
}
Also I am aware that the method of using the encoders is quite rudimentary however my team just wants to get it working a little before introducing the PID element. That will come shortly after getting this working.
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 22:46.

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