Go to Post There is no rule that specifically states that you must obey the law of physics during the competition. This may be an oversight. - bmather [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-10-2014, 11:25 PM
cogbrained3244 cogbrained3244 is offline
Registered User
FRC #3244
 
Join Date: Nov 2012
Location: St.Cloud MN
Posts: 5
cogbrained3244 is an unknown quantity at this point
Question How in the world do I code and wire this wacky sensor(a.k.a. Photoswitch)

So, we're tossing a telescoping blocker on our robot, and the mentors want a way to control it so it doesn't try and go past it's safe spot. So they handed me this thingy and told me "Figure out how to wire this. Then figure out how to program it." The Javadocs don't have anything I could see about using these. So how they work is a little beyond me.

I know that this is a photoswitch/photometer and that I want to get a true false value out of the thing's feedback. But where do these four wires connect to, is it analog or digital, and how do I write code for it?

Note that other members of my team might write replies to this topic consorting with me, so check our team number before you get confused by someone's post. Also, apologies for tossing the pictures of the thing in a word document. It was the only way to get the file size down.
Attached Files
File Type: doc Photo 2 Photometer.doc (358.5 KB, 34 views)
Reply With Quote
  #2   Spotlight this post!  
Unread 02-10-2014, 11:39 PM
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,697
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: How in the world do I code and wire this wacky sensor(a.k.a. Photoswitch)

The wiring diagram is on the back of the sensor.
Blue = ground
Brown = 12v
White or Black = signal (pick one, they just give opposite results)
It gets wired to a Digital Input and in code it'll act like a switch.

Something to be aware of with these sensors is they nominally require at least 11v, so if your robot power dips too low you may see bogus inputs.
It works best if you can feed it with a regulated 12v of power.

Allen-Bradley RightSight Specs
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 02-11-2014 at 08:12 AM.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-10-2014, 11:49 PM
Pault's Avatar
Pault Pault is offline
Registered User
FRC #0246 (Overclocked)
Team Role: College Student
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Boston
Posts: 618
Pault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond repute
Re: How in the world do I code and wire this wacky sensor(a.k.a. Photoswitch)

One thing to beware of is that unlike most sensors, you are going to want to wire this guy to your power distribution board for 12v and ground. There should only be a signal wire going to the digital side car; whether you choose the white or black only changes whether light = true or light = false.

Treat it like a normal digital input in code. I can't remember how you do that in Java, but it should be fairly simple.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-11-2014, 09:42 PM
wolfspell12 wolfspell12 is offline
Registered User
FRC #3244
 
Join Date: Jan 2014
Location: Minnesota
Posts: 16
wolfspell12 is an unknown quantity at this point
Re: How in the world do I code and wire this wacky sensor(a.k.a. Photoswitch)

It is actually 24 volts according to the manufacture's manual that we printed- don't mean to be a know-it-all.

Anyways, we can't even get the part to move without the sensor. The Jag code all looks normal to me.

We tested and the jag will operate with BDC-Comm.

Anyone have a clue what's wrong with our 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.Joystick;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DriverStationLCD;
import edu.wpi.first.wpilibj.Gyro;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.IterativeRobot;

/**
 * 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 {

    Joystick driver = new Joystick(1);
    Joystick operator = new Joystick(2);
    Jaguar claw = new Jaguar(6);
    Jaguar frontLeft = new Jaguar(2);
    Jaguar rearLeft = new Jaguar(3);
    Jaguar frontRight = new Jaguar(4);
    Jaguar rearRight = new Jaguar(5);
    Jaguar defender = new Jaguar(10);
    Compressor comp = new Compressor(1, 1);//Constructor Order: Digitial I/O, Relay
    Solenoid boomup = new Solenoid(7);
    Solenoid boomdown = new Solenoid(1);
    RobotDrive drive = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);
    Gyro gyro = new Gyro(1);
    //Timer time = new Timer();
    DigitalInput photoswitch = new DigitalInput(2);
    DriverStationLCD dataPrinter = DriverStationLCD.getInstance();
    boolean didAuto = false;

    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
        gyro.reset();
        comp.start();
        drive.setSafetyEnabled(false);
        /* drive.setInvertedMotor(RobotDrive.MotorType.kFrontLeft, false);
        drive.setInvertedMotor(RobotDrive.MotorType.kRearLeft, false);
        drive.setInvertedMotor(RobotDrive.MotorType.kFrontRight, false);
        drive.setInvertedMotor(RobotDrive.MotorType.kRearRight, false);*/
        
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
        log("didAuto= " + didAuto);

        if (didAuto) {
            return;//after value is set to true, the code will stop executing.
        }
        final double autoSpeed = 1.0;
        final long autoTime = 5000; //mili seconds

        long start = System.currentTimeMillis();
        while (true) {
            drive.tankDrive(autoSpeed, autoSpeed);
            //frontLeft.set(autoSpeed);//invert these if it drives backwards
            //rearLeft.set(autoSpeed);
            //frontRight.set(-autoSpeed);//Experimental
            //rearRight.set(-autoSpeed);//inversion of input will drive forward (we hope!)
            if ((System.currentTimeMillis() - start) > autoTime) {
                break;
            }
        }//moves robot straight forward for five seconds
//       log("Time start " + System.currentTimeMillis());
//       Timer.delay(autoTime);
//       log("Timer stop " + System.currentTimeMillis());
        claw.set(-.7);//drops claw
        didAuto = true;//prevents autonomous from running again.
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        //final double axisOutput = driver.getRawAxis(4);
        drive.mecanumDrive_Cartesian(driver.getRawAxis(1), driver.getRawAxis(3), -driver.getRawAxis(2), gyro.getAngle());
        /*if (driver.getRawAxis(4) < -0.1) {
            //to strafe left
            log("I'm going left " + axisOutput);
            frontLeft.set(-driver.getRawAxis(4));
            rearLeft.set(driver.getRawAxis(4));
            frontRight.set(driver.getRawAxis(4));
            rearRight.set(-driver.getRawAxis(4));
        } else if (driver.getRawAxis(4) > 0.1) {
            //to strafe right
            log("I'm going right " + axisOutput);
            frontLeft.set(driver.getRawAxis(4));
            rearLeft.set(-driver.getRawAxis(4));
            frontRight.set(-driver.getRawAxis(4));
            rearRight.set(driver.getRawAxis(4));
        }  else if(driver.getRawAxis(5) > 0){
         frontLeft.set(driver.getRawAxis(5));
         rearLeft.set(driver.getRawAxis(5));
         frontRight.set(driver.getRawAxis(5));
         rearRight.set(driver.getRawAxis(5));
         }
         else if(driver.getRawAxis(5) < 0){
         frontLeft.set(driver.getRawAxis(5));
         rearLeft.set(driver.getRawAxis(5));
         frontRight.set(driver.getRawAxis(5));
         rearRight.set(driver.getRawAxis(5));
         } else {
            drive.mecanumDrive_Cartesian(driver.getRawAxis(1), driver.getRawAxis(2), -driver.getRawAxis(3), gyro.getAngle());
            log("I'm reaching the else. Yay!");
        }*/

        if (operator.getRawButton(4)) {
            //Y button
            claw.set(1);
        } else if (operator.getRawButton(1)) {
            claw.set(-0.7);
        } else {
            claw.set(0);
        }

        if (operator.getRawButton(8)) {
            //Start button
            comp.start();
        } else if (operator.getRawButton(7)) {
            //Back 
            comp.stop();
        }

        if (driver.getRawButton(8)) {
            comp.start();
        } else if (driver.getRawButton(7)) {
            comp.stop();
        }

        if (operator.getRawButton(5)) {
            boomup.set(true);
            boomdown.set(false);
        } else if (operator.getRawButton(6)) {
            boomdown.set(true);
            boomup.set(false);
        }
        /* if (photoswitch.get() == true) {
        if (operator.getRawButton(2)) {
        defender.set(1.0);
        }
        }
        else if (photoswitch.get() == false) {
        if (operator.getRawButton(3)) {
        defender.set(-1.0);
        }
        }*/
        if (operator.getRawButton(2)) {
            defender.set(1.0);
        } else if (operator.getRawButton(3)) {
            defender.set(-1.0);
        }
    }
        
    

    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
        didAuto = false;
    }

    public double centerXbox(double axisOutput) {
        double reducedSensitivity = axisOutput;
        if (axisOutput > -0.2 || axisOutput < 0.2) {
            reducedSensitivity = 0;
        }
        return reducedSensitivity;
    }

    private void log(String msg) {
        dataPrinter.clear();
        dataPrinter.println(DriverStationLCD.Line.kUser1, 1, msg);
        dataPrinter.updateLCD();
    }

}
Reply With Quote
  #5   Spotlight this post!  
Unread 02-12-2014, 01:09 AM
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,547
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: How in the world do I code and wire this wacky sensor(a.k.a. Photoswitch)

Quote:
Originally Posted by wolfspell12 View Post
Anyways, we can't even get the part to move without the sensor. The Jag code all looks normal to me.

We tested and the jag will operate with BDC-Comm.
Since you mention BDC-Comm, does that mean you are trying to use CAN? The code you posted has defender jaguar on PWM 10.
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 07:42 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