Skip to content

Commit

Permalink
Merge commit '2f66d574d2abe615c3ef59c1c774bdb0a32a1de7' into refactor…
Browse files Browse the repository at this point in the history
…_calibratableusbcamera
  • Loading branch information
pascalzauberzeug committed Sep 9, 2024
2 parents b0e65c6 + 2f66d57 commit 4e9c914
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
3 changes: 2 additions & 1 deletion config/f15_config_f15/robotbrain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
configuration = {'robot_brain': {
'flash_params': ['orin', 'v05', 'nand']
'flash_params': ['orin', 'v05', 'nand'],
'enable_esp_on_startup':False,
}}
2 changes: 1 addition & 1 deletion field_friend/hardware/axis_D1.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def stop(self):

async def move_to(self, position: float, speed: int | None = None) -> None:
if self.is_referenced:
await self.robot_brain.send(f'{self.name}_motor.profile_position({self.compute_steps(position)});')
await self.robot_brain.send(f'{self.name}_motor.profile_position({self._compute_steps(position)});')
if not self.is_referenced:
self.log.error(f'AxisD1 {self.name} is not refernced')
return
Expand Down
5 changes: 4 additions & 1 deletion field_friend/hardware/field_friend_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def __init__(self) -> None:
raise NotImplementedError(f'Unknown FieldFriend implement: {implement}')

communication = rosys.hardware.SerialCommunication()
robot_brain = rosys.hardware.RobotBrain(communication)
if 'enable_esp_on_startup' in config_robotbrain['robot_brain']:
robot_brain = rosys.hardware.RobotBrain(communication,enable_esp_on_startup=config_robotbrain['robot_brain']['enable_esp_on_startup'])
else:
robot_brain = rosys.hardware.RobotBrain(communication)
robot_brain.lizard_firmware.flash_params += config_robotbrain['robot_brain']['flash_params']
bluetooth = rosys.hardware.BluetoothHardware(robot_brain,
name=config_hardware['bluetooth']['name'],
Expand Down
6 changes: 3 additions & 3 deletions field_friend/hardware/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def __init__(self, robot_brain: rosys.hardware.RobotBrain, *,
for name in estop.pins:
lizard_code += f'when estop_{name}.level == 0 then stop(); end\n'
if isinstance(bumper, rosys.hardware.BumperHardware):
lizard_code += 'when ' + \
' or '.join(f'{bumper.name}_{pin}.level == 1' for pin in bumper.pins) + \
f' then {wheels.name}.off(); end\n'
for name in bumper.pins:
lizard_code += f'bumper_{name}.level = 0\n'
lizard_code += f'when bumper_{name}.level == 1 then stop(); end\n'

# implement stop call for "ground check" reference sensors
if isinstance(y_axis, ChainAxisHardware):
Expand Down
22 changes: 11 additions & 11 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 All @@ -219,8 +219,8 @@ def build_svg_for_implement(self) -> str:
def build_svg_for_plant_provider(self) -> str:
if self.camera is None or self.camera.calibration is None:
return ''
position = rosys.geometry.Point(x=self.camera.calibration.extrinsics.translation[0],
y=self.camera.calibration.extrinsics.translation[1])
position = rosys.geometry.Point3d(x=self.camera.calibration.extrinsics.translation[0],
y=self.camera.calibration.extrinsics.translation[1])
svg = ''
for plant in self.plant_provider.get_relevant_weeds(position):
position_3d = rosys.geometry.Point3d(x=plant.position.x, y=plant.position.y, z=0)
Expand Down
2 changes: 1 addition & 1 deletion field_friend/interface/components/plant_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, plant_provider: PlantProvider, weed_category_names: list[str]
self.plant_provider.PLANTS_CHANGED.register_ui(self.update)

def update(self) -> None:
origin = rosys.geometry.Point(x=0, y=0)
origin = rosys.geometry.Point3d(x=0, y=0, z=0)
in_world = {p.id: p for p in
self.plant_provider.get_relevant_weeds(origin, max_distance=1000) +
self.plant_provider.get_relevant_crops(origin, max_distance=1000)}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ geopy
shapely
fiona
geopandas
rosys == v0.15.1
rosys == v0.16.1
uvicorn == 0.28.1

0 comments on commit 4e9c914

Please sign in to comment.