1

I'm trying to build a quadcopter and I have one ESC, one brushless motor and one Raspberry Pi B+. I find many tutorials on internet to see how to connect these components but it doesn't work. I'm using RPi lib in Python to program. I would like to be sure about my connectics and the code I use to control the ESC. I find a tutorial who has the same components as I. (solenerotech1.wordpress.com/2013/09/09/tutorialhow-to-control-a-brushless-motor-with-raspberry-pi/)
That is how I connect the components :
https://solenerotech.files.wordpress.com/2013/09/wiring_2.jpg
and the code I try to execute :
https://docs.google.com/file/d/0B6oczzPXbM-pc2hlTjd3Uy1VSzQ/edit
But the motor doens't work. Need I setup the Raspberry to use GPIO ?
I installed RPi correctly on the Raspberry, the code don't have any errors and if this turorial is correct I have correctly connect my components. Do you see where I'm wrong ?

from motor import motor

mymotor = motor('m1', 17, simulation=False)
#where 17 is  GPIO17 = pin 11

print('***Disconnect ESC power')
print('***then press ENTER')
res = raw_input()
mymotor.start()
mymotor.setW(100)

#NOTE:the angular motor speed W can vary from 0 (min) to 100 (max)
#the scaling to pwm is done inside motor class
print('***Connect ESC Power')
print('***Wait beep-beep')

print('***then press ENTER')
res = raw_input()
mymotor.setW(0)
print('***Wait N beep for battery cell')
print('***Wait beeeeeep for ready')
print('***then press ENTER')
res = raw_input()
print ('increase > a | decrease > z | save Wh > n | set Wh > h|quit > 9')

cycling = True
try:
    while cycling:
        res = raw_input()
        if res == 'a':
            mymotor.increaseW()
        if res == 'z':
            mymotor.decreaseW()
        if res == 'n':
            mymotor.saveWh()
        if res == 'h':
            mymotor.setWh()
        if res == '9':
            cycling = False
finally:
    # shut down cleanly
    mymotor.stop()
    print ("well done!")








class motor(object):
    """Manages the currect Angular rotation
    Implements the IO interface using the RPIO lib
    __init_(self, name, pin, kv=1000, RPMMin=1, RPMMax=100, debug=True, simulation=True):
    More info on RPIO in http://pythonhosted.org/RPIO/index.html"""


    def __init__(self, name, pin, kv=1000, WMin=0, WMax=100, debug=True, simulation=True):
        self.name = name
        self.powered = False
        self.simulation = simulation
        self.__pin = pin
        self.__kv = kv
        self.setWLimits(WMin, WMax)
        self.setDebug(debug)

        self.__W = self.__WMin
        self.__Wh = 10

        try:
            from RPIO import PWM
            self.__IO = PWM.Servo()
        except ImportError:
            self.simulation = True

    def setDebug(self, debug):
        self.__debug = debug
        #if self.__debug:
            #self.__logger.setLevel(logging.DEBUG)
        #else:
            #self.__logger.setLevel(logging.WARNING)

    def getDebug(self):
        return self.__debug

    def setPin(self, pin):
        "set the pin for each motor"
        self.__pin = pin

    def setKv(self, kv):
        "set the kv for each motor"
        self.__kv = kv

    def setWLimits(self, WMin, WMax):
        "set the pin for each motor"
        if WMin < 0:
            WMin = 0
        self.__WMin = WMin
        if WMax > 100:
            WMax = 100
        self.__WMax = WMax

    def saveWh(self):
        "Save Wh = current W%"
        self.__Wh = self.__W

    def setWh(self):
        "Sets current W% =Wh"
        self.__W = self.__Wh
        self.setW(self.__W)

    def getWh(self):
        "returns current W% =Wh"
        return self.__Wh

    def start(self):
        "Run the procedure to init the PWM"
        if not self.simulation:
            try:
                from RPIO import PWM
                self.__IO = PWM.Servo()
                self.powered = True
                #TODO Decide How to manage the WMax < 100
                #to keep anyhow the throttle range 0-100
            except ImportError:
                self.simulation = True
                self.powered = False

    def stop(self):
        "Stop PWM signal"

        self.setW(0)
        if self.powered:
            self.__IO.stop_servo(self.__pin)
            self.powered = False

    def increaseW(self, step=1):
        "increases W% for the motor"

        self.__W = self.__W + step
        self.setW(self.__W)

    def decreaseW(self, step=1):
        "decreases W% for the motor"

        self.__W = self.__W - step
        self.setW(self.__W)

    def getW(self):
        "retuns current W%"
        return self.__W

    def setW(self, W):
        "Checks W% is between limits than sets it"

        PW = 0
        self.__W = W
        if self.__W < self.__WMin:
            self.__W = self.__WMin
        if self.__W > self.__WMax:
            self.__W = self.__WMax
        PW = (1000 + (self.__W) * 10)
        # Set servo to xxx us
        if self.powered:
            self.__IO.set_servo(self.__pin, PW)

EDIT : Oh RPIO instead of RPi... that stupid... I installed RPIO too, the motor works during 1/2 second when I set it to 10. It don't works other times. Is that a new stupid error ?

  • You mention RPi.GPIO but the code uses RPIO.GPIO (they are different Python modules). Anyhow see raspberrypi.stackexchange.com/questions/25973/…. I expect you'll be better off using my pigpio. – joan Aug 24 '15 at 22:32
  • Please add the quote to the question so that's it's easier for someone to review it as opposed to have to download the zip file and the view the code – evolutionizer Aug 25 '15 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.