Commit Graph

306 Commits

Author SHA1 Message Date
Peter Johnson
bc80c55353 [hal] Add SimValue reset() function (#3064)
This enables correct behavior for resetting incremental sensor values like
encoder counts or gyro accumulated angle with WebSockets.
2021-01-12 00:38:58 -08:00
CoolSpy3
e620bd4d3f [doc] Add machine-readable websocket specification (#3059)
Co-authored-by: Vasista Vovveti <vasistavovveti@gmail.com>
2021-01-09 23:24:57 -08:00
Peter Johnson
78147aa342 [sim] GUI: Fix Keyboard Joystick (#3052)
This was broken by #3010.

Also fix a few unknown key cases and a nullptr return that could cause a crash.
2021-01-05 17:55:11 -08:00
Peter Johnson
f5e0fc3e9a Finish clang-tidy cleanups (#3003)
* Add .clang-tidy configuration.
* A separate .clang-tidy is used for hal includes to suppress modernize-use-using
  (as these are C headers).
* Add NOLINT where necessary for a clean run.
* Add clang-tidy job to lint-format workflow.  This workflow is now only run on PRs.
  To reduce runtime, clang-tidy is only run on files changed in the PR.

Two wpilibc changes; both are unlikely to break user code:
* BuiltInAccelerometer: Make SetRange() final
* Counter: Make SetMaxPeriod() final

After these cleanups, the only file that does not run cleanly is
cscore_raw_cv.h due to it not being standalone.
2021-01-01 10:27:49 -08:00
Peter Johnson
d741101fe3 [sim] Revert accidental commit of WSProvider_PDP.h (#3027) 2021-01-01 00:44:31 -08:00
Peter Johnson
921a733911 [sim] Add WS providers for AddressableLED, PCM, and Solenoid (#3026)
Co-authored-by: PJ Reiniger <pj.reiniger@gmail.com>
2020-12-31 20:34:34 -08:00
Peter Johnson
b7e46c558f Include .h from .inc/.inl files (NFC) (#3017)
This helps both IDEs and linting tools.

Also add some missing braces.
2020-12-31 11:26:53 -08:00
Austin Shalit
65b2359b27 [build] Add spotless for other files (#3007)
Adds spotless formatting for Gradle, xml, md, and gitignore files.

yml linting is not performed as it requires a dependency on npm.
2020-12-30 16:17:20 -08:00
Peter Johnson
fccf86532f [sim] DriverStationGui: Fix two bugs (#3010)
- Slicing of GlfwKeyboardJoystick
- Potential null pointer deref
2020-12-30 11:37:54 -08:00
Peter Johnson
1857417601 [sim] WSProvider_Joystick: Fix off-by-1 in incoming buttons (#3011) 2020-12-30 11:37:20 -08:00
Peter Johnson
c97c6dc065 clang-tidy: google-readability-casting (NFC) 2020-12-29 14:26:19 -08:00
Peter Johnson
32fa97d68d clang-tidy: modernize-use-nullptr (NFC) 2020-12-29 14:26:19 -08:00
Peter Johnson
aee4603269 clang-tidy: modernize-pass-by-value 2020-12-29 14:26:19 -08:00
Peter Johnson
67e03e625d clang-tidy: modernize-use-equals-default 2020-12-29 14:26:19 -08:00
Peter Johnson
d11a3a6380 clang-tidy: modernize-use-override (NFC)
Add NOLINT to CommandTestBase due to gmock not adding "override" keyword,
which causes warnings on clang.
2020-12-29 14:26:19 -08:00
Peter Johnson
2aed432b4b Add braces to C++ single-line loops and conditionals (NFC) (#2973)
This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
2020-12-28 12:58:06 -08:00
Peter Johnson
8f1f64ffb6 Remove year from file copyright message (NFC) (#2972)
Also update copyright to include "and other WPILib contributors" and clarify
license referral language to not be restricted to FIRST teams.
2020-12-26 14:12:05 -08:00
Peter Johnson
f9d492f4b1 [sim] GUI: Show "Other Devices" window by default (#2961) 2020-12-24 12:24:36 -08:00
Peter Johnson
240c629cda [sim] Try to guess "Map Gamepad" setting (#2960)
Looks to see if the joystick name starts with "Xbox" or contains "pad".
2020-12-23 20:38:28 -08:00
Peter Johnson
10b396b4c2 [sim] Various WebSockets fixes and enhancements (#2952)
This is a breaking change to the WebSockets layer to align it with
recent specification documentation work.

To support this, HAL SimValue changed readonly to a direction enum.
This allows specifying bidirectional in addition to input and output.

The SimValue change is specifically designed to avoid API and ABI breakage.
This is completely transparent in C++; in Java a new callback class was added,
and the old readonly functions have been marked deprecated.

A new SimValue creation function for enums allows specifying double values
for each enum value, not just strings.  This allows mapping enum values to
doubles in the WebSockets layer.

A ":" in the SimDevice name now maps it to different WebSocket types (e.g.
"Accel:Name" becomes type "Accel", device "Name").  The type is hidden
in the GUI.

Other WebSockets changes:
* Implemented match_time and game_data
* Added joystick rumble data
* Added builtin accelerometer support
* SimValue enums are mapped to string and double value on WS interface
* Added WebSockets protocol specification
* Added READMEs
2020-12-23 15:54:11 -08:00
Tyler Veness
20fbb5c63b [sim] Fix stringop truncation warning from GCC 10 (#2945)
If the strncpy() bound is equal to the destination size and the source
string is longer than 256 bytes, strncpy() won't write a null terminator
for the destination string.
2020-12-17 21:51:57 -08:00
Peter Johnson
1ba0a2cedd [sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.

Default keyboard mappings:

    Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
    Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
    Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn

Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
Peter Johnson
00b9ae77f9 [sim] Change default WS port number to 3300 (#2932) 2020-12-10 20:39:14 -08:00
Peter Johnson
f78d1d4340 [sim] Process WS Encoder reset internally (#2927)
Currently, Encoder.reset() must make a round trip to the sensor and back
in order for the count to be updated for the user program.  As the sim layer
also resets the internal encoder count, this creates a race condition (a WS
message with a new count can be "in flight" during a reset and update the
count).

This changes the WS layer to not put reset on the wire, but instead keep an
offset count internal to the robot program.  The value on the wire is not
reset, but rather all sends and receives are adjusted as necessary to the
internal robot count.

This approach is straightforward, but does result in the value on the wire
not matching the value in the user program.  A future improvement will fix
this, but this change fixes the immediate race condition problem.
2020-12-10 20:30:12 -08:00
Peter Johnson
125af556ce [simulation] Fix halsim_gui ntcore and wpiutil deps (#2908)
They were being linked out of order, so ntcore wasn't being linked.
2020-12-04 23:30:17 -08:00
Peter Johnson
2a5ca77454 [glass] Add glass: an application for display of robot data
This reuses many pieces of the current simulation GUI.  The common pieces have
been refactored into the libglass library.

The libglass library is designed to be usable for other standalone data
visualization applications (e.g. viewing data logs).

The name "glass" comes from "glass cockpit", as the application features
several multi-function displays that can be adjusted to display robot
information as needed.
2020-12-04 00:36:55 -08:00
Prateek Machiraju
cc1d86ba63 [sim] Add title to simulator GUI window (#2888) 2020-11-26 11:46:14 -08:00
Dean Brettle
467258e050 [sim] GUI: Add option to not zero disconnected joysticks (#2876)
This allows team sim code to set the joystick values and not have them overwritten by the GUI.
2020-11-23 19:46:27 -08:00
Vasista Vovveti
0170977914 [build] CMake: build sim extensions as shared libs (#2866)
This builds sim extensions as dylib's instead of so's on macOS.
2020-11-15 22:50:30 -08:00
Peter Johnson
47c59859ee [sim] Make SimDevice callbacks synchronous (#2861)
Asynchronous callbacks are more efficient but pose synchronization challenges;
other sim callbacks are synchronous but SimDevice ones were not.
2020-11-14 21:04:51 -08:00
Prateek Machiraju
f24f282442 [build] Disable Gazebo builds when -PmakeSim is not set (#2810) 2020-11-09 11:37:10 -05:00
Peter Johnson
4422904a2e [build] Add WITH_GUI cmake option 2020-10-23 07:13:01 -07:00
Peter Johnson
b66fcdb3f7 [sim] Fix Field2D GUI crash when collapsed (#2786)
Collapsed windows result in a vertical content size of 0.
2020-10-19 22:03:06 -07:00
Peter Johnson
c3b3fb8b74 [sim] Change StepTiming to wait for notifiers (#2603)
Old behavior is available via StepTimingAsync.

This makes it significantly easier to use simulation timing with notifiers.

Also update tests to use simulation framework.  This also speeds up the
timing-dependent tests by using simulation timing.  ResourceLock is used
in the Java tests to prevent parallel execution.

While we're here, tweak HAL Notifier implementation:
- Use wait_for instead of wait_until in WaitForNotifierAlarm
- Check for triggerTime = UINT64_MAX in UpdateNotifierAlarm
2020-09-27 13:27:53 -07:00
Prateek Machiraju
0503225928 [build] CMake: Fix Metal linking on macOS (#2725) 2020-09-20 09:31:20 -07:00
Peter Johnson
1ae8da3b3f [wpigui] Move portable-file-dialogs.h to wpigui and upgrade it (#2704)
Also split source and implementation to avoid platform headers in header.
2020-09-12 21:15:02 -07:00
Peter Johnson
5e54e13140 [sim] Ignore incoming websocket DS/Joystick when real DS connected 2020-09-04 16:26:46 -07:00
Peter Johnson
8f87c56312 [sim] Automatically turn off GUI DS when real DS connected 2020-09-04 16:26:46 -07:00
Peter Johnson
1b18560e90 [sim] ds_socket: Remove iostream 2020-09-04 16:26:46 -07:00
Peter Johnson
f86a5f9b09 [sim] WebSockets: don't override HAL_Main
Also clean up some other implementation aspects for cleaner shutdown and
reduce peak memory allocation.
2020-09-04 16:26:09 -07:00
Peter Johnson
1593eb4d47 [sim] Add plotting to simulation GUI 2020-09-02 21:13:38 -07:00
Peter Johnson
70ba92f917 [sim] GUI: Show DS info even when GUI DS disabled 2020-09-02 21:13:38 -07:00
Peter Johnson
6a1e5385e5 [sim] WS: Don't call virtual function from destructor 2020-09-01 22:54:05 -07:00
Peter Johnson
63487dca76 [sim] Fix WS blank device messages (e.g. DriverStation) 2020-09-01 22:54:05 -07:00
sciencewhiz
3e41d92c18 [wpilib] Use misspell to fix spelling errors (NFC) (#2674) 2020-08-31 00:33:11 -07:00
Peter Johnson
b83709b269 [wpigui] Add GetDistSquared and MaxFit functions
These utility functions were moved from halsim_gui.
2020-08-30 06:48:52 -07:00
Peter Johnson
781afaa852 [wpigui] Refactor texture handling
The platform-specific code now only has create, update, and delete texture.
Image reading functions have been moved to common code.

Also add pixel data functions and image data functions in addition to image
file loading.
2020-08-30 06:48:52 -07:00
Peter Johnson
c0de98f9f2 [sim] Fix GUI scaling of window sizes (#2668)
Also tweak initial sizes, positions, and visibility.
2020-08-29 15:07:12 -07:00
Peter Johnson
5d1220e629 [sim] Use wpigui for simulator GUI 2020-08-27 21:05:17 -07:00
Zhiquan Yeo
932bfcf374 [sim] Add WebSocket extension (client/server) (#2589)
This allows access to HAL-level simulation data via a WebSocket connection.

The server additionally serves local files.

The following environment variables can be used for configuration:
HALSIMWS_USERROOT (server) - local directory to use for file serving for /user/ URIs, defaults to ./sim/user
HALSIMWS_SYSROOT (server) - local directory to use for file serving for all other URIs, defaults to ./sim
HALSIMWS_URI (client or server) - WebSocket URI, defaults to /wpilibws
HALSIMWS_PORT (client or server) - port number, defaults to 8080
HALSIMWS_HOST (client) - host to connect to, defaults to localhost

Co-authored-by: Zhiquan Yeo <zyeo8@bloomberg.net>
Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
Co-authored-by: jpokornyiii <jpokornyiii@gmail.com>
2020-08-19 22:14:03 -07:00