Go to Post You can never take enough precautions when it comes to safety. Please, be prepared for anything. - Tom Bottiglieri [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 17-03-2014, 22:38
cad321 cad321 is offline
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: 318
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
  #2   Spotlight this post!  
Unread 17-03-2014, 23:15
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,543
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: trying to get encoders working

Code:
        leftEncoder.setDistancePerPulse(0.000623);
        rightEncoder.setDistancePerPulse(0.000623);
You are calling these methods before creating the leftEncoder and rightEncoder objects, which is causing the code to crash. If you scroll up in the output window, you will see a stack trace which would point to those lines.
Reply With Quote
  #3   Spotlight this post!  
Unread 17-03-2014, 23:22
cad321 cad321 is offline
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: 318
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
Re: trying to get encoders working

Quote:
Originally Posted by Joe Ross View Post

You are calling these methods before creating the leftEncoder and rightEncoder objects, which is causing the code to crash. If you scroll up in the output window, you will see a stack trace which would point to those lines.
So changing the code to this should in theory stop causing the code to crash:
Code:
public void robotInit() {
        driveStick  = new Joystick(1);
        mainDrive = new RobotDrive(1,2,3,4);
        
        rightEncoder = new Encoder(1,2);
        leftEncoder = new Encoder(3,4);
        
        leftEncoder.setDistancePerPulse(0.000623);
        rightEncoder.setDistancePerPulse(0.000623);
        
        RDistance = rightEncoder.getDistance();
        LDistance = leftEncoder.getDistance();
        
        DB1 = driveStick.getRawButton(1);
    }
Unfortunately I don't have the output from the Crio anymore but I understand how that would cause a problem.
Reply With Quote
  #4   Spotlight this post!  
Unread 18-03-2014, 07:48
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
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,712
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: trying to get encoders working

You also shouldn't need to start your encoders in every execution of the teleopPeriodic method. Move the starts of the encoders to robot init after all of the initialization of the encoders.
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 17:16.

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