Tuesday, August 30, 2016

FTC Robot Behavior Model (Part 4 - Global Data)

This is part 4 of a 5 part series on a robot behavior framework.

Behaviors are connected together with events to form more complex behaviors. In this simple example, pressing the y button on the joystick will trigger a change in the active behavior from driving the robot with an an arcade style input to driving the robot with a tank style input.


This article describes how information is passed from the joystick, motors, and sensors into the behavior framework. The GlobalData class is a buffer between the robot opmode and the behavior classes. If we share behaviors and events as a community, the global data class lets us re-map the I/O between names used in the opmode and names used by different behaviors. Although this is not the most elegant solution, it is simple and fast to implement. Get and Set methods can be used instead of public data if desired.


There is no template or interface for the Global Data. Just create a class called GlobalData and define the data your behavior model needs and produces. Here is an example of the GlobalData class I used in my example:


package com.qualcomm.ftcrobotcontroller.geekmybot;

/** * Created by David Lempia on 8/20/2016. */public class GlobalData {
    public GlobalData(){
    }
    // Gyro    public float headingDot=0.0f, heading=0.0f, headingCmd=0.0f;

    // Motors    public float rightCmd=0.0f, leftCmd=0.0f, rightCmd1=0.0f, leftCmd1=0.0f;

    // Joystick    public float jsLeftX, jsLeftY, jsRightX, jsRightY;
    //public float throttleJs=0.0f, directionJs=0.0f;    public boolean buttonX, buttonY;
    public boolean dpadRt, dpadLt, dpadUp, dpadDn;

    // Time    public float time,enterTime;
    public float deltaTime=0.0f;

    // IR Seeker    public double irAngle,irStrength;
    public boolean irDetected;

    // Debug    public float debugFloat1=0.0f, debugFloat2=0.0f;
    public int debugInt1, debugInt2;
    public double debugDouble1, debugDouble2;
    public boolean debugBoolean1, debugBoolean2;
}

For full copies of this software, see: https://github.com/dlacres/GeekMyBot.git 
 
If you use this behavior framework, I ask that you share the love. 
Print out a copy of the GeekMyBot logo and put it on your robot along 
with the http://geekmybot.blogspot.com/ URL address. Share this Blog 
with your friends.
 
If you develop an event that you are 
particularly proud of, I ask that you add a comment to this article and 
share your behavior along with a link to your software.

No comments:

Post a Comment