Skip to content

Instantly share code, notes, and snippets.

View NoahAndrews's full-sized avatar

Noah Andrews NoahAndrews

View GitHub Profile
@NoahAndrews
NoahAndrews / SwitchConfigFromOpMode.md
Last active December 7, 2017 03:16
Switching the config file from within an OpMode

To start with, create a new RobotConfigFileManager. You'll need to pass in the main activity if you want the UI to update when the config changes (which you should so no one gets confused). However, if you pass null, that shouldn't cause any problems. There are null checks whereever the parameter is used internally.

To get the main activity, use (FtcRobotControllerActivity)hardwareMap.appContext (only guaranteed to work on version 3.5)

Next, create a new RobotConfigFile. You'll need to pass in the file manager you created before, as well as the name of the config you want to switch to.It should work with or without the .xml extension, but it will strip out the extension behind the scenes.

Then call setActiveConfigAndUpdateUI(false, myRobotConfigFile) on your instance of RobotConfigFileManager. (replace myRobotConfigFile with whatever you named your instance of RobotConfigFile) There are variations on that method, but that is the one you want. It will tell the Driver Station about the new config.

@NoahAndrews
NoahAndrews / MrPIDTest.java
Last active January 11, 2018 20:56
How to set PID parameters on an MR motor controller (untested)
package org.firstinspires.ftc.teamcode;
import com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.DifferentialControlLoopCoefficients;
@Autonomous(name = "MR PID Test")
public class MrPIDTest extends LinearOpMode {
@Override
@NoahAndrews
NoahAndrews / GetConfigName.java
Created January 18, 2018 15:12
Getting the current configuration file's name
package org.firstinspires.ftc.teamcode;
import android.app.Activity;
import com.qualcomm.ftccommon.configuration.RobotConfigFileManager;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
@Autonomous(name = "Get Current Config File")
public class GetConfigName extends LinearOpMode {

Messages

All communication over the WebSocket connection is done through Messages, which are passed back and forth between the WebSocket client and the robot using a consistent JSON format. They have three fields, namespace, type, and payload.

namespace is used to route messages on the robot/server side, and to allow clients to specify what information they are interested in (through subscription). This allows for separation of concerns.

The type field is used to specify what the message means. Types are scoped to namespaces, so you can safely reuse them between namespaces.

The payload field optionally contains arbitrary text (often escaped JSON). The libraries will handle performing the escaping for you.

Messages can be sent either as responses to a specific client, or broadcast to an entire namespace (all connections that have subscribed to the namespace will receive the message).

// SPDX-License-Identifier: GPL-2.0-or-later
/*
* HID driver for Sony DualSense(TM) controller.
*
* Copyright (c) 2020-2022 Sony Interactive Entertainment
*/
#include <linux/bits.h>
#include <linux/crc32.h>
#include <linux/device.h>
@NoahAndrews
NoahAndrews / multiplyFloat.js
Last active July 23, 2024 03:13 — forked from wchargin/multiplyFloat.js
multiply bigint by float in JS (spoiler alert: BigInt has no useful functions)
// Copied under the MIT license from https://gist.githubusercontent.com/wchargin/93062064e1ec0e3383b91b921da86048/raw/191a10b5ea5169a6c5c436a172353002e653b04c/multiplyFloat.js
/**
* For a finite normal 64-bit float `f`, extracts integers `sgn`,
* `exponent`, and `mantissa` such that:
*
* - `sgn` is -1 or +1
* - `exponent` is between -1023 and 1024, inclusive
* - `mantissa` is between 0 and 2^51 - 1, inclusive
* - the number given by `f` equals `sgn * 2^exponent * (1 + mantissa / 2^52)`