Go to Post The best thing that could be said about 2015 was things could only go up from there. - Koko Ed [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 02-06-2015, 18:41
iggy_gim's Avatar
iggy_gim iggy_gim is offline
Registered User
AKA: Theodore Kim
FRC #5123 (Mechadogs)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2012
Location: Yonkers, NY
Posts: 79
iggy_gim is on a distinguished road
Capping Speed in Java

Hello all,

I thought I posted this topic here yesterday but I don't see it. Forgive me if I actually did post it somewhere else and am now repeating myself.

Our team is going to be doing a demonstration at a local elementary school and we are going to let the students drive our robot for a while. Is it possible to cap the speed of the robot via programming (for a quick fix) via Java. Thank you!
__________________
My motto: Eh... that looks about right...
---------------
2013: Team 2344 Saunders Droid Factory
2014-16: Team 5123 Mechadogs, Captain/Founder
2017: Team 5123 Mechadogs Mentor
Reply With Quote
  #2   Spotlight this post!  
Unread 02-06-2015, 18:55
thatprogrammer's Avatar
thatprogrammer thatprogrammer is offline
Registered User
AKA: Ahad Bawany
no team (None)
Team Role: Programmer
 
Join Date: Apr 2014
Rookie Year: 2014
Location: Florida
Posts: 610
thatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond repute
Re: Capping Speed in Java

Yes. If you're using tank or arcade, just make it so the output of the drive motors is hapf, or whatever you need the max to be, of the joysticks' x and y values. If you need further explication or an example, just ask and I can pm this or or post it here.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-06-2015, 21:42
dubiousSwain's Avatar
dubiousSwain dubiousSwain is offline
The ride never ends
AKA: Christian Steward
FRC #5420 (Velocity)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2011
Location: USA
Posts: 304
dubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond repute
Re: Capping Speed in Java

dividing the speed in half also works for mechanum
__________________
2015 MAR District Champions




Reply With Quote
  #4   Spotlight this post!  
Unread 03-06-2015, 00:09
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,686
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Capping Speed in Java

If you want to be really slick, leverage object orientation to the fullest, and reduce the number of places you'll have to modify code, you could create a new class called (for example) "limited_controller" that extends your current motor controller class. The code for this class basically recreates all of the methods of the superclass through use of super, and modifies only the "set" method to enforce the top limit, or divide by 2, or whatever. Then, when you initialize your motor controllers, use "new limited_controller([args])" rather than (for example) "new Talon([args])".
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #5   Spotlight this post!  
Unread 18-06-2015, 02:06
kiningsdd kiningsdd is offline
Registered User
no team
 
Join Date: Jun 2015
Rookie Year: 2014
Location: Undua
Posts: 2
kiningsdd is an unknown quantity at this point
Re: Capping Speed in Java

Dividing mechanism may that help you.
Reply With Quote
  #6   Spotlight this post!  
Unread 26-06-2015, 17:18
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Capping Speed in Java

I'll also leave this code here. Just initialize this class with the joystick port you desire and any button on that controller (or left/right trigger for xbox controllers, axes drifted too much) and the robot stops until you release said button. (To do this, call pollForPressed() than if(!good()){kill robot})

Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.chimeras1684.year2014.iterative.aaroot;
import edu.wpi.first.wpilibj.Joystick;

/**
 *
 * @author Arhowk
 */
public class DeadSwitch {
    
    final static int MAX_NUM_BUTTONS = 10;
    final static int MAX_NUM_AXES = 6;
    final static double TRIGGER_POLL = 0.5;
    
    m_DR reciever;
    
    private static class m_DR{
        private Joystick djoy = null;
        
        public boolean pollButton(int axis){
            if(djoy != null) return djoy.getRawButton(axis);
            else return false;
        } 
        
        public boolean pollRightTrigger(){
            if(djoy != null){
//                System.out.println("right trigger : " + (djoy.getRawAxis(3) < -TRIGGER_POLL));
                return djoy.getRawAxis(3) < -TRIGGER_POLL;
            }
            return false;
        }
        public boolean pollLeftTrigger(){
            if(djoy != null){
//                System.out.println("left trigger : " + (djoy.getRawAxis(3) > TRIGGER_POLL));
                return djoy.getRawAxis(4) > TRIGGER_POLL;
            }
            return false;
        }
        
        public static m_DR joystick(Joystick j){
            m_DR m = new m_DR();
            m.djoy = j;
            return m;
        }
    }
    
    private boolean [] axes;
    private double [] joys;
    
    private boolean leftTrigger, rightTrigger;
    
    private int last = -1;
    
    public DeadSwitch(int port){
        reciever = m_DR.joystick(new Joystick(port));
        axes = new boolean [MAX_NUM_BUTTONS];
        joys = new double [MAX_NUM_AXES];
    }
    
    public int pollForPressed(){
        
        for(int i = 0; i < MAX_NUM_BUTTONS; i++){
            if(reciever.pollButton(i)){
                if(!axes[i]){
                    last = i;
                    axes[i] = true;
                }
            }else axes[i] = false;
        }
        
        if(reciever.pollLeftTrigger()){
            if(!leftTrigger){
                leftTrigger = true;
                last = 100;
            }
        }else leftTrigger = false;
        
        if(reciever.pollRightTrigger()){
            if(!rightTrigger){
                rightTrigger = true;
                last = 99;
            }
        }else rightTrigger = false;
        
        return last;
    }
    
    public boolean good(){
        if(last == -1) return true;
        else if(last == 99) return reciever.pollRightTrigger();
        else if(last == 100) return reciever.pollLeftTrigger();
        else return reciever.pollButton(last);
    }
    
    public void disabledInit(){
        pollForPressed();
        last = -1;
    }
    
}
Our team used this in tandem with speed controls for demos, mainly because a half speed robot can still cause some serious damage.
__________________
FRC Team 1684 - Head Programmer (2013-2016)
FRC Team 5460 - Programming Mentor (2015-2016)

FIRST in Michigan - Technical Crew (2015-continuing)
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 12:56.

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