Giter Club home page Giter Club logo

piservoctl's Introduction

piServoCtl

Overview

This is a servo motor control library for Raspberry Pi. In addition to normal servo motors, continuous rotation servo motors can also be controlled. It utilizes hardware PWM. Therefore, the servo motor can be moved smoothly. Since you are using pigpio, you need to install pigpio and start pigpiod. To start pigpiod, you need to press the sudo pigpiod command or run pigpiod automatically.
In addition, you can easily make an RC car by using two rotation servo motors. Use the Drive class to set the GPIO pin and servo motor. You can easily implement the steering function by using the steering method.

Installation

sudo pip3 install piServoCtl

Usage

First, start pigpiod (if it is not started). Then import the module. The module name is "piservo". Please note that it is different from the name when it was installed.

sudo pigpiod

Servo

The easiest way is to use Servo(gpio) (where gpio is the GPIO pin number). Use GPIO that supports hardware PWM.
You can control the servo motor with the write method.

Drive

The easiest way is to use Drive(left_gpio, right_gpio) (left_gpio, right_gpio enter the GPIO pin number). Use GPIO that supports hardware PWM. You can swap the left_gpio and right_gpio to flip the front and back of the car.
You can control the car with the steering method.

Demo

Servo

from piservo import Servo
import time

myservo = Servo(12)

myservo.write(180)
time.sleep(3)
myservo.write(0)
time.sleep(3)
myservo.stop()

Drive

from piservo import Drive
import time

mycar = Drive(12, 13)

mycar.steering(50, 45)
time.sleep(1)
mycar.steering(-50, 0)
time.sleep(1)
mycar.stop()

Method

Servo

Servo(gpio, min_value=0, max_value=180, min_pulse=0.5, max_pulse=2.4, frequency=50)

gpio: The gpio pin number to which the servo motor is connected.
min_value: Minimum angle of servo motor (speed if it is a rotation servo motor).
max_value: Maximum angle of servo motor (speed if it is a rotation servo motor).
min_pulse: Minimum control pulse width of servo motor (millisecond).
max_pulse: Maximum control pulse width of servo motor (millisecond).
frequency: PWM frequency of the servo motor.

Create an instance.

Servo.write(value)

value: Servo motor drive angle (speed if it is a rotation servo motor).

Drives the servo motor.

Servo.read()

Read the current value of the servo motor.

Servo.start()

Starts control of the servo motor.

Servo.stop()

Stops control of the servo motor.

Drive

Drive(left_gpio, right_gpio, min_value=-100, max_value=100, min_pulse=0.5, max_pulse=2.4, frequency=50)

left_gpio: GPIO pin number to which the left servo motor is connected.
right_gpio: GPIO pin number to which the right servo motor is connected.
min_value: Minimum speed of servo motor.
max_value: Maximum speed of servo motor.
min_pulse: Minimum control pulse width of servo motor (millisecond).
max_pulse: Maximum control pulse width of servo motor (millisecond).
frequency: PWM frequency of the servo motor.

Create an instance.

Drive.steering(speed=50, direction=0)

speed: Speed of movement.
direction: Direction of movement.

It moves in the specified direction at the specified speed.

Drive.stop()

Stop moving.

Drive.start()

Start control.

Drive.set_speed(speed)

speed: Speed of movement.

Moves in the previously specified direction and at the specified speed.

Drive.set_direction(direction)

direction: Direction of movement.

Moves in the specified direction at the previously specified speed.

Drive.get_speed()

Get the current speed.

Drive.get_direction()

Gets the current direction.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.