Package com.test.simplecarusorobot

Source Code of com.test.simplecarusorobot.SimpleFRCBotPhysical

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.test.simplecarusorobot;

import ca.teamdave.caruso.AbstractRobot;
import ca.teamdave.caruso.actuator.Actuator;
import ca.teamdave.caruso.sensor.Sensor;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Solenoid;
import java.util.Hashtable;

/**
* Physical implementation of the robot, simply maps sensors and actuators
* to calls from WPI.
* @author leigh
*/
public class SimpleFRCBotPhysical implements AbstractRobot {

   
    // Sensors
    DigitalInput armUpButton;
    DigitalInput armDownButton;
   
    // Actuators
    Solenoid armValve;

    /**
     * The rest of the robot has initialized, this is the place to create WPI objects
     */
    public void robotInit() {
        this.armUpButton = new DigitalInput(1);
        this.armDownButton = new DigitalInput(2);

        this.armValve = new Solenoid(1);
    }

    /**
     * Called after #robotInit, tells caruso what input the robot has
     * @return The Sensor objects indexed by sensor names
     */
    public Hashtable createSensors() {
        final SimpleFRCBotPhysical me = this;

        Hashtable res = new Hashtable();
        res.put(SimpleFRCIO.ARM_UP_BUTTON, new Sensor(Boolean.class) {
            protected Object retrieveValue() {
                return (me.armUpButton.get() ? Boolean.TRUE : Boolean.FALSE);
            }
        });
        res.put(SimpleFRCIO.ARM_DOWN_BUTTON, new Sensor(Boolean.class){
            protected Object retrieveValue() {
                return (me.armDownButton.get() ? Boolean.TRUE : Boolean.FALSE);
            }
        });

        return res;
    }

    /**
     * Called after #robotInit, tell caruso what outputs the robot has
     * @return The Actuator Objects indexed by actuator names
     */
    public Hashtable createActuators() {
        final SimpleFRCBotPhysical me = this;

        Hashtable res = new Hashtable();
        res.put(SimpleFRCIO.ARM_VALVE, new Actuator(Boolean.class){
            protected void assignValue(Object val) {
                me.armValve.set(((Boolean)val).booleanValue());
            }

            protected Object retriveValue() {
                return (me.armValve.get() ? Boolean.TRUE : Boolean.FALSE);
            }
        });

        return res;
    }

    /**
     * Called every cycle before the controller is updated.
     *
     * If you want to do lower-level signal filtering that you wouldn't do
     * in the simulator environment (button debouncing, camera processing, etc.)
     * do it here.
     */
    public void periodicUpdate() {
        // nothing to do here...

    }
}
TOP

Related Classes of com.test.simplecarusorobot.SimpleFRCBotPhysical

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.