-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from truher/main
more pose estimation
- Loading branch information
Showing
20 changed files
with
556 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Intrinstic and distortion config of a camera.""" | ||
|
||
# pylint: disable=E1101,R0903 | ||
|
||
import gtsam | ||
import numpy as np | ||
|
||
from app.config.identity import Identity | ||
|
||
|
||
class CameraConfig: | ||
def __init__(self, identity: Identity) -> None: | ||
match identity: | ||
case Identity.UNKNOWN: | ||
self.camera_offset = gtsam.Pose3( | ||
gtsam.Rot3(), | ||
np.array([0, 0, 1]), | ||
) | ||
self.calib = gtsam.Cal3DS2( | ||
200.0, 200.0, 0.0, 200.0, 200.0, -0.2, 0.1, 0.0, 0.0 | ||
) | ||
case _: | ||
self.camera_offset = gtsam.Pose3( | ||
gtsam.Rot3(), | ||
np.array([0, 0, 1]), | ||
) | ||
self.calib = gtsam.Cal3DS2( | ||
200.0, 200.0, 0.0, 200.0, 200.0, -0.2, 0.1, 0.0, 0.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Tag locations.""" | ||
|
||
import math | ||
|
||
import numpy as np | ||
|
||
TAG_SIZE_M = 0.1651 | ||
HALF = TAG_SIZE_M / 2 | ||
|
||
|
||
class FieldMap: | ||
def __init__(self) -> None: | ||
# key = tag number | ||
# value = list of arrays, each array is (x, y) | ||
# TODO: make this a flat array with 8 numbers instead. | ||
self.tags: dict[int, list[np.ndarray]] = {} | ||
self.tags[0] = FieldMap.make_tag(4, 0, 1, 0) | ||
self.tags[1] = FieldMap.make_tag(2, 2, 1, math.pi / 2) | ||
|
||
def get(self, tag_id: int) -> list[np.ndarray]: | ||
"""list of corners""" | ||
return self.tags[tag_id] | ||
|
||
@staticmethod | ||
def make_tag(x, y, z, yaw) -> list[np.ndarray]: | ||
"""yaw: 'into the page' orientation. | ||
pitch and roll are always zero""" | ||
s = HALF * math.sin(yaw) | ||
c = HALF * math.cos(yaw) | ||
ll = np.array([x - s, y + c, z - HALF]) | ||
lr = np.array([x + s, y - c, z - HALF]) | ||
ur = np.array([x + s, y - c, z + HALF]) | ||
ul = np.array([x - s, y + c, z + HALF]) | ||
return [ll, lr, ur, ul] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,52 @@ | ||
"""Read measurements from Network Tables, run the | ||
smoother, and publish the results on Network Tables.""" | ||
|
||
# pylint: disable=C0301,E0611,E1101,R0903,R0914 | ||
|
||
# TODO: remove gtsam | ||
import gtsam | ||
import numpy as np | ||
from gtsam import noiseModel # type:ignore | ||
from wpimath.geometry import Pose2d | ||
|
||
from app.camera.camera_protocol import Camera | ||
from app.config.camera_config import CameraConfig | ||
from app.config.identity import Identity | ||
from app.network.network_protocol import Network | ||
from app.pose_estimator.estimate import Estimate | ||
from app.pose_estimator.field_map import FieldMap | ||
|
||
PRIOR_NOISE = noiseModel.Diagonal.Sigmas(np.array([0.3, 0.3, 0.1])) | ||
|
||
|
||
class NTEstimate: | ||
def __init__(self, net: Network) -> None: | ||
def __init__(self, field_map: FieldMap, net: Network) -> None: | ||
self.field_map = field_map | ||
self.net = net | ||
self.blip_receiver = net.get_blip25_receiver("foo") | ||
self.est = Estimate() | ||
# current estimate, used for initial value for next time | ||
# TODO: remove gtsam types | ||
self.state = gtsam.Pose2() | ||
self.est.init() | ||
prior_mean = gtsam.Pose2(0, 0, 0) | ||
self.est.add_state(0, prior_mean) | ||
self.est.prior(0, prior_mean, PRIOR_NOISE) | ||
|
||
def step(self) -> None: | ||
"""Collect any pending measurements from | ||
the network and add them to the sim.""" | ||
# TODO: read the camera identity from the blip | ||
cam = CameraConfig(Identity.UNKNOWN) | ||
sights = self.blip_receiver.get() | ||
print("sights ", sights) | ||
for sight in sights: | ||
timestamp_us = sight[0] | ||
tag_id = sight[1] | ||
blip = sight[2] | ||
pixels = blip.measurement() | ||
corners = self.field_map.get(tag_id) | ||
self.est.apriltag_for_smoothing_batch( | ||
corners, pixels, timestamp_us, cam.camera_offset, cam.calib | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.