-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1 from illini-robomaster/roger/2023_educational
Roger's 2022 competition season implementation
- Loading branch information
Showing
15 changed files
with
869 additions
and
83 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 |
---|---|---|
@@ -1,6 +1,75 @@ | ||
import numpy as np | ||
import config | ||
import Utils | ||
|
||
class Aim: | ||
def __init__(self): | ||
pass | ||
|
||
def get_rotation(self, pred): | ||
pass | ||
def process_one(self, pred_list, enemy_team, depth_map): | ||
assert enemy_team in ['blue', 'red'] | ||
closet_pred, closet_dist = self.get_closet_pred(pred_list, enemy_team, depth_map) | ||
if closet_pred is None: | ||
return None | ||
name, confidence, bbox = closet_pred | ||
center_x, center_y, width, height = bbox | ||
|
||
# Get yaw/pitch differences in radians | ||
yaw_diff, pitch_diff = self.get_rotation_angle(center_x, center_y) | ||
|
||
calibrated_yaw_diff, calibrated_pitch_diff = self.posterior_calibration(yaw_diff, pitch_diff, closet_dist) | ||
|
||
return { | ||
'yaw_diff': calibrated_yaw_diff, | ||
'pitch_diff': calibrated_pitch_diff, | ||
'center_x': center_x, | ||
'center_y': center_y, | ||
} | ||
|
||
def posterior_calibration(self, yaw_diff, pitch_diff, distance): | ||
"""Given a set of naively estimated parameters, return calibrated parameters | ||
from a range table? | ||
Args: | ||
yaw_diff (float): yaw difference in radians | ||
pitch_diff (float): pitch difference in radians | ||
distance (float): distance to target in meters | ||
Returns: | ||
(float, float): calibrated yaw_diff, pitch_diff in radians | ||
""" | ||
if distance >= 2**16: | ||
# In this case, distance is a rough estimation from bbox size | ||
return (yaw_diff, pitch_diff) | ||
else: | ||
# In this case, distance comes from D455 stereo estimation | ||
# TODO: compute a range table | ||
return (yaw_diff, pitch_diff) | ||
|
||
def get_closet_pred(self, pred_list, enemy_team, depth_map): | ||
closet_pred = None | ||
closet_dist = None # Cloest to camera in z-axis | ||
obj_of_interest = [f"armor_{enemy_team}"] | ||
for name, conf, bbox in pred_list: | ||
# name from C++ string is in bytes; decoding is needed | ||
if isinstance(name, bytes): | ||
name_str = name.decode('utf-8') | ||
else: | ||
name_str = name | ||
if name_str not in obj_of_interest: continue | ||
cur_dist = Utils.estimate_target_depth(bbox, depth_map) | ||
if closet_pred is None: | ||
closet_pred = (name, conf, bbox) | ||
closet_dist = cur_dist | ||
else: | ||
if cur_dist < closet_dist: | ||
closet_pred = (name, conf, bbox) | ||
closet_dist = cur_dist | ||
return closet_pred, closet_dist | ||
|
||
@staticmethod | ||
def get_rotation_angle(bbox_center_x, bbox_center_y): | ||
yaw_diff = (bbox_center_x - config.IMG_CENTER_X) * (config.RGBD_CAMERA.YAW_FOV_HALF / config.IMG_CENTER_X) | ||
pitch_diff = (bbox_center_y - config.IMG_CENTER_Y) * (config.RGBD_CAMERA.PITCH_FOV_HALF / config.IMG_CENTER_Y) | ||
|
||
return yaw_diff, pitch_diff |
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
import numpy as np | ||
import pyrealsense2 as rs | ||
import Utils | ||
|
||
# TODO: make an abstract camera base class | ||
class D455_camera(object): | ||
# Camera parameters from intelrealsense.com/depth-camera/d-455/ | ||
# TODO: for better accuracy, use individual calibrated intrinsics | ||
YAW_FOV_HALF = Utils.deg_to_rad(87) / 2 | ||
PITCH_FOV_HALF = Utils.deg_to_rad(58) / 2 | ||
|
||
def __init__(self, width, height): | ||
self.width = width | ||
self.height = height | ||
|
||
self.pipeline = rs.pipeline() | ||
|
||
self.config = rs.config() | ||
self.config.enable_stream(rs.stream.depth, self.width, self.height, rs.format.z16, 30) | ||
self.config.enable_stream(rs.stream.color, self.width, self.height, rs.format.bgr8, 30) | ||
|
||
self.pipeline.start(self.config) | ||
|
||
def get_frame(self): | ||
RGBD_frame = self.pipeline.wait_for_frames() | ||
|
||
frame = np.array(RGBD_frame.get_color_frame().get_data()) # HW3 | ||
depth = np.array(RGBD_frame.get_depth_frame().get_data()) # uint16 0-65535 | ||
depth[depth == 65535] = 0 # mask ignored label to background | ||
|
||
return (frame, depth) |
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.