Skip to content

Commit

Permalink
Fix implement projection (#163)
Browse files Browse the repository at this point in the history
* fix implement projection

* cleanup

* use new Pose3d -> Point3d property

* cleanup
  • Loading branch information
pascalzauberzeug authored Sep 9, 2024
1 parent 2a15b61 commit 2f66d57
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions field_friend/interface/components/camera_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from field_friend.automations.implements.weeding_implement import WeedingImplement

from ...automations import PlantLocator, Puncher
from ...hardware import Axis, FieldFriend, FlashlightPWM, FlashlightPWMV2, Tornado
from ...hardware import Axis, FlashlightPWM, FlashlightPWMV2, Tornado
from .calibration_dialog import calibration_dialog

if TYPE_CHECKING:
Expand Down Expand Up @@ -126,8 +126,7 @@ def update_content(self) -> None:
if image and image.detections:
svg += self.to_svg(image.detections)
svg += self.build_svg_for_plant_provider()
# TODO: fix in later PR
# svg += self.build_svg_for_implement()
svg += self.build_svg_for_implement()
self.image_view.set_content(svg)

def on_mouse_move(self, e: MouseEventArguments):
Expand Down Expand Up @@ -196,15 +195,16 @@ def to_svg(self, detections: rosys.vision.Detections) -> str:
def build_svg_for_implement(self) -> str:
if not isinstance(self.system.current_implement, WeedingImplement) or self.camera is None or self.camera.calibration is None:
return ''
tool_3d = self.odometer.prediction.point_3d() + \
rosys.geometry.Point3d(x=self.field_friend.WORK_X, y=self.field_friend.y_axis.position, z=0)
tool_3d = rosys.geometry.Pose3d(x=self.field_friend.WORK_X, y=self.field_friend.y_axis.position, z=0).in_frame(
self.odometer.prediction_frame).resolve().point_3d
tool_2d = self.camera.calibration.project_to_image(tool_3d) / self.shrink_factor
svg = f'<circle cx="{int(tool_2d.x)}" cy="{int(tool_2d.y)}" r="10" fill="black"/>'
min_tool_3d = self.odometer.prediction.point_3d() + \
rosys.geometry.Point3d(x=self.field_friend.WORK_X, y=self.field_friend.y_axis.min_position, z=0)

min_tool_3d = rosys.geometry.Pose3d(x=self.field_friend.WORK_X, y=self.field_friend.y_axis.min_position, z=0).in_frame(
self.odometer.prediction_frame).resolve().point_3d
min_tool_2d = self.camera.calibration.project_to_image(min_tool_3d) / self.shrink_factor
max_tool_3d = self.odometer.prediction.point_3d() + \
rosys.geometry.Point3d(x=self.field_friend.WORK_X, y=self.field_friend.y_axis.max_position, z=0)
max_tool_3d = rosys.geometry.Pose3d(x=self.field_friend.WORK_X, y=self.field_friend.y_axis.max_position, z=0).in_frame(
self.odometer.prediction_frame).resolve().point_3d
max_tool_2d = self.camera.calibration.project_to_image(max_tool_3d) / self.shrink_factor
svg += f'<line x1="{int(min_tool_2d.x)}" y1="{int(min_tool_2d.y)}" x2="{int(max_tool_2d.x)}" y2="{int(max_tool_2d.y)}" stroke="black" stroke-width="2" />'
if self.show_weeds_to_handle:
Expand Down

0 comments on commit 2f66d57

Please sign in to comment.