Guest User

ESC example script

a guest
Mar 29th, 2021
19
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -----------------------------------------
  2. # Imports
  3. # -----------------------------------------
  4. import os
  5. import time
  6. os.system ("sudo pigpiod")
  7. time.sleep(1)
  8. import pigpio
  9.  
  10. # -----------------------------------------
  11. # Constant values
  12. # -----------------------------------------
  13. # Gpio pins
  14. MOTOR_1=24 # Right motor
  15. MOTOR_2=27 # Left motor
  16. MOTOR_3=20 # Right-Up motor
  17. MOTOR_4=5 # Left-Up motor
  18.  
  19. # PWM values for the gio pins
  20. MAX_VALUE = 1900 # ESC's max value
  21. ZERO_VALUE = 1500 #ESC's zero value
  22. MIN_VALUE = 1100 #ESC's min value
  23.  
  24. # -----------------------------------------
  25. # Initialization
  26. # -----------------------------------------
  27. pi = pigpio.pi();
  28.  
  29. pi.set_servo_pulsewidth(MOTOR_1, 0)
  30. pi.set_servo_pulsewidth(MOTOR_2, 0)
  31. pi.set_servo_pulsewidth(MOTOR_3, 0)
  32. pi.set_servo_pulsewidth(MOTOR_4, 0)
  33. time.sleep(1)
  34. # 1500 sets the motor speeds off
  35. pi.set_servo_pulsewidth(MOTOR_1, ZERO_VALUE)
  36. pi.set_servo_pulsewidth(MOTOR_2, ZERO_VALUE)
  37. pi.set_servo_pulsewidth(MOTOR_3, ZERO_VALUE)
  38. pi.set_servo_pulsewidth(MOTOR_4, ZERO_VALUE)
  39.  
  40. # -----------------------------------------
  41. # Method Definitions
  42. # -----------------------------------------
  43.  
  44. def motor1_go(inp):
  45. pi.set_servo_pulsewidth(MOTOR_1,inp)
  46.  
  47. def motor2_go(inp):
  48. pi.set_servo_pulsewidth(MOTOR_2,inp)
  49.  
  50. def motor3_go(inp):
  51. pi.set_servo_pulsewidth(MOTOR_3,inp)
  52.  
  53. def motor4_go(inp):
  54. pi.set_servo_pulsewidth(MOTOR_4,inp)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×