-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathESC.py
More file actions
42 lines (32 loc) · 1.08 KB
/
ESC.py
File metadata and controls
42 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# ESC Python program to run the ESC
import os
import time
# Launching GPIO library
os.system("sudo pigpiod")
# Will cause errors if this delays are removed
time.sleep(1)
import pigpio
class ElectronicSpeedController:
# Constructor
def __init__(self, gpio_pin_number):
self.ESC = gpio_pin_number
self.pi = pigpio.pi()
self.pi.set_servo_pulsewidth(self.ESC, 1500)
# Max and min pulse width values of ESC
self.max_value = 1900
self.min_value = 1100
self.arm()
# Function to control the speed of the motor
def control(self, speed):
if speed < self.min_value:
speed = self.min_value
elif speed > self.max_value:
speed = self.max_value
self.pi.set_servo_pulsewidth(self.ESC, speed)
# Function to arm Blue Robotics Basic ESC
def arm(self):
self.pi.set_servo_pulsewidth(self.ESC, 1500)
# Function to stop every action the Pi is performing for the ESC.
def stop(self):
self.pi.set_servo_pulsewidth(self.ESC, 1500)
self.pi.stop()