controllables.Claw
- class controllables.Claw(port: Optional[int] = None)
Reference to a claw part.
The follow code block assumes that a claw part is assigned to port
0
.from controllables import Claw # create claw reference claw = Claw(0) while True: # wait until somthing is in our reach while not claw.can_grab(): pass # grab it claw.close() # do nothing until it breaks free while claw.is_holding(): pass
- close()
Closes the claw. If an object is between the claws mandibles, the claw will try grip onto it.
For example usage see
open()
.
- open()
Releases the close signal to a claw reference causing it to open if closed via that claw reference. If the claw is being closed via another script, reference object, or transmitter, it will remain closed.
The following example assumes that there is exactly one claw assigned to any port. It closes and opens the claw.
from controllables import Claw from time import sleep claw = Claw() while True: claw.close() sleep(.5) claw.open() sleep(1)
In the below example the claw will remain closed because it is being openned via a new reference which didn’t close it.
from controllables import Claw from time import sleep while True: Claw().close() sleep(.5) Claw().open() sleep(1)
- property max_force: float
The maximum force (in newtons) property of the claw avaliable in the properties tab.
In the below example, the property is displayed on a
TextScreen
. It assumes that exactly one screen and claw are assigned to any ports.from controllables import Claw, TextScreen screen = TextScreen() claw = Claw() while True: screen.text = f'claw.max_force: {claw.max_force: 0.0f}'
In the next example the property is set to
0
on start up. It assumes that exactly one claw is assigned to any port.from controllables import Claw Claw().max_force = 0
- can_grab() bool
Returns true when an object is between the claws mandibles.
The following example shows how to display the result of the method to a
TextScreen
. It assumes that exactly one screen and one claw are assigned to any ports. To see the effects, build a robot that can press the claw up against things to change the method’s result.from controllables import Claw, TextScreen screen = TextScreen() claw = Claw() while True: screen.text = f'claw.can_grab: {claw.can_grab()}'
- is_holding() bool
Returns
True
exactly when the claw is holding an object. In the case that the claw was holding something, but has lost its grip, returnsFalse
.The following example shows how to display the result of the method to a
TextScreen
. It assumes that exactly one screen and one claw are assigned to any ports. To see the effects, build a robot that can grab objects to change the method’s result.from controllables import Claw, TextScreen screen = TextScreen() claw = Claw() while True: screen.text = f'claw.is_holding: {claw.is_holding()}'
- is_open() bool
Returns whether the mandibles of the claw are physically apart. The claw may be opened or closed by other scripts or by transmitters, which this method can be used to detect.
The following example shows how to display the result of the method to a
TextScreen
. It assumes that exactly one screen and one claw are assigned to any ports.from controllables import Claw, TextScreen screen = TextScreen() claw = Claw() while True: screen.text = f'claw.is_open: {claw.is_open()}'
- name() str
Returns the user editable name of the controllable as found in the properties tab of the game.
The following example assumes that any controllable or sensor is assigned to port
0
and prints out its name.from ports import PortReference print(PortReference(0).name())