Package com.test.simplecarusorobot

Source Code of com.test.simplecarusorobot.SimpleFRCBotSimulated

/*
* 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 java.util.Hashtable;

/**
* Simulator interface for the simple robot
* @author leigh
*/
public class SimpleFRCBotSimulated implements AbstractRobot {

    private int armPosition = 0;
    private boolean valveOn = false;

    // arm limit positions
    private final int highSensor = 2;
    private final int lowSensor = -2;

    public Hashtable createSensors() {
        final SimpleFRCBotSimulated me = this;
        Hashtable res = new Hashtable();

        // Create sensor objects
        res.put(SimpleFRCIO.ARM_DOWN_BUTTON, new Sensor(Boolean.class) {
            protected Object retrieveValue() {
                return me.armPosition <= me.lowSensor;
            }
        });
        res.put(SimpleFRCIO.ARM_UP_BUTTON, new Sensor(Boolean.class) {
            protected Object retrieveValue() {
                return me.armPosition >= me.highSensor;
            }
        });
        res.put(SimpleFRCIO.MOTION_STATE, new Sensor(String.class) {
            protected Object retrieveValue() {
                if (me.lowSensor == me.armPosition) {
                    return "At low limit";
                } else if (me.highSensor == me.armPosition) {
                    return "At high limit";
                } else {
                    return "Moving";
                }
            }
        });

        return res;
    }

    public Hashtable createActuators() {
        final SimpleFRCBotSimulated me = this;
        Hashtable res = new Hashtable();

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

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

        return res;
    }

    /**
     * Initialize the robot. Since this is a simulation, there isn't any
     * difference between doing things here or in the constructor (since I'm
     * not waiting for WPI to initialize)
     */
    public void robotInit() {
        // nothing to do here
    }

    /**
     * Update the simulated environment
     * A simple spring-retracted pnumatic cylinder.
     * The physics have been dumbed down for the purposes of demonstration
     */
    public void periodicUpdate() {
        if (valveOn) {
            // trying to move the arm up
            if (this.armPosition < this.highSensor) {
                this.armPosition++;
            }
        } else {
            // spring is pulling the arm down
            if (this.armPosition > this.lowSensor) {
                this.armPosition--;
            }
        }
    }

}
TOP

Related Classes of com.test.simplecarusorobot.SimpleFRCBotSimulated

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.