Raspberry Pi - Robot Arm

Project and Code

1. Robot Configuration

  • 1 * Raspberry Pi processor.

  • 4 * SG90 servos.
    在这里插入图片描述

  • 1 * PCA9685.
    在这里插入图片描述

  • 1 * 5V(2A/4A) adaptor.

  • 3D printed arm model EEZYbotARM.
    在这里插入图片描述

1.1 Configure PCA9685

I have followed this post

  • Install I2C tools
sudo apt-get install python-smbus
sudo apt-get install i2c-tools
sudo i2cdetect -y 0
  • Connect pins

在这里插入图片描述

  • Install python PCA9685 library
sudo pip3 install adafruit-circuitpython-servokit

1.2 servokit lib

This library offers simple usage of servos.

  • Initialize the system (PCA9685 is a 16 channels system):
from adafruit_servokit import ServoKit
kit = ServoKit(channels=16)
  • Standard servos, control the desire angle.
kit.servo[servo_id].angle = 180
kit.servo[servo_id].angle = 0
kit.servo[servo_id].set_pulse_width_range(1000, 2000)
  • Continuous servo (which is our case with SG90):
kit.continuous_servo[servo_id].throttle = -1
kit.continuous_servo[servo_id].throttle = 1
kit.continuous_servo[servo_id].throttle = 0
kit.continuous_servo[servo_id].throttle = 0.5

Control

在这里插入图片描述

video blibili

def change_servo(angle, ids=[1]):
    print("  Rotate to %f"%(angle))
    direction = -1
    if angle > 0:
        direction = 1
    for id_servo in ids:
        kit.continuous_servo[id_servo].throttle = direction
        
    # rotate the servos
    time.sleep(abs(angle))
    
    # stop the servos
    for id_servo in ids:
        kit.continuous_servo[id_servo].throttle = 0
def go_forward(angle=magnitude, direction=1):
    kit.continuous_servo[1].throttle = direction
    # rotate the servos
    time.sleep(abs(angle))
    kit.continuous_servo[1].throttle = 0

def go_left(angle=magnitude, direction=1):
    kit.continuous_servo[0].throttle = direction
    time.sleep(abs(angle))
    kit.continuous_servo[0].throttle = 0
    
def hands_up(angle=magnitude, direction=1):
    kit.continuous_servo[3].throttle = direction
    time.sleep(abs(angle))
    kit.continuous_servo[3].throttle = 0

def go_up(angle=magnitude, direction=1):
    kit.continuous_servo[2].throttle = direction
    time.sleep(abs(angle))
    kit.continuous_servo[2].throttle = 0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值