diff options
author | Matt Strapp <matt@mattstrapp.net> | 2022-04-14 14:16:57 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2022-04-14 14:17:20 -0500 |
commit | 747addc70e0f0ec34f31a50f3faa45687d065afc (patch) | |
tree | 0ea4f0ae08d69d7deac2f4105e2ee626dd05a013 /src/public | |
parent | Bump fastify/github-action-merge-dependabot from 3.0.2 to 3.1.2 (#47) (diff) | |
download | ee4511w-web-747addc70e0f0ec34f31a50f3faa45687d065afc.tar ee4511w-web-747addc70e0f0ec34f31a50f3faa45687d065afc.tar.gz ee4511w-web-747addc70e0f0ec34f31a50f3faa45687d065afc.tar.bz2 ee4511w-web-747addc70e0f0ec34f31a50f3faa45687d065afc.tar.lz ee4511w-web-747addc70e0f0ec34f31a50f3faa45687d065afc.tar.xz ee4511w-web-747addc70e0f0ec34f31a50f3faa45687d065afc.tar.zst ee4511w-web-747addc70e0f0ec34f31a50f3faa45687d065afc.zip |
Add better example
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to 'src/public')
-rw-r--r-- | src/public/example.py | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/src/public/example.py b/src/public/example.py index 7768ecf..9931460 100644 --- a/src/public/example.py +++ b/src/public/example.py @@ -1,15 +1,33 @@ -# REQUIRED IMPORT! The pendulum will NOT WORK if you do not import this. -from pendulum import System +from pendulum import System # REQUIRED import to use the inverted pendulum +from time import sleep # OPTIONAL import, needed to use the sleep function -# Initialize the system -system = System() +sys = System() # Create System object. This is REQUIRED to use the inverted pendulum. +sys.initialize() # Initialize the inverted pendulum. This is REQUIRED. The pendulum will move all the way to the left, then all the way to the right, then go to the center and pause for 1 second. -# REQUiRED! This initializes the system. -system.initialize() +ang,lin = sys.measure() # Measure the angular position of the pendulum, and the linear position of the sled. -# -# Add your code here! -# + # This example moves the inverted pendulum back and forth 10 times. +counter = 0 +while (counter < 10): # Loop 10 times -#REQUIRED! This deinitializes the system, allowing another instance to be initialized. -system.deinitialize()
\ No newline at end of file + sleep(0.2) # Sleep for 0.2 seconds + sys.torque(5) # Apply a torque of 5. The max is 80. The inverted pendulum will move the right. + + while lin < 10: # Loop while the linear position of the sled is less than 10 inches right of center. + ang,lin = sys.measure() # Measure again + sleep(0.01) # Sleep for 0.01 seconds + + sys.torque(0) # Apply a torque of 0. This will let the pendulum coast in whichever direction it was headed. It will stop shortly after. + sleep(0.6) # Sleep for 0.6 seconds. This gives the pendulum time to stop and stay idle. This isn't required. + sys.torque(-5) # Apply a torque of -5. The max is -80. This is still a torque of 5, but in the opposite direction. The pendulum moves left. + + while lin > -10: # Loop until a linear position of -10 (10 inches left of center) is measured. + ang,lin = sys.measure() + sleep(0.01) + + sys.torque(0) # Have the pendulum coast + sleep(0.1) # Sleep for 0.1 seconds + + counter += 1 # increment the counter variable + +sys.return_home() # REQUIRED function call, always return home at the end of every run. |