Shop OBEX P1 Docs P2 Docs Learn Events
Serial Servo: Making a servo more intelligent — Parallax Forums

Serial Servo: Making a servo more intelligent

RaymanRayman Posts: 14,515
edited 2010-11-11 04:56 in Robotics
I don't post in this forum, but I wanted to share a project I'm working on...

My goal is to improve the servos for my robot.

I'm taking a low cost digital, all-metal servo and reprogramming the onboard PIC16F676 microcontroller.
This will allow bi-directional digitial communications between the servo and Propeller (brain of my robot).

I'm having to learn how to program PICs, but I'm getting there...

The original plan was to remove the PIC and run 5 wires to a Propeller to control the servo.· But, this way
is a lot more convenient.· But, I discussed my original plans and servo details in this Propeller thread:
http://forums.parallax.com/showthread.php?p=907089

Here's some features that "Serial Servos" will have:
1.· Digital bi-directional communications
2.· Servo can transmit it's position to host controller
3.· You can limit the power of·a servo or even let it free
4.· You can use "motor braking" to maintain position without using any power
5.· Bus operation so that several servos can use the same 3 wires

There are also a few extra I/O pins that aren't being used on the PIC, so I'm toying with the idea of adding buttons or LEDs to the servo....

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm

My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm

Post Edited (Rayman) : 7/25/2010 2:12:59 PM GMT

Comments

  • RaymanRayman Posts: 14,515
    edited 2010-07-25 11:45
    Only had to make a minor hardware change to allow communications with a Propeller board...
    Here's a photo of my test setup:

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm

    My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
    My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
    1496 x 1122 - 812K
  • Martin_HMartin_H Posts: 4,051
    edited 2010-07-25 13:24
    That's pretty neat.

    The ability to know a servo's position will be really handy. Wheen using them for positioning something large, you have to park it, so that during the next power up the servo is at a known position. Otherwise at the next power up you'll get a major jerk when the first servo pulses are applied.

    Position feedback to the main controller avoids that problem, plus helps with stall detection.
  • ercoerco Posts: 20,256
    edited 2010-07-25 16:22
    Way cool, Rayman! That will be very useful! Parallax' Beau Schwabe had a neat older post about reading (analog) servo position at· http://forums.parallax.com/showthread.php?p=582447·Actually, I see you in that thread. You're way ahead of me!

    Please keep on posting here, very informative stuff.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • Peter KG6LSEPeter KG6LSE Posts: 1,383
    edited 2010-07-25 21:26
    you bring up a interesting point .

    when I heard that "digital" servos were coming in the RC world I was hopeing SO bad for a Bi Dir comms on them .

    Ends up there the same PPM system IN but there smarter on the inside ..
    Peter KG6LSE

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Carpe Ducktum" "seize the tape!!"
    peterthethinker.com/tesla/Venom/Venom.html
    Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway. —Tanenbaum, Andrew S.
    LOL
  • ratronicratronic Posts: 1,451
    edited 2010-07-25 21:56
    Rayman - I too am real interested in what your doing - please keep us up to date with what your doing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if it ain't broke!


    D Rat

    Dave Ratcliff N6YEE
  • surfdabblersurfdabbler Posts: 3
    edited 2010-07-27 06:09
    Great project. I've though about this, but it would be great to see someone actually do it. I have a hexapod robot (= 18 servos) that would love some smart-servos! There's already a couple of HX12Ks in there too. Here's some thoughts...

    The biggest advantage is being able to read the servo position, speed, torque, etc, at any instant. It would be really nice to get rid of the servo jump on startup, and also to get good feedback on actual maximum movement rates under load in controlling the walk cycles.

    It would be nice to get the original code off the HX12K, to re-burn the PIC back to the original code if it doesn't work, but often the PIC is read-protected against this.

    Another nice feature would be to implement a serial protocol that was auto-detecting. If a normal pulse-width is given, it can use this to drive the servo. Alternatively, if it detects a serial message, it could detect that and switch to serial mode. There's the best of both worlds, and wouldn't require any hardware changes. Ideally, a one-wire serial protocol would be implemented, as this would permit the existing hardware to be used without any modification. Unfortunately the more standard SPI and I2C require extra wires for bi-direction communication. Perhaps the clock can be combined with the power line - this would require some extra circuitry at both ends to drive a high-current clock signal, and smooth it out again at the servo end. [noparse]:([/noparse]

    Perhaps it's better to just add the extra digital control lines that are required. In the end, I2C on an independent connection is probably a good choice, with the option of running the power through the original analogue connection or the new digital connection. This would allow a lot of flexibility, and it looks like there's room above the circuit board to add a new pin-header. Unfortunately, the 16F676 doesn't have hardware support for SPI or I2C, so this means implementing them in software, or possibly swapping the 676 out for a newer 14-pin PIC with SPI/I2C support, such as 16F1823. PICs themselves are cheap - it's the board that seems to add most of the cost, so if the same board can support another chip, then that's still an economical option.

    Anyway, I'll be watching with interest to see how you go.
  • surfdabblersurfdabbler Posts: 3
    edited 2010-07-27 06:24
    Hmm, rethink...I was getting a little carried away. You are right - get it working with one wire if you can. Zero hardware change is certainly simplest!
  • RaymanRayman Posts: 14,515
    edited 2010-07-27 09:28
    The PIC code is protected, so I couldn't get it. But, I think I can do a decent job without it. It's just going to take me a few days to figure it out...

    I kinda like the auto-sensing idea so that it would revert back to a regular servo...

    The hardware change I made was to remove the input transistor and replace it with just a 1k series resistor directly to the PIC input pin. The PIC operates at 4.4 V, but it has TTL input and CMOS output. So, I think it should work fine with a Propeller at 3.3V. It may not work with a Basic Stamp, I don't know...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm

    My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
    My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
  • ratronicratronic Posts: 1,451
    edited 2010-07-27 14:20
    Rayman - I have been using ax12's but they are too expensive for my hobbiest use, if you can come up with a cheap way to make a digital servo that has serial control and feedback that would be great!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···································Fix it, if it ain't broke!


    D Rat

    Dave Ratcliff N6YEE
  • RaymanRayman Posts: 14,515
    edited 2010-07-27 15:48
    Ax12 does look a lot like what I want to do...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm

    My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
    My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
  • schillschill Posts: 741
    edited 2010-07-27 18:39
    Something else to look at, The openservo project:
    http://openservo.com/
  • RaymanRayman Posts: 14,515
    edited 2010-07-27 19:27
    I think somebody mentioned the openservo project over in the Propeller thread where I started this project...
    But that approach involves replacing the servo's circuit board...
    This way uses the same board and just reprograms the existing controller chip, which I think will be a whole lot cheaper and easier...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm

    My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
    My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
  • simonlsimonl Posts: 866
    edited 2010-07-27 22:24
    @Rayman: You've got me out of the Propeller thread - LOL

    You've made great progress - congrat's.

    When you're ready; I wonder if you'd give us a "dummies guide" to re-programming the PIC? I have a PIC programmer (I came to the Propeller after a yaer of frustration with PICs and their (cringe) interrupts) so would be able to do this, but how did you interface the programmer to the PIC?

    Keep up the good work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,
    Simon

    www.norfolkhelicopterclub.com

    Announcement: To cut costs in the current economic climate, we have switched-off the light at the end of the tunnel.
  • RaymanRayman Posts: 14,515
    edited 2010-07-28 00:02
    simonl, I'll try to provide some kind of diagram later. I'm learning myself... But, my Pickit 2 came with a demo board with a PIC16F690 on it. If you ignore the fact that the PIC16F690 has more pins, you hook up the programmer the exact same way as with the demo board.
    I'm pretty sure that the DIP version of the PIC16F676 could just plug into that demo board and be programmed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm

    My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
    My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
  • RaymanRayman Posts: 14,515
    edited 2010-08-03 19:56
    Here's my reverse engineered circuit diagram of the servo's circuit board:



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm

    My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
    My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
    1305 x 1255 - 28K
  • Martin_HMartin_H Posts: 4,051
    edited 2010-08-03 23:37
    Rayman, have you heard of OpenServo openservo.com/? In concept it looks similar to what you are doing. I particularly liked the fact that they are using I2C so you can daisy chain servos.

    Update: nevermind I just noticed the earlier discussion of open servo.

    Post Edited (Martin_H) : 8/4/2010 2:31:59 AM GMT
  • RaymanRayman Posts: 14,515
    edited 2010-09-27 06:31
    Well, I finally had some time to work on this some more...

    I've now learned enough PIC code to make the servo act like a servo and move to any hard-coded position and hold it. It still needs tweaking, but it works good enough and I can control how much power the servo uses to move and hold position.

    Now, I just have to code up a communication protocol...

    I think I'll have the servo act as a slave and have the data line trigger an interrupt whenever it detects the start of a serial command...
  • surfdabblersurfdabbler Posts: 3
    edited 2010-10-17 23:09
    Rayman wrote: »
    Well, I finally had some time to work on this some more...

    I've now learned enough PIC code to make the servo act like a servo and move to any hard-coded position and hold it. It still needs tweaking, but it works good enough and I can control how much power the servo uses to move and hold position.

    Now, I just have to code up a communication protocol...

    I think I'll have the servo act as a slave and have the data line trigger an interrupt whenever it detects the start of a serial command...

    Great job on getting this far. It's superb to know that these servos can indeed be reprogrammed. I've found a few different servos that are based on the PIC chip, so there's a range available, just waiting to be reprogrammed.
  • RaymanRayman Posts: 14,515
    edited 2010-10-23 16:48
    Update: Well the serial communications is a tougher problem than I thought... I would like to have the option of having multiple servos on one wire, but this turns out to be a serious issue with no UART in the PIC. I can bit bang RS232 but that is so slow that servo operation could be affected.

    Fortunately, a new line of PIC chips with UART that are drop-in replacements are coming out in November. I'm just going to wait for them now, because they will make things so much simpler and better...
  • RaymanRayman Posts: 14,515
    edited 2010-10-23 16:49
    surfdabbler,

    If you or anybody else is a PIC programmer, let me know and I'll share my code...
  • RaymanRayman Posts: 14,515
    edited 2010-11-04 13:06
    The new PIC I've been waiting for is finally available:
    PIC16F1823

    This one is a drop in replacement that will allow me to add a UART on some of the free pins. I could also up the clock speed using the internal oscillator...

    Got a couple free samples coming in a few days, so should know soon if this will work or not...

    The UART will make things much, much simpler for me...
  • william chanwilliam chan Posts: 1,326
    edited 2010-11-04 18:24
    Rayman,

    Can you make your Intelligent Servo able to go into sleep mode at a few uAmps?
    and able to wake up when a pulse (or any uart signal) is sent to it?
    It should also auto sleep if idle for more than 30 seconds.

    This is important as a normal servo wastes a few milli amps when idle, draining AA batteries within 2-3 days even when not doing anything.
  • RaymanRayman Posts: 14,515
    edited 2010-11-05 06:23
    Good question. I do want to use the motor braking to maintain position while using low power. But, that's likely to be more than a few uA...

    I know this setup will allow a great deal of power savings, but don't know exactly how much....
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-11-08 12:09
    In days past I would tie both motor wires together to make a brake. With the gear reduction on these, this might be a possibility for you. A tiny NC relay could work. When the servo is ON and receiving commands / positioning, you would energize the relay opening the contact and opening the shorted junction (at the expense of a few mA while running). In the servo's "sleep" state, the relay is closed, the brake is energized and no power is consumed.

    It worked especially well with brushless motors and in my trials has worked fairly well with brushed. YMMV and for what it's worth, I've not tried it on a motor tiny as what's in a servo.
  • ercoerco Posts: 20,256
    edited 2010-11-09 08:45
    Dynamic braking (DB) using a relay is my favorite trick. It works superbly to stop a moving DC motor in a real hurry, putting all that kinetic energy to work. But a stopped motor has no KE, so DB can't add any holding torque until it starts moving again, and by that time you're out of position. Not any real gain to be had in that case.
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-11-09 09:58
    Cool, Rayman.

    Are you going with a similar setup as AX12+ (half-duplex) or full?
  • RaymanRayman Posts: 14,515
    edited 2010-11-10 16:17
    erco,
    I know what you're saying. But, believe me, it works. The servo is almost impossible to move when the brakes are on.

    MaxTuxLin,
    There's only 1 wire, so it's tough to do any kind of 2-way comms without conflict. My current plan is to have the servo only respond with it's position when asked....
  • MacTuxLinMacTuxLin Posts: 821
    edited 2010-11-10 19:52
    I would really like to help but I only have a little experience on servos with Mega128 and new to Propeller but already getting my hands dirty.

    Yes, using UART is a lot better then PWM.
  • RaymanRayman Posts: 14,515
    edited 2010-11-11 04:56
    Just checked on my free sample order status and these new chips aren't scheduled to ship until Dec 1st :(
Sign In or Register to comment.