Shop OBEX P1 Docs P2 Docs Learn Events
Servo 360 and the P2 — Parallax Forums

Servo 360 and the P2

iseriesiseries Posts: 1,495
edited 2021-03-02 14:28 in Propeller 2

I'm calling it, the first servo360 Driver for the P2.

Apparently, there is not a lot of call for it since there isn't one for the P2. I guess since there is no BOE Bot to put it on there is not a need for one.

Anyway here is the C version of that driver that is almost complete. I need to work on a PID controller for it so that it works better when under load. I also want a free mode so I can position the servo and have it record that position for playback.

Here is the test program I used:

#include <stdio.h>
#include <propeller.h>
#include "servo360.h"

#define SERVO 8
#define FEEDBACK 9


int main(int argc, char** argv)
{
    int s, s1;
    int i;

    printf("Starting\n");

    s = Servo360_Start(SERVO, FEEDBACK);
    s1 = Servo360_Add(20, 21);

    printf("Servo: %d %d\n", s, s1);

    _waitms(5000);

    Servo360_Enable(s, 1);
    Servo360_Enable(s1, 1);

    i = Servo360_Angle(s);

    printf("angle: %d\n", i);

    Servo360_SetAngle(s, 0);
    Servo360_SetAngle(s1, 0);
    _waitms(5000);
    Servo360_SetAngle(s, 180);
    _waitms(5000);
    Servo360_SetAngle(s, 270);
    _waitms(5000);
    Servo360_SetAngle(s, 90);
    _waitms(5000);
    Servo360_SetAngle(s, 0);

    while (1)
    {
        i = Servo360_Angle(s);

        printf("Angle %d Status: %d\n", i, Servo360_Status(s));
        _waitms(1000);
    }
}

Servo in action: Servo360 Video.

Mike

Comments

  • Is your code available, Mike? I have a Spin2 object that will handle servo pulses and read the feedback signal, but no code for ramping speed down the speed to land on a specific position. C is not my first language, and looking through the [mostly uncommented] Parallax FB360 code has not been fun. I'm hoping that your style more closely aligns with my experience (well, lack thereof) with C and I can add more features to the Spin2 version I've written.

  • @JonnyMac ,

    Since there is not a repository for C libraries used in FlexProp I put them in on my github repository.

    The code can be found here in P2Custom.

    Mike

  • Thanks, Mike, I will have a look. I will also be sure to credit you in my listing for any ideas that I "liberate" from your code! :)

Sign In or Register to comment.