controllables.Piston
- class controllables.Piston(port: Optional[int] = None)
Reference to a piston part
The follow code block assumes that a piston is assigned to port
0
and aTextScreen
is assigned to port1
.from controllables import Piston, TextScreen from time import sleep piston = Piston(0) screen = TextScreen(1) #the notes to mary had a little lamb notes = [5,4,3,4, 5,5,5, 4,4,4, 5,7,7, 5,4,3,4, 5,5,5,5, 4,4,5,4, 3,] #the lengths of each note lengths = [1,1,1,1, 1,1,2, 1,1,2, 1,1,2, 1,1,1,1, 1,1,1,1, 1,1,1,1, 4] #the words for each note lyrics = ["mary", "mary", "had", "a", "little", "little", "lamb", "little", "little", "lamb", "little", "little", "lamb", "mary", "mary", "had", "a", "little", "little", "lamb", "its", "fleece", "was", "white", "as", "snow"] while True: #play each note for i in range(0,len(notes)): screen.text = lyrics[i] #move the piston the the height of the note piston.move_to(notes[i] / 8.) #hold it for it's length sleep(lengths[i]) #lift the note piston.move_to(0) sleep(.05) #rest for a measure before repeating sleep(4)
- move(power: float = 1)
Sends a signal to move the piston shaft.
power
should be set to afloat
from-1
to1
representing the proportion of max velocity at which the shaft will extend. Negative values retract the shaft instead of extending it.from controllables import Piston import time piston = Piston(0) piston.move() time.sleep(1) piston.stop()
- stop()
Stops moving the piston.
Note
This doesn’t prevent transmitters or properties from moving the piston.
from controllables import Piston import time piston = Piston(0) piston.move() time.sleep(1) piston.stop()
- move_to(position: float)
Sends a signal to move the piston shaft to the position
position
between0
and1
with0
being fully retracted and1
being fully extended.from controllables import Piston import time piston = Piston(0) #set the target position to 50% piston.move_to(.5) time.sleep(2) #release the target position piston.stop()
- position() float
A
float
from0
to1
representing how far extended the shaft is with0
being fully retracted and1
being fully extended.
- property oscillate: bool
The oscillate property of the piston avaliable in the properties tab.
- property return_to_origin: bool
The return to origin property of the piston avaliable in the properties tab.
- property max_velocity: float
The maximum velocity (in meters per second) property of the piston avaliable in the properties tab.
- property acceleration_time: float
The acceleration time (in seconds) property of the piston avaliable in the properties tab.
- property max_force: float
The maximum force (in newtons) property of the piston avaliable in the properties tab.
- name() str
Returns the user editable name of the controllable as found in the properties tab of the game.
from ports import PortReference print(PortReference(0).name())