Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openscan_firmware/config/endstop.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ class EndstopConfig(BaseModel):

pull_up: Optional[bool] = Field(True, description="Whether to use a pull-up resistor")
bounce_time: Optional[float] = Field(0.005, description="Debounce time for the button in seconds")
active_high: Optional[bool] = Field(False, description="Useful for normally closed switches")
3 changes: 2 additions & 1 deletion openscan_firmware/controllers/hardware/endstops.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ def get_status(self) -> dict:
Returns:
dict: A dictionary containing the status of the endstop.
"""
pressed = is_button_pressed(self.settings.pin)
return {"assigned_motor": self.settings.motor_name,
"position": self.settings.angular_position,
"pin": self.settings.pin,
"is_pressed": not is_button_pressed(self.settings.pin)}
"is_pressed": pressed if self.settings.active_high else (not pressed)}


async def _move_back_task(self):
Expand Down
23 changes: 22 additions & 1 deletion openscan_firmware/controllers/hardware/motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,27 @@ async def _move_to_target_angle(self, target_angle: float) -> None:
logger.debug(f"Motor {self.model.name} will move {step_count} steps.")
await self._execute_movement(step_count, target_angle)

async def move_to_endstop(self) -> None:
"""Internal method to move motor to endstop.

Args:
none """

if self.endstop is None:
return

logger.debug(f"Will move motor {self.model.name} to endstop")

spr = self.settings.steps_per_rotation
direction = self.settings.direction

# Some high count degrees, rotor could be in a weird position
degrees_to_move = 270

step_count = int(degrees_to_move * spr / 360) * direction
logger.debug(f"Motor {self.model.name} will move {step_count} steps.")
await self._execute_movement(step_count, 0.0)

def _pre_calculate_step_times(self, steps: int, min_interval=0.0001) -> List[float]:
"""
Pre-calculate the exact time for each step in the movement.
Expand Down Expand Up @@ -521,4 +542,4 @@ async def move_to_point(point: PolarPoint3D):
rotor.move_to(point.theta)
)

logger.debug(f"Moved to {point}")
logger.debug(f"Moved to {point}")
4 changes: 3 additions & 1 deletion openscan_firmware/models/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
class ScannerModel(Enum):
CLASSIC = "classic"
MINI = "mini"
CUSTOM = "custom"

class ScannerShield(Enum):
GREENSHIELD = "greenshield"
BLACKSHIELD = "blackshield"
CUSTOM = "custom"

class ScannerDevice(BaseModel):
name: str
Expand All @@ -25,4 +27,4 @@ class ScannerDevice(BaseModel):
lights: dict[str, Light]
endstops: Optional[dict[str, Endstop]]

initialized: bool
initialized: bool
4 changes: 2 additions & 2 deletions openscan_firmware/routers/next/motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def move_motor_to_home_position(motor_name: str):
if controller.endstop and not controller.is_busy():
# Trigger Endstop
controller.model.angle = 0
await controller.move_degrees(140)
await controller.move_to_endstop()
# Wait for Endstop and move motor to home position
await asyncio.sleep(3)
await controller.move_to(90)
Expand All @@ -164,4 +164,4 @@ async def move_motor_to_home_position(motor_name: str):
resource_name="motor_name",
get_controller=get_motor_controller,
settings_model=MotorConfig
)
)
47 changes: 47 additions & 0 deletions settings/device/default_miciomax.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "OpenScan.eu MicioMax",
"model": "custom",
"shield": "custom",
"cameras": {},
"motors": {
"rotor": {
"direction_pin": 5,
"enable_pin": 0,
"step_pin": 6,
"acceleration": 20000,
"max_speed": 5000,
"direction": 1,
"steps_per_rotation": 122880,
"min_angle": 13,
"max_angle": 180
},
"turntable": {
"direction_pin": 9,
"enable_pin": 10,
"step_pin": 11,
"acceleration": 5000,
"max_speed": 5000,
"direction": 1,
"steps_per_rotation": 6400
}
},
"lights": {
"Openscan.eu Ringlight": {
"pins": [12],
"pwm_support": true
}
},
"endstops": {
"rotor-endstop": {
"name": "rotor-endstop",
"settings": {
"pin": 27,
"angular_position": 165.0,
"motor_name": "rotor",
"pull_up": true,
"bounce_time": 0.005,
"active_high": true
}
}
}
}