Merge commit '7c1ae250acb4120322b01a666993ed63c795ef21' into master
Update flatbuffers to latest master.
This adds an upstream flatbuffer_ts_library rule and changes the
typescript codegen, so ends up touching every typescript file we have
that uses flatbuffers. But it does clean up some of the hacks we had to
make to get that to work.
Had to hack the flatbuffer_ts_library a bit because I forgot to make
imports work nicely for cross-repo things.
And of course, the original motivation for this is that it gives us
proper handling of transitive dependencies for
flatbuffer_cc_library, if we start using the deps attribute!
Had to modify the codegen for the new declaration_file attribute in
flatbuffer schemas to make it just be the filename rather than including
the path. Modifying that to make it use a workspace-relative path was
looking obnoxious. It's definitely feasible, but since we don't actually
need that attribute, just make it be a filename for now.
Change-Id: I523a758cafa512fa2a686c9705d23337a26798ca
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/y2020/control_loops/drivetrain/BUILD b/y2020/control_loops/drivetrain/BUILD
index f4915da..1bbe55e 100644
--- a/y2020/control_loops/drivetrain/BUILD
+++ b/y2020/control_loops/drivetrain/BUILD
@@ -227,6 +227,7 @@
"//aos/network/www:plotter",
"//aos/network/www:proxy",
"//aos/network/www:reflection_ts",
+ "@com_github_google_flatbuffers//reflection:reflection_ts_fbs",
"@com_github_google_flatbuffers//ts:flatbuffers_ts",
],
)
diff --git a/y2020/control_loops/drivetrain/localizer_plotter.ts b/y2020/control_loops/drivetrain/localizer_plotter.ts
index 86465a5..9fe80de 100644
--- a/y2020/control_loops/drivetrain/localizer_plotter.ts
+++ b/y2020/control_loops/drivetrain/localizer_plotter.ts
@@ -1,15 +1,12 @@
// Provides a plot for debugging robot state-related issues.
import {AosPlotter} from 'org_frc971/aos/network/www/aos_plotter';
-import * as proxy from 'org_frc971/aos/network/www/proxy';
-import * as configuration from 'org_frc971/aos/configuration_generated';
+import {Connection} from 'org_frc971/aos/network/www/proxy';
import {BLUE, BROWN, CYAN, GREEN, PINK, RED, WHITE} from 'org_frc971/aos/network/www/colors';
import {MessageHandler, TimestampedMessage} from 'org_frc971/aos/network/www/aos_plotter';
import {Point} from 'org_frc971/aos/network/www/plotter';
import {Table} from 'org_frc971/aos/network/www/reflection';
-import {ByteBuffer} from 'org_frc971/external/com_github_google_flatbuffers/ts/byte-buffer';
-
-import Connection = proxy.Connection;
-import Schema = configuration.reflection.Schema;
+import {ByteBuffer} from 'flatbuffers';
+import {Schema} from 'org_frc971/external/com_github_google_flatbuffers/reflection/reflection_generated';
const TIME = AosPlotter.TIME;
diff --git a/y2020/control_loops/superstructure/BUILD b/y2020/control_loops/superstructure/BUILD
index 9fa5969..822e7bb 100644
--- a/y2020/control_loops/superstructure/BUILD
+++ b/y2020/control_loops/superstructure/BUILD
@@ -30,11 +30,11 @@
srcs = [
"superstructure_status.fbs",
],
- includes = [
- "//frc971/control_loops:control_loops_fbs_includes",
- "//frc971/control_loops:profiled_subsystem_fbs_includes",
- ],
target_compatible_with = ["@platforms//os:linux"],
+ deps = [
+ "//frc971/control_loops:control_loops_ts_fbs",
+ "//frc971/control_loops:profiled_subsystem_ts_fbs",
+ ],
)
flatbuffer_cc_library(
@@ -146,6 +146,7 @@
"//aos/network/www:plotter",
"//aos/network/www:proxy",
"//aos/network/www:reflection_ts",
+ "@com_github_google_flatbuffers//reflection:reflection_ts_fbs",
"@com_github_google_flatbuffers//ts:flatbuffers_ts",
],
)
diff --git a/y2020/control_loops/superstructure/turret_plotter.ts b/y2020/control_loops/superstructure/turret_plotter.ts
index 488aed9..2c3fb01 100644
--- a/y2020/control_loops/superstructure/turret_plotter.ts
+++ b/y2020/control_loops/superstructure/turret_plotter.ts
@@ -6,11 +6,10 @@
import {MessageHandler, TimestampedMessage} from 'org_frc971/aos/network/www/aos_plotter';
import {Point} from 'org_frc971/aos/network/www/plotter';
import {Table} from 'org_frc971/aos/network/www/reflection';
-import {ByteBuffer} from 'org_frc971/external/com_github_google_flatbuffers/ts/byte-buffer';
-import {Long} from 'org_frc971/external/com_github_google_flatbuffers/ts/long';
+import {ByteBuffer} from 'flatbuffers';
+import {Schema} from 'org_frc971/external/com_github_google_flatbuffers/reflection/reflection_generated';
import Connection = proxy.Connection;
-import Schema = configuration.reflection.Schema;
const TIME = AosPlotter.TIME;
@@ -20,7 +19,7 @@
constructor(private readonly schema: Schema) {
super(schema);
}
- private readScalar(table: Table, fieldName: string): number|Long|null {
+ private readScalar(table: Table, fieldName: string): number|BigInt|null {
return this.parser.readScalar(table, fieldName);
}
diff --git a/y2020/vision/sift/demo_sift_training.py b/y2020/vision/sift/demo_sift_training.py
index e8d3521..67874c9 100644
--- a/y2020/vision/sift/demo_sift_training.py
+++ b/y2020/vision/sift/demo_sift_training.py
@@ -28,7 +28,7 @@
for n in reversed(descriptor):
assert n == round(n)
fbb.PrependUint8(int(round(n)))
- descriptor_vector = fbb.EndVector(len(descriptor))
+ descriptor_vector = fbb.EndVector()
Feature.FeatureStart(fbb)
@@ -45,7 +45,7 @@
TrainingImage.TrainingImageStartFeaturesVector(fbb, len(features_vector))
for feature in reversed(features_vector):
fbb.PrependUOffsetTRelative(feature)
- features_vector_table = fbb.EndVector(len(features_vector))
+ features_vector_table = fbb.EndVector()
TrainingImage.TrainingImageStart(fbb)
TrainingImage.TrainingImageAddFeatures(fbb, features_vector_table)
@@ -54,7 +54,7 @@
TrainingData.TrainingDataStartImagesVector(fbb, 1)
fbb.PrependUOffsetTRelative(training_image_offset)
- images_offset = fbb.EndVector(1)
+ images_offset = fbb.EndVector()
TrainingData.TrainingDataStart(fbb)
TrainingData.TrainingDataAddImages(fbb, images_offset)
diff --git a/y2020/vision/tools/python_code/load_sift_training.py b/y2020/vision/tools/python_code/load_sift_training.py
index 0dbcb98..0841938 100644
--- a/y2020/vision/tools/python_code/load_sift_training.py
+++ b/y2020/vision/tools/python_code/load_sift_training.py
@@ -38,7 +38,7 @@
TransformationMatrix.TransformationMatrixStartDataVector(fbb, len(values))
for n in reversed(values):
fbb.PrependFloat32(n)
- list_offset = fbb.EndVector(len(values))
+ list_offset = fbb.EndVector()
TransformationMatrix.TransformationMatrixStart(fbb)
TransformationMatrix.TransformationMatrixAddData(fbb, list_offset)
@@ -91,7 +91,7 @@
for n in reversed(descriptor):
assert n == round(n)
fbb.PrependUint8(int(round(n)))
- descriptor_vector = fbb.EndVector(len(descriptor))
+ descriptor_vector = fbb.EndVector()
# Add all the components to the each Feature
Feature.FeatureStart(fbb)
@@ -117,7 +117,7 @@
fbb, len(field_to_target_list))
for n in reversed(field_to_target_list):
fbb.PrependFloat32(n)
- field_to_target_offset = fbb.EndVector(len(field_to_target_list))
+ field_to_target_offset = fbb.EndVector()
TransformationMatrix.TransformationMatrixStart(fbb)
TransformationMatrix.TransformationMatrixAddData(
@@ -130,7 +130,7 @@
len(features_vector))
for feature in reversed(features_vector):
fbb.PrependUOffsetTRelative(feature)
- features_vector_offset = fbb.EndVector(len(features_vector))
+ features_vector_offset = fbb.EndVector()
# Add the TrainingImage data
TrainingImage.TrainingImageStart(fbb)
@@ -149,7 +149,7 @@
TrainingData.TrainingDataStartImagesVector(fbb, len(images_vector))
for training_image in reversed(images_vector):
fbb.PrependUOffsetTRelative(training_image)
- images_vector_table = fbb.EndVector(len(images_vector))
+ images_vector_table = fbb.EndVector()
# Create camera calibration data
camera_calibration_vector = []
@@ -174,14 +174,14 @@
fbb, len(camera_int_list))
for n in reversed(camera_int_list):
fbb.PrependFloat32(n)
- intrinsics_vector = fbb.EndVector(len(camera_int_list))
+ intrinsics_vector = fbb.EndVector()
dist_coeffs_list = camera_calib.camera_int.dist_coeffs.ravel().tolist()
CameraCalibration.CameraCalibrationStartDistCoeffsVector(
fbb, len(dist_coeffs_list))
for n in reversed(dist_coeffs_list):
fbb.PrependFloat32(n)
- dist_coeffs_vector = fbb.EndVector(len(dist_coeffs_list))
+ dist_coeffs_vector = fbb.EndVector()
node_name_offset = fbb.CreateString(camera_calib.node_name)
CameraCalibration.CameraCalibrationStart(fbb)
@@ -204,8 +204,7 @@
fbb, len(camera_calibration_vector))
for camera_calibration in reversed(camera_calibration_vector):
fbb.PrependUOffsetTRelative(camera_calibration)
- camera_calibration_vector_table = fbb.EndVector(
- len(camera_calibration_vector))
+ camera_calibration_vector_table = fbb.EndVector()
# Fill out TrainingData
TrainingData.TrainingDataStart(fbb)
diff --git a/y2020/www/field_handler.ts b/y2020/www/field_handler.ts
index c1170c4..c165bcc 100644
--- a/y2020/www/field_handler.ts
+++ b/y2020/www/field_handler.ts
@@ -1,24 +1,10 @@
-import * as configuration from 'org_frc971/aos/configuration_generated';
-import * as web_proxy from 'org_frc971/aos/network/web_proxy_generated';
+import {ByteBuffer} from 'flatbuffers';
import {Connection} from 'org_frc971/aos/network/www/proxy';
import * as flatbuffers_builder from 'org_frc971/external/com_github_google_flatbuffers/ts/builder';
-import {ByteBuffer} from 'org_frc971/external/com_github_google_flatbuffers/ts/byte-buffer';
-import * as drivetrain from 'org_frc971/frc971/control_loops/drivetrain/drivetrain_status_generated';
-import * as localizer from 'org_frc971/y2020/control_loops/drivetrain/localizer_debug_generated';
-import * as ss from 'org_frc971/y2020/control_loops/superstructure/superstructure_status_generated'
-import * as sift from 'org_frc971/y2020/vision/sift/sift_generated';
-
-import DrivetrainStatus = drivetrain.frc971.control_loops.drivetrain.Status;
-import LocalizerDebug = localizer.y2020.control_loops.drivetrain.LocalizerDebug;
-import RejectionReason = localizer.y2020.control_loops.drivetrain.RejectionReason;
-import ImageMatchDebug = localizer.y2020.control_loops.drivetrain.ImageMatchDebug;
-import SuperstructureStatus = ss.y2020.control_loops.superstructure.Status;
-import FlywheelControllerStatus = ss.y2020.control_loops.superstructure.FlywheelControllerStatus;
-import ImageMatchResult = sift.frc971.vision.sift.ImageMatchResult;
-import Channel = configuration.aos.Channel;
-import SubscriberRequest = web_proxy.aos.web_proxy.SubscriberRequest;
-import ChannelRequest = web_proxy.aos.web_proxy.ChannelRequest;
-import TransferMethod = web_proxy.aos.web_proxy.TransferMethod;
+import {Status as DrivetrainStatus} from 'org_frc971/frc971/control_loops/drivetrain/drivetrain_status_generated';
+import {LocalizerDebug, RejectionReason, ImageMatchDebug} from 'org_frc971/y2020/control_loops/drivetrain/localizer_debug_generated';
+import {Status as SuperstructureStatus, FlywheelControllerStatus} from 'org_frc971/y2020/control_loops/superstructure/superstructure_status_generated'
+import {ImageMatchResult} from 'org_frc971/y2020/vision/sift/sift_generated';
import {FIELD_LENGTH, FIELD_WIDTH, FT_TO_M, IN_TO_M} from './constants';
@@ -165,9 +151,7 @@
private handleImageMatchResult(prefix: string, data: Uint8Array): void {
const fbBuffer = new ByteBuffer(data);
this.imageMatchResult.set(
- prefix,
- ImageMatchResult.getRootAsImageMatchResult(
- fbBuffer as unknown as flatbuffers.ByteBuffer));
+ prefix, ImageMatchResult.getRootAsImageMatchResult(fbBuffer));
}
private handleLocalizerDebug(data: Uint8Array): void {
@@ -175,9 +159,7 @@
const fbBuffer = new ByteBuffer(data);
this.localizerImageMatches.set(
- now,
- LocalizerDebug.getRootAsLocalizerDebug(
- fbBuffer as unknown as flatbuffers.ByteBuffer));
+ now, LocalizerDebug.getRootAsLocalizerDebug(fbBuffer));
const debug = this.localizerImageMatches.get(now);
@@ -207,14 +189,12 @@
private handleDrivetrainStatus(data: Uint8Array): void {
const fbBuffer = new ByteBuffer(data);
- this.drivetrainStatus = DrivetrainStatus.getRootAsStatus(
- fbBuffer as unknown as flatbuffers.ByteBuffer);
+ this.drivetrainStatus = DrivetrainStatus.getRootAsStatus(fbBuffer);
}
private handleSuperstructureStatus(data: Uint8Array): void {
const fbBuffer = new ByteBuffer(data);
- this.superstructureStatus = SuperstructureStatus.getRootAsStatus(
- fbBuffer as unknown as flatbuffers.ByteBuffer);
+ this.superstructureStatus = SuperstructureStatus.getRootAsStatus(fbBuffer);
}
drawField(): void {
diff --git a/y2020/www/image_handler.ts b/y2020/www/image_handler.ts
index 661100b..856ee8b 100644
--- a/y2020/www/image_handler.ts
+++ b/y2020/www/image_handler.ts
@@ -1,20 +1,8 @@
-import * as configuration from 'org_frc971/aos/configuration_generated';
+import {Channel, Configuration} from 'org_frc971/aos/configuration_generated';
import {Connection} from 'org_frc971/aos/network/www/proxy';
-import * as flatbuffers_builder from 'org_frc971/external/com_github_google_flatbuffers/ts/builder';
-import {ByteBuffer} from 'org_frc971/external/com_github_google_flatbuffers/ts/byte-buffer';
-import {Long} from 'org_frc971/external/com_github_google_flatbuffers/ts/long';
-import * as sift from 'org_frc971/y2020/vision/sift/sift_generated'
-import * as vision from 'org_frc971/frc971/vision/vision_generated';
-import * as web_proxy from 'org_frc971/aos/network/web_proxy_generated';
-
-import Channel = configuration.aos.Channel;
-import Configuration = configuration.aos.Configuration;
-import CameraImage = vision.frc971.vision.CameraImage;
-import ImageMatchResult = sift.frc971.vision.sift.ImageMatchResult;
-import Feature = sift.frc971.vision.sift.Feature;
-import SubscriberRequest = web_proxy.aos.web_proxy.SubscriberRequest;
-import ChannelRequest = web_proxy.aos.web_proxy.ChannelRequest;
-import TransferMethod = web_proxy.aos.web_proxy.TransferMethod;
+import {ByteBuffer} from 'flatbuffers';
+import {ImageMatchResult, Feature} from 'org_frc971/y2020/vision/sift/sift_generated'
+import {CameraImage} from 'org_frc971/frc971/vision/vision_generated';
export class ImageHandler {
private canvas = document.createElement('canvas');
@@ -22,9 +10,9 @@
private imageBuffer: Uint8ClampedArray|null = null;
private image: CameraImage|null = null;
- private imageTimestamp: Long|null = null;
+ private imageTimestamp: BigInt|null = null;
private result: ImageMatchResult|null = null;
- private resultTimestamp: Long|null = null;
+ private resultTimestamp: BigInt|null = null;
private width = 0;
private height = 0;
private selectedIndex = 0;
@@ -64,8 +52,7 @@
}
const fbBuffer = new ByteBuffer(data);
- this.image = CameraImage.getRootAsCameraImage(
- fbBuffer as unknown as flatbuffers.ByteBuffer);
+ this.image = CameraImage.getRootAsCameraImage(fbBuffer);
this.imageTimestamp = this.image.monotonicTimestampNs();
this.width = this.image.cols();
@@ -116,16 +103,14 @@
handleImageMetadata(data: Uint8Array): void {
console.log('got an image match result to process');
const fbBuffer = new ByteBuffer(data);
- this.result = ImageMatchResult.getRootAsImageMatchResult(
- fbBuffer as unknown as flatbuffers.ByteBuffer);
+ this.result = ImageMatchResult.getRootAsImageMatchResult(fbBuffer);
this.resultTimestamp = this.result.imageMonotonicTimestampNs();
this.draw();
}
draw(): void {
if (!this.imageTimestamp || !this.resultTimestamp ||
- this.imageTimestamp.low !== this.resultTimestamp.low ||
- this.imageTimestamp.high !== this.resultTimestamp.high) {
+ this.imageTimestamp !== this.resultTimestamp) {
// console.log('image and result do not match');
// console.log(this.imageTimestamp.low, this.resultTimestamp.low);
// console.log(this.imageTimestamp.high, this.resultTimestamp.high);