Skip to content
This repository was archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
merge MentorSandbox -> Master
Browse files Browse the repository at this point in the history
Former-commit-id: 1c4b6b24a8386018899a4af9d7e630ed6136a541
Former-commit-id: 853d458
  • Loading branch information
rgatkinson committed Jan 19, 2016
2 parents ff992a8 + 4c4360e commit ff9b619
Show file tree
Hide file tree
Showing 28 changed files with 72 additions and 302 deletions.
Binary file modified FtcRobotController/libs/FtcCommon-release.aar
Binary file not shown.
Binary file modified FtcRobotController/libs/Hardware-release.aar
Binary file not shown.
Binary file modified FtcRobotController/libs/RobotCore-release.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.qualcomm.ftcrobotcontroller.opmodes.FtcOpModeRegister;
import com.qualcomm.hardware.HardwareFactory;
import com.qualcomm.robotcore.eventloop.EventLoopManager;
import com.qualcomm.robotcore.exception.RobotCoreException;
import com.qualcomm.robotcore.hardware.configuration.Utility;
import com.qualcomm.robotcore.robocol.*;
import com.qualcomm.robotcore.robot.Robot;
Expand Down Expand Up @@ -476,28 +477,7 @@ public synchronized static void installIfNecessary(FtcRobotControllerService ser

// Ok, the EventLoopManager is up and running. Install our hooks if we haven't already done so

// Make sure our event loop manager has a thread-safe socket. Doing so will allow us
// to explore the possibility of sending telemetry from other than the loop() thread.
RobocolDatagramSocket socket = MemberUtil.socketOfEventLoopManager(eventLoopManager);
if (socket != null)
{
if (socket instanceof ThreadSafeRobocolDatagramSocket)
{
}
else
{
// We should be inserting this hook before the socket manages to do anything
assertTrue(!BuildConfig.DEBUG || socket.getState() == RobocolDatagramSocket.State.CLOSED);

// Stuff in a replacement, thread-safe, socket.
RobocolDatagramSocket newSocket = new ThreadSafeRobocolDatagramSocket();
MemberUtil.setSocketOfEventLoopManager(eventLoopManager, newSocket);
robot.socket = newSocket;
Log.v(SynchronousOpMode.LOGGING_TAG, "installed ThreadSafeRobocolDatagramSocket");
}
}

EventLoopManager.EventLoopMonitor monitor = MemberUtil.monitorOfEventLoopManager(eventLoopManager);
EventLoopManager.EventLoopMonitor monitor = eventLoopManager.getMonitor();
if (monitor != null)
{
if (monitor instanceof SwerveEventLoopMonitorHook)
Expand Down Expand Up @@ -566,10 +546,7 @@ void verifyLegalPhoneNames()
{
if (!legalRCNamePattern.matcher(robotControllerName).matches())
{
if (containsNewline(robotControllerName))
reportWifiDirectError("robot controller name \"%s\" contains a carriage return: PLEASE FIX immediately", withoutNewlines(robotControllerName));
else
reportWifiDirectError("\"%s\" is not a legal robot controller name (see <RS02>)", robotControllerName);
reportWifiDirectError("\"%s\" is not a legal robot controller name (see <RS02>)", robotControllerName);
}
}

Expand All @@ -582,10 +559,7 @@ void verifyLegalPhoneNames()
{
if (!legalDSNamePattern.matcher(peer.deviceName).matches())
{
if (containsNewline(peer.deviceName))
reportWifiDirectError("driver station name \"%s\" contains a carriage return: PLEASE FIX immediately", withoutNewlines(peer.deviceName));
else
reportWifiDirectError("\"%s\" is not a legal driver station name (see <RS02>)", peer.deviceName);
reportWifiDirectError("\"%s\" is not a legal driver station name (see <RS02>)", peer.deviceName);
}
}
}
Expand All @@ -596,25 +570,6 @@ void verifyLegalPhoneNames()
// Utility
//------------------------------------------------------------------------------------------

boolean containsNewline(String name)
{
return name.contains("\n") || name.contains("\r");
}
String withoutNewlines(String name)
{
StringBuilder result = new StringBuilder();
for (int ich = 0; ich < name.length(); ich++)
{
char ch = name.charAt(ich);
switch (ch)
{
case '\r':case '\n': break;
default: result.append(ch); break;
}
}
return result.toString();
}

/** Is this peer a driver station? If in doubt, answer 'no'*/
boolean isDriverStation(WifiP2pDevice peer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.qualcomm.robotcore.hardware.IrSeekerSensor;
import com.qualcomm.robotcore.util.RobotLog;
import com.qualcomm.robotcore.util.TypeConversion;
import com.qualcomm.robotcore.util.Util;

import java.util.concurrent.locks.Lock;

Expand Down Expand Up @@ -106,7 +107,7 @@ public void runOpMode() throws InterruptedException {
// I2c addresses on Modern Robotics devices must be divisible by 2, and between 0x7e and 0x10
// Different hardware may have different rules.
// Be sure to read the requirements for the hardware you're using!
IrSeekerSensor.throwIfModernRoboticsI2cAddressIsInvalid(newAddress);
Util.throwIfModernRoboticsI2cAddressIsInvalid(newAddress);

// wait for the start button to be pressed
waitForStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

package com.qualcomm.ftcrobotcontroller.opmodes;

import com.qualcomm.hardware.MatrixDcMotorController;
import com.qualcomm.hardware.matrix.*;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorController;
Expand Down
Binary file added SwerveRoboticsLibrary/sdk/signing.keystore
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,21 @@ public final boolean updateGamepads()
/** Capture the gamepad state so that it will be available for a later updateGamepads() */
private void captureGamepadState()
{
// We conservatively indicate that things have changed
boolean changed1 = true, changed2 = true;
//
if (this.gamepad1Captured == null)
this.gamepad1Captured = new Gamepad();
else
else if (super.gamepad1 != null)
changed1 = !gamepadsSame(this.gamepad1Captured, super.gamepad1);
//
if (this.gamepad2Captured == null)
this.gamepad2Captured = new Gamepad();
else
else if (super.gamepad2 != null)
changed2 = !gamepadsSame(this.gamepad2Captured, super.gamepad2);
//
gamepadAssign(this.gamepad1Captured, super.gamepad1);
gamepadAssign(this.gamepad2Captured, super.gamepad2);
if (super.gamepad1 != null) gamepadAssign(this.gamepad1Captured, super.gamepad1);
if (super.gamepad2 != null) gamepadAssign(this.gamepad2Captured, super.gamepad2);
//
boolean changed = changed1 || changed2;
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ private void clearComposedLines()

private static String getKey(int iLine)
{
// At present (Aug 8, 2015), the driver station both sorts by the key we return here
// but also DISPLAYS it! Ugh. So we try to conserve space. And we use Unicode characters
// that don't actually take up space on the display.
return String.format("%c", 0x180 + iLine);
// Keys must be unique. If they start with nul, then they're not shown on the driver display.
// Historically, they were always shown, and sorted, so we used an increasing sequence
// of unrenderable strings.
return String.format("\0%c", 0x180 + iLine);
}

/**
Expand Down Expand Up @@ -357,6 +357,7 @@ private synchronized boolean update(int msUpdateInterval, boolean userRequest, b
// Build an object to carry our telemetry data.
// Transmit same to the driver station.
Telemetry transmitter = new Telemetry();
transmitter.setSorted(false);
//
for (int i = 0; i < keys.size(); i++)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.swerverobotics.library.internal;

import android.graphics.Color;
import com.qualcomm.hardware.adafruit.*;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.*;
import com.qualcomm.robotcore.util.*;
Expand All @@ -18,7 +19,7 @@
* https://www.adafruit.com/products/1334?&main_page=product_info&products_id=1334
* https://github.com/adafruit/Adafruit_TCS34725
*/
public class AdaFruitTCS34725ColorSensor extends ColorSensor implements IOpModeStateTransitionEvents
public class AdaFruitTCS34725ColorSensor implements ColorSensor, IOpModeStateTransitionEvents
{
//----------------------------------------------------------------------------------------------
// State
Expand Down Expand Up @@ -132,7 +133,7 @@ public static ColorSensor create(OpMode context, ColorSensor target)
int port;
int i2cAddr8Bit;

if (target instanceof com.qualcomm.hardware.AdafruitI2cColorSensor)
if (target instanceof AdafruitI2cColorSensor)
{
controller = MemberUtil.deviceInterfaceModuleOfAdaFruitColorSensor(target);
port = MemberUtil.portOfAdaFruitColorSensor(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,29 +169,12 @@ else if (lhs.isAnnotationPresent(Autonomous.class) && rhs.isAnnotationPresent(Au
}
}

// Check that the overall length of the OpMode names doesn't exceed the (paltry) length
// that can be transmitted from the robot controller to the driver station.
// See FtcEventLoop.sendOpModeList().
StringBuilder nameBuilder = new StringBuilder();
// Finally, register all the OpModes
for (Class<OpMode> opMode : opModesToRegister)
{
if (nameBuilder.length() > 0) nameBuilder.append(com.qualcomm.robotcore.util.Util.ASCII_RECORD_SEPARATOR);
nameBuilder.append(getOpModeName(opMode));
}
if (TypeConversion.stringToUtf8(nameBuilder.toString()).length >= Command.MAX_COMMAND_LENGTH) // see Command.Command
{
reportOpModeConfigurationError("OpMode names are too long to be sent to the Driver Station");
this.opModeManager.register("OpMode names too long", OpModeNamesTooLong.class);
}
else
{
// Finally, register all the OpModes
for (Class<OpMode> opMode : opModesToRegister)
{
String name = getOpModeName(opMode);
this.opModeManager.register(name, opMode);
Log.d(LOGGING_TAG, String.format("registered {%s} as {%s}", opMode.getSimpleName(), name));
}
String name = getOpModeName(opMode);
this.opModeManager.register(name, opMode);
Log.d(LOGGING_TAG, String.format("registered {%s} as {%s}", opMode.getSimpleName(), name));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.swerverobotics.library.internal;

import android.util.Log;
import com.qualcomm.hardware.*;
import com.qualcomm.hardware.modernrobotics.*;
import com.qualcomm.modernrobotics.*;
import com.qualcomm.robotcore.eventloop.*;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
Expand Down Expand Up @@ -47,26 +47,18 @@ enum WRITE_STATUS { IDLE, DIRTY, READ };

public EasyModernController(OpMode context, ModernRoboticsUsbDevice target, ReadWriteRunnableHandy readWriteRunnable) throws RobotCoreException, InterruptedException
{
// We *have to* give a live ReadWriteRunnable to our parent constructor, so we grudgingly do so
super(target.getSerialNumber(), SwerveThreadContext.getEventLoopManager(), readWriteRunnable);

// Wait until the thing actually gets going. We need it to get to the point where the
// 'this.running=true' has at least been set so that the 'this.running=false' we are
// about to do in the close() in next line down will sequence correctly against it.
readWriteRunnable.waitUntilRunGetsGoing();

// Then shut it down right away, because we want to start disarmed until we fully configure
closeModernRoboticsUsbDevice(this);
// Note that we don't give a ReadWriteRunnable to our parent constructor. This essentially just sets the serial number
super(target.getSerialNumber(), SwerveThreadContext.getEventLoopManager(), null);

// Initialize the rest of our state
this.context = context;
this.eventLoopManager = SwerveThreadContext.getEventLoopManager();
this.isArmed = false;
this.writeStatus = WRITE_STATUS.IDLE;

ReadWriteRunnableStandard readWriteRunnableStandard = MemberUtil.getReadWriteRunnableModernRoboticsUsbDevice(target);
ReadWriteRunnableUsbHandler handler = MemberUtil.getHandlerOfReadWriteRunnableStandard(readWriteRunnableStandard);
this.robotUsbDevice = MemberUtil.getRobotUsbDeviceOfReadWriteRunnableUsbHandler(handler);
ReadWriteRunnableStandard targetReadWriteRunnable = (ReadWriteRunnableStandard)MemberUtil.getReadWriteRunnableModernRoboticsUsbDevice(target);
ReadWriteRunnableUsbHandler targetHandler = MemberUtil.getHandlerOfReadWriteRunnableStandard(targetReadWriteRunnable);
this.robotUsbDevice = MemberUtil.getRobotUsbDeviceOfReadWriteRunnableUsbHandler(targetHandler);
}

//----------------------------------------------------------------------------------------------
Expand All @@ -87,23 +79,21 @@ static void closeModernRoboticsUsbDevice(ModernRoboticsUsbDevice usbDevice)
{
// Get access to the state
ExecutorService service = MemberUtil.getExecutorServiceModernRoboticsUsbDevice(usbDevice);
ReadWriteRunnableStandard readWriteRunnableStandard = MemberUtil.getReadWriteRunnableModernRoboticsUsbDevice(usbDevice);

// Stop accepting new work
service.shutdown();

// Set a dummy handler so that we don't end up closing the actual FT_device.
// Note that this overwrites a 'final' member variable, so there's a slight
// risk of running into optimization problems, but we live with that.
RobotUsbDevice robotUsbDevice = new DummyRobotUsbDevice();
ReadWriteRunnableUsbHandler dummyHandler = new ReadWriteRunnableUsbHandler(robotUsbDevice);
MemberUtil.setHandlerOfReadWriteRunnableStandard(readWriteRunnableStandard, dummyHandler);

// Set 'running' to false; this fixes a race condition
MemberUtil.setRunningReadWriteRunnableStandard(readWriteRunnableStandard, false);
ReadWriteRunnableStandard readWriteRunnableStandard = (ReadWriteRunnableStandard)MemberUtil.getReadWriteRunnableModernRoboticsUsbDevice(usbDevice);
if (readWriteRunnableStandard != null)
{
// Set a dummy handler so that we don't end up closing the actual FT_device.
RobotUsbDevice robotUsbDevice = new DummyRobotUsbDevice();
ReadWriteRunnableUsbHandler dummyHandler = new ReadWriteRunnableUsbHandler(robotUsbDevice);
MemberUtil.setHandlerOfReadWriteRunnableStandard(readWriteRunnableStandard, dummyHandler);

// Ok: actually carry out the close
readWriteRunnableStandard.close();
// Ok: actually carry out the close
readWriteRunnableStandard.close();
}

// Wait until the thread terminates
Util.awaitTermination(service);
Expand All @@ -118,9 +108,9 @@ void installReadWriteRunnable(ModernRoboticsUsbDevice usbDevice, int cbMonitor,
//
MemberUtil.setExecutorServiceModernRoboticsUsbDevice(usbDevice, service);
MemberUtil.setReadWriteRunnableModernRoboticsUsbDevice(usbDevice, rwRunnable);
rwRunnable.setCallback(usbDevice);
service.execute(rwRunnable);
rwRunnable.blockUntilReady();
rwRunnable.setCallback(usbDevice);
this.eventLoopManager.registerSyncdDevice(rwRunnable);
}
catch (Exception e)
Expand Down Expand Up @@ -272,42 +262,6 @@ static class DummyRobotUsbDevice implements RobotUsbDevice
}
}

/**
* A handler that let's you know when it's had methods called on it
*/
static class InterlockingReadWriteRunnableUsbHandler extends ReadWriteRunnableUsbHandler
{
private ManualResetEvent methodCalled = new ManualResetEvent(false);

public InterlockingReadWriteRunnableUsbHandler(RobotUsbDevice device)
{
super(device);
}

@Override public void purge(RobotUsbDevice.Channel channel) throws RobotCoreException
{
methodCalled.set();
super.purge(channel);
}

@Override public void read(int address, byte[] buffer) throws RobotCoreException, InterruptedException
{
methodCalled.set();
super.read(address, buffer);
}

@Override public void write(int address, byte[] buffer) throws RobotCoreException, InterruptedException
{
methodCalled.set();
super.write(address, buffer);
}

void awaitMethodCall() throws InterruptedException
{
this.methodCalled.waitOne();
}
}

/**
* This class is a ReadWriteRunnableStandard but one that doesn't report any errors
* due to connection failures in its blockUntilReady(). And you can interlock with its
Expand All @@ -318,14 +272,6 @@ static class ReadWriteRunnableHandy extends ReadWriteRunnableStandard
public ReadWriteRunnableHandy(SerialNumber serialNumber, RobotUsbDevice device, int monitorLength, int startAddress, boolean debug)
{
super(serialNumber, device, monitorLength, startAddress, debug);
InterlockingReadWriteRunnableUsbHandler handler = new InterlockingReadWriteRunnableUsbHandler(device);
MemberUtil.setHandlerOfReadWriteRunnableStandard(this, handler);
}

void waitUntilRunGetsGoing() throws InterruptedException
// We ideally want to wait until after 'running' is set and the log is written
{
((InterlockingReadWriteRunnableUsbHandler)this.usbHandler).awaitMethodCall();
}

@Override public void run()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.swerverobotics.library.internal;

import android.util.Log;
import com.qualcomm.hardware.*;
import com.qualcomm.hardware.modernrobotics.*;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.exception.*;
import com.qualcomm.robotcore.hardware.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.swerverobotics.library.internal;

import android.util.Log;
import com.qualcomm.hardware.*;
import com.qualcomm.hardware.modernrobotics.*;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.exception.*;
import com.qualcomm.robotcore.hardware.*;
Expand Down
Loading

0 comments on commit ff9b619

Please sign in to comment.