Code Monkey home page Code Monkey logo

wpilib-ws-robot's Introduction

wpilib-ws-robot

Library for creating robots controllable via WPILib's WebSocket protocol

Installation

npm install wpilib-ws-robot

Overview

This package consists of two main units, an abstract class representing a robot (WPILibWSRobotBase) and an endpoint (either client or server) that links a provided WPILibWSRobotBase-derived class and the protocol implementation from node-wpilib-ws. The endpoint (WPILibWSRobotEndpoint) acts as an interface between the WPILib WebSocket protocol implementation and the robot controller.

Usage

To start, create a robot controller class that extends from WPILibWSRobotBase. This abstract base class provides methods to interact with robot "hardware" (this can be actual hardware, or even a simulated robot). See src/debug-robot.ts for a simplistic example.

With a concrete robot controller class in hand, you can then create an endpoint, passing in the robot controller as a parameter. Endpoints come in two flavors, a client or a server.

To create a server (which interacts with the halsim_ws_client extension):

const endpointServer = WPILibWSRobotEndpoint.createServer(robot, optionalServerConfig);

Similarly, to create a client (which interacts with the halsim_ws_server extension):

const endpointClient = WPILibWSRobotEndpoint.createClient(robot, optionalClientConfig);

Once your endpoint is created, start it up with the startP() method, which resolves a promise when the protocol interface and robot are ready.

endpoint.startP()
.then(() => {
    console.log("System Ready");
});

Example Implementations

This library is designed to make it easy to implement a robot controller interface. For a more feature complete example, look at the reference robot design

wpilib-ws-robot's People

Contributors

jpokornyiii avatar zhiquanyeo avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

wpilib-ws-robot's Issues

DriverStation enabled setting should be reset on disconnect

In_handleCloseConnection,
_driverStationEnabled = false
Logically, if the DS is does not send an event upon startup (say is not running at the time), it would have an incorrect setting and may inadvertently allow the motors to run when they are not supposed to.

Motors running after disabled

Motors continue to run after drive station is disabled. Upon a disabled signal, this should stop the motors. (Might need a signal on halsim extension but logging it here for now)

Motors run upon start up

After the first run from wpilib, upon next run (leaving robot on), when connection happens it will start the motors at full steam even while FRC Drive Station is disabled. It takes a signal from wpilib client to stop them. Note that bringing drive through down and back up on the pi seems to resolve the issue. So it appears it's related to data left over from the previous connection.

Disabled to Auto transition doesn't let motor restart

Program which just drives the motors in auto and nothing else.

  1. Start program - it comes up disabled.
  2. Switch to auto - motors start running
  3. Switch back to disabled - the motors stop
    4 Switch back to auto - the motors do not start again.

But if I switch to teleop, then auto, the motors will start. And if I put a tankDrive(0,0) in disabled periodic, then the disabled->auto transition does restart the motors.

Add ability to register encoders with the `WPILibWSRobotBase`

In the HAL layer, encoders are identified by a virtual channel number, which does not correspond to the pins that they use for the quadrature channels (A/B). This could lead to a situation where a subclass of WPILibWSRobotBase assumes that encoders are declared in a particular order, and return incorrect results.

Since the WS layer receives the quadrature channels as part of the initialization message, it should also inform the connected WPILibWSRobotBase of the virtual encoder channel number, and the quadrature channel numbers, and allow it to decide what encoder values to return (e.g. if the A/B channels are swapped, we might want to return the inverse of the current encoder reading)

Motors start up immediately if wpilib ran first and server started second

If wpilib (and hal extension halsim_ws_client.dll) is started first, then wpilib-ws-robot (romi in my case), the motors start immediately upon connection. It seems there is a difference in either messages processed or messages sent from wpilib in this case. If the robot starts after hal, it seems that hal sends position and raw with init true. Since the robot then thinks it's initialized, it uses these values incorrectly and uses them to set the speed of the motors.

This is what is printed if you add console.log at:
https://github.com/bb-frc-workshops/wpilib-ws-robot/blob/master/src/wpilib-ws-robot-endpoint.ts#L169
BAD CASE (wplib and hal started first, wpilib-ws-robot second)
Successfully connected
_handlePWMEvent channel:1 payload:{"<init":true}
_handlePWMEvent channel:1 payload:{"<speed":0}
_handlePWMEvent channel:1 payload:{"<position":0}
_handlePWMEvent channel:1 payload:{"<raw":0}
_handlePWMEvent channel:1 payload:{"<period_scale":0}
_handlePWMEvent channel:1 payload:{"<zero_latch":false}
_handlePWMEvent channel:0 payload:{"<init":true}
_handlePWMEvent channel:0 payload:{"<speed":0}
_handlePWMEvent channel:0 payload:{"<position":0}
_handlePWMEvent channel:0 payload:{"<raw":0}
_handlePWMEvent channel:0 payload:{"<period_scale":0}
_handlePWMEvent channel:0 payload:{"<zero_latch":false}
GOOD CASE (wpilib-ws-robot started first, wpilib and hal second):
Successfully connected
_handlePWMEvent channel:1 payload:{"<init":false}
_handlePWMEvent channel:1 payload:{"<speed":0}
_handlePWMEvent channel:1 payload:{"<position":0}
_handlePWMEvent channel:1 payload:{"<raw":0}
_handlePWMEvent channel:1 payload:{"<period_scale":0}
_handlePWMEvent channel:1 payload:{"<zero_latch":false}
_handlePWMEvent channel:0 payload:{"<init":false}
_handlePWMEvent channel:0 payload:{"<speed":0}
_handlePWMEvent channel:0 payload:{"<position":0}
_handlePWMEvent channel:0 payload:{"<raw":0}
_handlePWMEvent channel:0 payload:{"<period_scale":0}
_handlePWMEvent channel:0 payload:{"<zero_latch":false}
_handlePWMEvent channel:0 payload:{"<init":true}
_handlePWMEvent channel:0 payload:{"<zero_latch":true}
_handlePWMEvent channel:0 payload:{"<zero_latch":false}
_handlePWMEvent channel:1 payload:{"<init":true}
_handlePWMEvent channel:1 payload:{"<zero_latch":true}
_handlePWMEvent channel:1 payload:{"<zero_latch":false}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.