{"id":20205386,"url":"https://github.com/cgxeiji/servo","last_synced_at":"2025-04-10T12:13:16.399Z","repository":{"id":57537737,"uuid":"209999371","full_name":"cgxeiji/servo","owner":"cgxeiji","description":"Go library for controlling servos on a Raspberry Pi","archived":false,"fork":false,"pushed_at":"2021-09-24T00:10:31.000Z","size":103,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T11:07:28.501Z","etag":null,"topics":["go","golang","pi-blaster","raspberry-pi","servo"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cgxeiji.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null}},"created_at":"2019-09-21T14:29:08.000Z","updated_at":"2024-11-21T19:30:19.000Z","dependencies_parsed_at":"2022-09-07T16:41:17.841Z","dependency_job_id":null,"html_url":"https://github.com/cgxeiji/servo","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgxeiji%2Fservo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgxeiji%2Fservo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgxeiji%2Fservo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgxeiji%2Fservo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cgxeiji","download_url":"https://codeload.github.com/cgxeiji/servo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217081,"owners_count":21066633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","pi-blaster","raspberry-pi","servo"],"created_at":"2024-11-14T05:17:19.211Z","updated_at":"2025-04-10T12:13:16.373Z","avatar_url":"https://github.com/cgxeiji.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Servo\n\n[![Version](https://img.shields.io/github/v/tag/cgxeiji/servo?sort=semver)](https://github.com/cgxeiji/servo/releases)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/cgxeiji/servo)](https://pkg.go.dev/github.com/cgxeiji/servo)\n[![License](https://img.shields.io/github/license/cgxeiji/servo)](https://github.com/cgxeiji/servo/blob/master/LICENSE)\n![Go version](https://img.shields.io/github/go-mod/go-version/cgxeiji/servo)\n\nServo is a Go library to control servo motors on a Raspberry Pi using pi-blaster.\n\n## DISCLAIMER\n\n\u003e **This library controls physical pins of a Raspberry Pi using pi-blaster.\n\u003e Incorrect pin assignment or pi-blaster configuration may DAMAGE the Raspberry\n\u003e Pi or connected devices.  Please, make sure to carefully check your connections\n\u003e and code before running your program.**\n\u003e\n\u003e **You have been warned.**\n\u003e\n\u003e **Good luck and Godspeed!**\n\n## About the library\n\nThis library uses [pi-blaster](https://github.com/sarfata/pi-blaster) to\ncontrol servo motors on a Raspberry Pi. Under the hood, it opens a pipeline to\n`/dev/pi-blaster` and sends commands in the format `GPIO=PWM`. The library\ncalculates the appropriate PWM based on the speed and position of the servo and\ngroups the writes to `/dev/pi-blaster` at a rate of 40 ms, if multiple servos\nare connected. You can check the\n[documentation](https://godoc.org/github.com/cgxeiji/servo) for more detailed\ninformation.\n\nEach connected servo is managed independently from one another and is designed\nto be concurrent-safe.\n\nIf the package `servo` detects that `pi-blaster` is not running on the system when\nexecuted, it will throw a warning:\n```\nYYYY/MM/DD HH:mm:ss WARNING: pi-blaster was not found running: start pi-blaster to avoid this error\n        (servo will continue with pi-blaster disabled)\n```\nand redirect all writes to `/dev/null`. This way, you can build and test your code\non machines other than a Raspberry Pi or do a cold run before committing.\n\n## Testing your System\n\nTo check if your system can handle real-time control of servos (i.e. move the\nservos at the expected speed), a system check and a stress test are provided.\n\nYou can run them with:\n```\n$ cd $(go env GOPATH)/src/github.com/cgxeiji/servo\n$ go test -v\n```\n\nThis test makes sure that the system is capable of running **100 servos**\nconcurrently within the expected time frame. It simulates connecting 100 servos\nand moving them from `0 to 180` degrees, from `180 to 0` degrees, and from `0\nto 180` degrees for a total of 3 passes. At the nominal speed of a common\nTowerPro servo of `0.19s/60degrees`, it should take approximately `570ms +/-\n50ms` for the servo to move 180 degrees.\n\nFor benchmarking, the test also checks 1,000 and 10,000 concurrent servos\nconnected, but these tests won't throw critical failures.\n\nIn simple terms, if your Raspberry Pi is capable of running 100 servos at the\nsame time (which is a number way above the number of pins available), you can\nbe confident that the servos will be controlled as expected.\n\n## Example code\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/cgxeiji/servo\"\n)\n\nfunc main() {\n\t// Use servo.Close() to close the connection of all servos and pi-blaster.\n\tdefer servo.Close()\n\n\t// If you want to move the servos, make sure that pi-blaster is running.\n\t// For example, start pi-blaster as:\n\t// $ sudo pi-blaster --gpio 14 --pcm\n\n\t// Create a new servo connected to gpio 14.\n\tmyServo := servo.New(14)\n\t// (optional) Initialize the servo with your preferred values.\n\t// myServo.Flags = servo.Normalized | servo.Centered\n\tmyServo.MinPulse = 0.05 // Set the minimum pwm pulse width (default: 0.05).\n\tmyServo.MaxPulse = 0.25 // Set the maximum pwm pulse width (default: 0.25).\n\tmyServo.SetPosition(90) // Set the initial position to 90 degrees.\n\tmyServo.SetSpeed(0.2)   // Set the speed to 20% (default: 1.0).\n\t// NOTE: The maximum speed of the servo is 0.19s/60degrees.\n\t// (optional) Set a verbose name.\n\tmyServo.Name = \"My Servo\"\n\n\t// Print the information of the servo.\n\tfmt.Println(myServo)\n\n\t// Connect the servo to the daemon.\n\terr := myServo.Connect()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// (optional) Use myServo.Close() to close the connection to a specific\n\t// servo. You still need to close the connection to pi-blaster with\n\t// `servo.Close()`.\n\tdefer myServo.Close()\n\n\tmyServo.SetSpeed(0.5) // Set the speed to half. This is concurrent-safe.\n\tmyServo.MoveTo(180)   // This is a non-blocking call.\n\n\t/* do some work */\n\n\tmyServo.Wait() // Call Wait() to sync with the servo.\n\n\t// MoveTo() returns a Waiter interface that can be used to move and wait on\n\t// the same line.\n\tmyServo.MoveTo(0).Wait() // This is a blocking call.\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgxeiji%2Fservo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcgxeiji%2Fservo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgxeiji%2Fservo/lists"}