[PYTHON] Try moving the servo motor with RasPi (360 degree round and round version)

Before

I wrote it when using the servo motor SG-90 I thought about using PI HAT, which I had bought a long time ago. It didn't work, so I tried it. IMG_3894.JPG

parts

  1. RasPi3 / RasPi2
  2. Servo motor FS90R
  3. Power supply for motor
  4. Motor controller Adafruit 16 channel PWM / servo HAT for Raspberry Pi

environment

  1. python 3.7.3
  2. adafruit-circuitpython-servokit 1.2.1

What I looked up and what I did

For the time being, the first thing to do is Check the sample code from the product page.

Translating the explanation, 1 means forward rotation, -1 means reverse rotation, and 0.5 means half power. It seems that 0 is enough to stop the rotation.

For the time being, I don't know how much the rotation will be at full power, but first I will try turning it with 1.

kit.continuous_servo[1].throttle = 1

Reverse rotation

kit.continuous_servo[1].throttle = -1

Hmm? Let's stop for the time being.

kit.continuous_servo[1].throttle = 0

Don't stop ... Stop ~~ For the time being, let's unplug the power supply for the motor.

So, I feel like I can use the following code.

# Adafruit 16-Channel PWM/Servo HAT & Bonnet for Raspberry Pi & FS90R sample
#
# see:
# https://learn.adafruit.com/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi
#
# test system:
# python 3.7.3
# adafruit-circuitpython-servokit 1.2.1

import time
from adafruit_servokit import ServoKit

# Set channels to the number of servo channels on your kit.
# 8 for FeatherWing, 16 for Shield/HAT/Bonnet.
kit = ServoKit(channels=16)

ch = 1

def fs90r_convert(throttle):
    """
    Parameters
    ----------
    throttle : float
      require -1.0 .. 1.0, but no check

    Returns : float
      -0.4(right rotation) <= 0.1(stop) <= 0.6(left rotation)
    """
    return 0.1 + throttle / 2

# left rotation (0.1 .. 1.0(max))
for i in range(1,11):
    v = fs90r_convert(i/10)
    print( "i=%f v=%f" % (i/10, v) )
    kit.continuous_servo[ch].throttle = v
    time.sleep(1)

# right rotation (-0.1 .. -1.0(max))
for i in range(-1,-11,-1):
    v = fs90r_convert(i/10)
    print( "i=%f v=%f" % (i/10, v) )
    kit.continuous_servo[ch].throttle = v
    time.sleep(1)

# stop rotation
kit.continuous_servo[ch].throttle = fs90r_convert(0)
time.sleep(1)

# left rotation, max throttle
kit.continuous_servo[ch].throttle = fs90r_convert(1)
time.sleep(1)

# right rotation, half throttle
kit.continuous_servo[ch].throttle = fs90r_convert(-0.5)
time.sleep(1)

# stop rotation
kit.continuous_servo[ch].throttle = fs90r_convert(0)

The point is

def fs90r_convert(throttle):
    return 0.1 + throttle / 2

So, I put the conversion for FS90R. Apparently, it doesn't stop at 0, it stops at 0.1. The argument can be forward rotation, reverse rotation, or stop at 0, given the range 1 to -1 described in the sample program.

reference

  1. https://learn.adafruit.com/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi
  2. https://learn.adafruit.com/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi/using-the-python-library
  3. http://akizukidenshi.com/catalog/g/gM-13206/

Recommended Posts

Try moving the servo motor with RasPi (360 degree round and round version)
Try moving the servo motor with RasPi (180 degree version)
Try to separate the background and moving object of the video with OpenCV
Try hitting the Twitter API quickly and easily with Python
Servo motor control with Raspberry Pi
Try moving 3 servos with Raspberry Pi
Try blurring the image with opencv2
Put Cabocha 0.68 on Windows and try to analyze the dependency with Python