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.
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.
Recommended Posts