Go to Post All hail the amazing duct tape and the mighty zip-tie!!! :] - Gabe [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 29-01-2014, 20:11
sthreet's Avatar
sthreet sthreet is offline
Registered User
AKA: scott threet
FRC #4692
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Toutle Lake
Posts: 84
sthreet is an unknown quantity at this point
Ultrasonic analog input?

We have ultrasonic analog input, wired based on a youtube video.

I however don't understand the parameters of Ultrasonic namehere=new Ultrasonic(a, b);

a is input, what does that mean?
b is output, what does that mean?

I tried 8, 7 and tried with the ultrasound in both analog 8 and analog 7, with the following code:

Code:
if(namehere.getRangeMM<10)
{
drive.tankDrive(1, 1);
}
I know drive.tankDrive(1, 1); works fine, as that works based on joysticks. What am I doing wrong?

Also are their good java tutorials for cameras/encoders/solenoid magnetic sensor thingies anyone know them? (By "good" I mean that it explains the api and the parameters. for example: this parameter means you have to wire the output to <analog/DIO/pwm/other> and it will reference that slot.)
__________________
Spoiler for gif:
Reply With Quote
  #2   Spotlight this post!  
Unread 29-01-2014, 20:23
TFleig78's Avatar
TFleig78 TFleig78 is offline
Registered User
AKA: Tyler
FRC #0078 (Air Strike)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Rhode Island
Posts: 58
TFleig78 will become famous soon enoughTFleig78 will become famous soon enough
Re: Ultrasonic analog input?

We have had more luck with an AnalogChannel object instead of Ultrasonic. Then the getAverageVoltage method returns a value between 0-5v which you can use a scale factor to translate into a distance. We found the scale factor on the stats sheet that came with the rangefinder.
Reply With Quote
  #3   Spotlight this post!  
Unread 29-01-2014, 20:47
sthreet's Avatar
sthreet sthreet is offline
Registered User
AKA: scott threet
FRC #4692
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Toutle Lake
Posts: 84
sthreet is an unknown quantity at this point
Re: Ultrasonic analog input?

Thanks, tried that. It didn't work. I tried distance.getAverageVoltage()<=1 and distance.getAverageVoltage()*9.8<=6 but neither of those worked.

Am I doing something wrong? Using the slot 1 because it won't let me use slot 8. AnalogChannel distance=new AnalogChannel(1);
__________________
Spoiler for gif:
Reply With Quote
  #4   Spotlight this post!  
Unread 29-01-2014, 20:52
TFleig78's Avatar
TFleig78 TFleig78 is offline
Registered User
AKA: Tyler
FRC #0078 (Air Strike)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Rhode Island
Posts: 58
TFleig78 will become famous soon enoughTFleig78 will become famous soon enough
Re: Ultrasonic analog input?

Could you post the code to see what else there might be? Also, have you tried printing out the value from the distance.getAverageVoltage() method to make sure the hardware is working properly?
something like:
Code:
System.out.println(distance.getAverageVoltage());
It should print out the value in the IDE, or you could use NetConsole to read the values.
Reply With Quote
  #5   Spotlight this post!  
Unread 30-01-2014, 16:35
sthreet's Avatar
sthreet sthreet is offline
Registered User
AKA: scott threet
FRC #4692
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Toutle Lake
Posts: 84
sthreet is an unknown quantity at this point
Re: Ultrasonic analog input?

It's always giving a value of 2.99 or 3 (approximately.), I think it is a hardware problem, but will post rest of code tonight if I remember a memory stick.
__________________
Spoiler for gif:
Reply With Quote
  #6   Spotlight this post!  
Unread 31-01-2014, 16:49
sthreet's Avatar
sthreet sthreet is offline
Registered User
AKA: scott threet
FRC #4692
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Toutle Lake
Posts: 84
sthreet is an unknown quantity at this point
Re: Ultrasonic analog input?

Also having trouble stopping a piston partway through, tried setting both solenoids to true, and both to false.

here is 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.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.Watchdog;
import edu.wpi.first.wpilibj.AnalogChannel;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * 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 team4692robot extends SimpleRobot 
{
    RobotDrive drive=new RobotDrive(1, 2);
    Joystick left=new Joystick(1);
    Joystick right=new Joystick(2);
    Compressor airCompressor=new Compressor(1, 1);
    Solenoid launchopen=new Solenoid(1);
    Solenoid launchclose=new Solenoid(2);
    Joystick gamepad=new Joystick(3);
    Talon winch=new Talon(3);
    DigitalInput winchstopper=new DigitalInput(2);
    DigitalInput winchstarter=new DigitalInput(3);
    AnalogChannel distance=new AnalogChannel(1);
    Solenoid extendoropen=new Solenoid(3);
    Solenoid extendorclose=new Solenoid(4);
    
    /**
     * This function is called once each time the robot enters autonomous mode.
     */
    public void autonomous() 
    {
        int autotimer=0;
        
        airCompressor.start();
        
        while(true && isAutonomous() && isEnabled())
        {
            if(autotimer<100)
            {
                drive.tankDrive(.5, -.5);
            }
            else
            {
                drive.tankDrive(0, 0);
            }
            
            autotimer++;
            Timer.delay(.005);
        }
    }

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void operatorControl() 
    {
        boolean winching=false;
        
        airCompressor.start();
        
        while(true && isOperatorControl() && isEnabled())
        {
            double leftpow=left.getY(); double rightpow=right.getY();
            double powermod=.7;
            if(left.getTrigger())
            {
                powermod+=.1;
            }
            if(right.getTrigger())
            {
                powermod+=.2;
            }
            leftpow*=powermod; rightpow*=powermod;
            
            drive.tankDrive(leftpow, rightpow); 
            
            if(gamepad.getRawButton(1) && winching==false && winchstarter.get())
            {
                winching=true;
            }
            else if(winching==true)
            {
                winch.set(1);
                if(winchstopper.get())
                {
                    winching=false;
                    winch.set(0);
                }
            }
            
            winch.set(gamepad.getRawAxis(1));
            
            launchopen.set(!gamepad.getRawButton(2));
            launchclose.set(gamepad.getRawButton(2));
            
            if(gamepad.getRawButton(3))
            {
                extendoropen.set(true);
                extendorclose.set(false);
            }
            if(gamepad.getRawButton(4))
            {
                extendoropen.set(false);
                extendorclose.set(true);
            }
            
            if(!gamepad.getRawButton(3) && !gamepad.getRawButton(4))
            {
                extendoropen.set(true);
                extendorclose.set(true);
            }
                    
            System.out.println(distance.getAverageVoltage());
            if(distance.getAverageVoltage()<=1)
            {
                drive.tankDrive(.5, .5);
            }
            
            Timer.delay(.005);
        }
    }
    
    /**
     * This function is called once each time the robot enters test mode.
     */
    public void test() 
    {
    
    }
    
    public void robotInit()
    {
        drive.setSafetyEnabled(false);
        Watchdog.getInstance().kill();
    }
}

/*
double left=y; double right=y;
if(x>0)
{
    left+=x;
}
if(x<0)
{
    right+=x;
}
drive.tankDrive(left, right);
*/
__________________
Spoiler for gif:
Reply With Quote
  #7   Spotlight this post!  
Unread 31-01-2014, 21:15
dvanvoorst dvanvoorst is offline
Registered User
FRC #2771 (Code Red)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Grand Rapids, MI
Posts: 66
dvanvoorst is an unknown quantity at this point
Re: Ultrasonic analog input?

With an Ultrasonic sensor, you need to either tell it to ping, or set it to automatic ping mode. Otherwise it will read maximum distance.

Add this to your robotInit():

distance.setAutomaticMode(true);
Reply With Quote
  #8   Spotlight this post!  
Unread 02-02-2014, 00:10
James Lightfoot James Lightfoot is offline
Programming & Electrical Mentor
FRC #3737 (Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Wayne County, NC
Posts: 21
James Lightfoot is just really niceJames Lightfoot is just really niceJames Lightfoot is just really niceJames Lightfoot is just really niceJames Lightfoot is just really nice
Re: Ultrasonic PWM instead of analog input?

Hello all,

1st year mentoring, and boy did I underestimate the time it would take for me to come up to speed on Java.

Anyway, I had the team order a MaxBotix MB7366 http://www.maxbotix.com/Ultrasonic_Sensors/MB7366.htm I speced this one as it has the Free Reading mode which will ignore nearly all other ultrasonic sensors that may be in use on the field. The sensor offers analog voltage, PWM & serial outputs. For better signal/ratio ration I want to use the PWM output, but is there an input in this year's cRIO that will take that PWM input? If not, is there a card that will work with it (preferable a mixed I/O type card so as to not buy 1 card just for 1 PWN input)?

Thanks
Reply With Quote
  #9   Spotlight this post!  
Unread 03-02-2014, 18:18
sthreet's Avatar
sthreet sthreet is offline
Registered User
AKA: scott threet
FRC #4692
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Toutle Lake
Posts: 84
sthreet is an unknown quantity at this point
Re: Ultrasonic analog input?

Quote:
Originally Posted by dvanvoorst View Post
With an Ultrasonic sensor, you need to either tell it to ping, or set it to automatic ping mode. Otherwise it will read maximum distance.

Add this to your robotInit():

distance.setAutomaticMode(true);
Doesn't work, no function setAutomaticMode with parameter boolean found in analog class.
EDIT: not exact words, but general meaning.
__________________
Spoiler for gif:
Reply With Quote
  #10   Spotlight this post!  
Unread 03-02-2014, 21:19
sthreet's Avatar
sthreet sthreet is offline
Registered User
AKA: scott threet
FRC #4692
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Toutle Lake
Posts: 84
sthreet is an unknown quantity at this point
Re: Ultrasonic analog input?

Blah. I had it wired in backwards. for anyone in the future: Black wires go towards the main part of the crio.
__________________
Spoiler for gif:
Reply With Quote
  #11   Spotlight this post!  
Unread 07-02-2014, 11:31
dvanvoorst dvanvoorst is offline
Registered User
FRC #2771 (Code Red)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Grand Rapids, MI
Posts: 66
dvanvoorst is an unknown quantity at this point
Re: Ultrasonic analog input?

Quote:
Originally Posted by sthreet View Post
Doesn't work, no function setAutomaticMode with parameter boolean found in analog class.
EDIT: not exact words, but general meaning.
The setAutomaticMode is a function of the Ultrasonic class, not the AnalogChannel class. The Ultrasonic class makes using the sensors much simpler.
Glad you got yours going though!
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:41.

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