{"id":22560713,"url":"https://github.com/kevinmarquesp/pservo","last_synced_at":"2025-04-10T09:41:57.546Z","repository":{"id":244309970,"uuid":"814207863","full_name":"kevinmarquesp/PServo","owner":"kevinmarquesp","description":"An Arduino library designed to make working with multiple servo motors simpler and more intuitive, especially for those building complex robots. With PServo, you can easily control the movements of multiple servos at the same time and even create more advanced motion sequences","archived":false,"fork":false,"pushed_at":"2024-08-20T16:36:35.000Z","size":15409,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T08:41:31.501Z","etag":null,"topics":["arduino","arduino-library","async","servo-motor","state-machine"],"latest_commit_sha":null,"homepage":"https://kevinmarquesp.github.io/PServo/","language":"C++","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/kevinmarquesp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-12T14:43:58.000Z","updated_at":"2025-03-23T18:02:18.000Z","dependencies_parsed_at":"2024-07-07T16:10:15.400Z","dependency_job_id":null,"html_url":"https://github.com/kevinmarquesp/PServo","commit_stats":null,"previous_names":["kevinmarquesp/pservo"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmarquesp%2FPServo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmarquesp%2FPServo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmarquesp%2FPServo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmarquesp%2FPServo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinmarquesp","download_url":"https://codeload.github.com/kevinmarquesp/PServo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248194390,"owners_count":21063034,"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":["arduino","arduino-library","async","servo-motor","state-machine"],"created_at":"2024-12-07T21:16:01.765Z","updated_at":"2025-04-10T09:41:57.519Z","avatar_url":"https://github.com/kevinmarquesp.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PServo\n\nAn Arduino library designed to make working with multiple servo motors simpler\nand more intuitive, especially for those building complex robots. With PServo,\nyou can easily control the movements of multiple servos at the same time and\neven create more advanced motion sequences. The library introduces a design\npattern that I call Scene-Oriented Programming, making it easier to choreograph\nand synchronize servo movements for your projects.\n\n![PServo demo](demo.gif)\n\n\n## Installation\n\nPServo is built as a *state machine*, so it requires the `Servo.h` library to\nfunction properly. Make sure you have that installed as well.\n\n\n### Option 1: Manual Installation\n\n+   Visit the [releases page](https://github.com/kevinmarquesp/PServo/releases)\n    on GitHub.\n+   Download the `.zip` file for the version you want.\n+   Extract the `.zip` file into your Arduino libraries folder:\n    +   On Linux or Mac: `~/Arduino/libraries`\n    +   On Windows: `Documents\\Arduino\\libraries`\n\n\n### Option 2: Using Arduino CLI (Recommended)\n\nIf you prefer a faser method, you can use the following [Arduino CLI](https://arduino.github.io/arduino-cli/1.0/)\ncommand:\n\n```bash\narduino-cli lib install --git-url https://github.com/kevinmarquesp/PServo\n```\n\n\u003e [!NOTE]\n\u003e If you haven’t configured the Arduino CLI to allow unsafe library\n\u003e installations, you might need to follow [this documentation](https://arduino.github.io/arduino-cli/0.35/configuration/#configuration-keys)\n\u003e to enable it. In short, run `arduino-cli config init`, open the generated\n\u003e file, and set `library.enable_unsafe_install` to `true`. That’s it!\n\n\n## Usage\n\nThis library doesn’t use the `delay()` function to control the speed of\nmovements, as it would pause the entire program, which isn’t suitable for most\nArduino applications. Instead, it relies on the `millis()` function to determine\nwhen to wait and when to execute movements, similar to other Arduino projects.\n\nThe general structure of your application should look something like this:\n\n```cpp\nunsigned long timer = 0;\n\nvoid setup(void) {\n  // ...rest of the code...\n}\n\nvoid loop(void) {\n  timer = millis();\n\n  // ...rest of the code...\n}\n```\n\nFirst, import the `Servo.h` and `PServo.h` libraries, then create the servo\nobjects you want to control, along with a PServo object for each servo. The\nPServo object will calculate the servo position, and you'll need to update the\nactual servo object with these calculated values.\n\n```cpp\n#include \u003cServo.h\u003e\n#include \u003cPServo.h\u003e\n\nunsigned long timer = 0;\n\nServo servo_right;\nServo servo_left;\n\nPServo machine_right(\u0026timer, 0, 180, true);\nPServo machine_left(\u0026timer, 0, 180, true);\n\nvoid setup(void) {\n  servo_right.attach(7);\n  servo_left.attach(6);\n}\n```\n\n\u003e In this example, the line `PServo machine_left(\u0026timer, 0, 180, true);`\n\u003e initializes a PServo object with a minimum value of 0, a maximum value of 180,\n\u003e and the `true` parameter indicates that this machine allows looping. When the\n\u003e movement sequence ends, it will automatically restart.\n\nSince the `timer` pointer lets the PServo object track the current time in your\napplication, you'll need to update the servo positions within the `loop()`\nfunction. The process involves getting the current position from each PServo\nobject and then writing that position to the corresponding servo object:\n\n```cpp\nvoid loop(void) {\n    timer = millis();\n\n    servo_right.write(machine_right.get_pos());\n    servo_left.write(machine_left.get_pos());\n\n    // ...rest of the code...\n}\n```\n\nTo configure the moveset for the servos, start with the `.begin()` method,\nfollowed by a series of `move()` calls. The `.begin()` method indicates the start\nof a new movement sequence, while each `move()` method specifies a movement to\nbe performed. The PServo object will manage which movement is currently active\nand which should be skipped. It’s important to define this moveset within the\n`loop()` function:\n\n```cpp\nvoid loop(void) {\n    // ...rest of the code...\n\n    machine_right.begin();\n    machine_right.move(180, 15);  // Go to 180º waiting 15 ms for each deg update.\n    machine_right.move(0, 20);    // Go to 0º waiting 0 ms for each deg update.\n\n    machine_left.begin();\n    machine_left.move(180, 20);\n    machine_left.move(0, 0);\n}\n```\n\nSince repeatedly writing the machine name can be tedious, this library provides\na syntax shortcut to simplify your code. The following code does the same as the\none above:\n\n```cpp\nvoid loop(void) {\n    // ...rest of the code...\n\n    machine_right.begin()\n        -\u003emove(180, 15)\n        -\u003emove(0, 20);\n\n    machine_left.begin()\n        -\u003emove(180, 20)\n        -\u003emove(0, 0);\n}\n```\n\nThis is just a basic example. For more details on what this library can do and\nhow to implement additional features, check out the [official documentation](https://kevinmarquesp.github.io/PServo/)\nand the [example sketches](https://github.com/kevinmarquesp/PServo/tree/main/examples)\nto learn more.\n\n\n## Contributing\n\nIf you’d like to contribute to the development of PServo, follow these steps:\n\n### Getting Started\n\n1.  Clone the repository:\n\n```bash\ngit clone https://github.com/kevinmarquesp/PServo\ncd PServo\n```\n\n2.  Set up dependencies:\n\n```bash\nmake deps # Clone and/or build vendorized libraries.\n```\n\n\n### Testing (Arduino Board not Required)\n\nYou can run tests without needing an Arduino board.\n\n\n#### Run All Tests\n\nTo run the entire test suite:\n\n```bash\nmake deps\nmake test\n```\n\n\n#### Run a Specific Test\n\nTo run a specific test, specify the test file with the `GTEST_UNITS` variable:\n\n```bash\nmake deps\nmake test GTEST_UNITS=extra/gtest/test_gtest.cpp\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinmarquesp%2Fpservo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinmarquesp%2Fpservo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinmarquesp%2Fpservo/lists"}