-
Notifications
You must be signed in to change notification settings - Fork 0
Add analog servo control #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #include "servo.h" | ||
|
|
||
| Servo::Servo(uint8_t channel) { | ||
| this->channel = channel; | ||
| ledcSetup(channel, PWM_FREQ, PWM_RESOLUTION); // nastaveni PWM vystupu | ||
| // write(1500); | ||
| } | ||
|
|
||
| void Servo::attach(uint8_t pin) { | ||
| this->pin = pin; | ||
| ledcAttachPin(pin, channel); | ||
| } | ||
|
|
||
| void Servo::detach() { | ||
| ledcDetachPin(pin); | ||
| } | ||
|
|
||
| void Servo::write(int pos) { | ||
| pos = 65536 * pos / 20000; | ||
| ledcWrite(channel, pos); // nastaveni vystupni hodnoty na vystup | ||
| } | ||
|
|
||
| Servo::~Servo() { | ||
| detach(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #ifndef SERVO_H | ||
| #define SERVO_H | ||
|
|
||
| #include <Arduino.h> | ||
|
|
||
| #define PWM_CHANNEL 1 | ||
| #define PWM_FREQ 50 | ||
| #define PWM_RESOLUTION 16 | ||
|
|
||
| class Servo { | ||
| public: | ||
| Servo(uint8_t channel = PWM_CHANNEL); | ||
| void attach(uint8_t pin); | ||
| void detach(); | ||
| void write(int pos); | ||
| ~Servo(); | ||
| private: | ||
| uint8_t channel; | ||
| uint8_t pin; | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,8 @@ counter command data | |
| T uint16 period (ms) uint16 timeout (ms) ... nastavení periody posílání dat z robota a timeout pro příjem povelů | ||
| P uint8 mode ... nastavení režimu gps (0 - vypnuto, 1 - surová data, 2 - ...) | ||
| V ... version | ||
|
|
||
| C uint16_t ... analogové servo na pinu GPIO4 (šířka pulzu 1000 ... 2000 us) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why 'C'? if you would extend the protocol for smart servos, you would use new command or extend this one?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 'C', and why not (the first letter that came to mind). I would rather use a new command for smart servos.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, thanks |
||
|
|
||
| ESP -> PC | ||
|
|
||
| potvrzení přijatého příkazu DATA: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what this means? should we keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a default setting (middle servo position) for testing purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for explanation