MKET

Man Keeping an Eye on Things. Look closely and you will see his right eye opens as his head rises.

My sister’s latest sculpture is called “Man Keeping an Eye on Things” or MKET for short. It is a man in a rocking chair, who, when motion occurs within his view, raises his head and starts rocking. Relative to the Ghost Elevator sculpture, this was from my point of view simple to animate. The head motion is controlled by an RC type hobby servo. Often for something like this I’d use a Robotic servo, but there were none available small enough to fit. Standard RC servos tend to be somewhat problematic for this type of application since there is no way to tell where they are. Their position is set by sending a pulse train where the width of the pulses tells it where to go. So the problem you have is when things first power up, you don’t necessarily know where the current position is and if it’s not where you first tell it to go, it goes there as fast as it can which looks bad and may break things.

However, there are now so called “digital servos”. They are still intended to be controlled with a pulse train, but they have the advantage of being able to be pre-programed with multiple parameters, including a soft-start and operating speed. It also turns out, that the same digital protocol used to program them, can be used to operate them, bypassing the whole pulse train control protocol. The problem is, the digital protocol is, somewhat oddly, not documented, but it is not hard to reverse engineer. I used a Hitec “D” series servo and a quick search of the web turned up a post by someone who had reverse engineered the protocol (I was surprised I could find only one person who had done this). He also discovered that the protocol was the same as that for servos produced by Robotro, a Korean company who’s products do not seem to be available in the US. The manuals they produce are in Korean, but it turns out, because the language of programming is English, much of the most useful part of the manuals are largely in English, so they are quite useful.

The digital protocol used is a simple asynchronous serial one in which the servo is controlled simply by reading and writing registers in the servo. This is pretty much like typical robotic servos. They invert the standard polarity of the UART and since they use one line for send and receive there is a somewhat time sensitive turnaround from send to receive, but this is not hard to deal with.

Of course the Hitec servos do deviate from the documents from Robotro. The strangest deviation is that while the Hitec servos contain a current position register and a set position register, and the current position register behaves as documented, the new position register does not use the same scaling the current position register (as one would expect) and the scaling, while linear, makes no sense.

For this project, I once again chose to use a Cypress PSoC5 microcontroller. I used this since it allowed me to reuse a lot of code from the Ghost Elevator. Also it was actually very cost effective, since Cypress sells a dev board with this processor (actually two of them, one is used to program the other) for $10 and it would be hard to get any other board mounted processor for this price.

The programable logic in the PSoC allowed me to handle the inverted serial logic and send receive turn around timing in hardware without any external logic which was very nice.

The PSoC allows the logic required for serial communication to be programmed into the chip, requiring no external circuitry.

In the circuit above, you will see two inverters, which handle the fact that the servo is using inverted logic. The mux avoids having the UART readback what is being sent, which is nice. The timer handles pulling the RX/TX line high after a read request.

The rocking motion in MKET is done using a stepper motor with “locomotive drive” to convert rotary motion to approximately sinusoidal linear motion. Once again I used a Trinamic stepper controller since these provide very quiet stepper operation. The trick here, is that you want the stepper to stop when the rocking chair is in its neutral position, other wise it can end up looking odd and tends to move suddenly to its neutral position when power to the stepper is removed. To handle this, the motor is equipped with a Hall effect index sensor, which provides a pulse once every revolution to the PSoC. When you want to stop rocking, a timer triggered by the index pulse is enabled. When it times out, it asserts a limit input to the motor controller, which soft stops the motor. By setting the delay appropriately, you can ensure the motor stops reliably in the neutral position. While all of this could be done is software, once again the PSoC allows it to be done totally in hardware.

The stop timer, programmed into the PSoC, allows the motor to be reliably stopped in the desired position completely by hardware.

As with the Ghost Elevator, I once again used FreeRTOS to build the software. This allowed a good deal of software reuse and also results in a design which is easier to understand and easier to modify. This time I also took advantage of the Bootloader system provided by Cypress. This will allow the firmware to be changed over the USB port on the processor without any special programming hardware. While not too likely to ever be used, I had plenty of programming space available and it might be useful if the firmware ever needed to be changed in the field. I will probably retro fit the boot loader to the Ghost Elevator at some point as well.

The electronics and drive motor are all mounted on the bottom of the base.
The head drive servo is just visible above the cutout. The drive linkage can be seen near the back running up to the head.

Updating a DRO

As mentioned in a previous post, Holes, my Sherline mill has a digital readout (DRO). Unlike typical DROs which use magnetic or optical sensors, the Sherline works by keeping track of the position of the lead-screws using quadrature detectors mounted in the hand-wheels. While this is not as accurate as real positions sensors, the lead-screws are precise enough that it is generally more than good enough. The readout for the DRO was designed years ago and uses a 2×16 character display which is quite small. The same unit is still being sold today and is quite expensive for what it is.

I decided I wanted an easier to see display and after looking around for something suitable found Nextion displays. These are small graphical LCD displays with an attached microprocessor, touch screen and PC software that allows a GUI to be relatively easily designed and loaded into the Nextion. The Nextion uses a UART interface, so it is easy to run with another micro-controller. Interestingly, I was able to buy a 2.8 inch Nextion for less than I could find a raw 2.8 inch graphical LCD.

It was quite simple to use the Nextion PC software to produce a GUI for my DRO. The result can be seen in the photo below, which shows the Nextion in a 3D printed case next to the original Sherline readout. Since the Nextion includes a touch-screen, no buttons will be required.

The Nextion display (left) in a 3D printed case next to the original Sherline readout.

You can also see at the top of the photo, the Cypress PSoC4 prototyping kit I’m using to develop the DRO firmware. PSoC stands for programmable system on a chip, and the PSoCs are quite amazing devices containing some combination of programmable analog circuitry, various function blocks and effectively a CPLD along with an ARM Cortex CPU. While all of this is not required for this project (the Sherline DRO uses an 80C51 compatible micro) and in the past I might well have done this with a Microchip PIC, the PSoCs have some advantages over typical micro-controllers. One is, the CPLD can be used to synthesize a quadrature decoder, so this operation can be done in hardware rather than software. I plan on using a PSoC5 for the actual display since it has enough CPLD cells to synthesize the required 3 quadrature decoders also has a lot program and data memory. This allows it to easily accommodate FreeRTOS, the use of which I find can considerably simplify program design.

If you were going to mass produce this DRO, the PSoC would be overkill as you can certainly do it using a much cheaper micro-controller. However, for quantity one, the processor cost is not significant. Indeed, the PSoC5 I will use is the KitProg part of the PS0C5 prototyping board and so is effectively free. The PSoC5 prototyping kit contains 2 PS0C5s, one is the prototyping PSoC, the other is used to program the first and is called KitProg. KitProg can be broken off the main board and then reprogrammed to do what you want, albeit with a limited number of pins brought out. I have several KitProgs from the Miniature elevators project available. Even if you need to buy a PSoC5 prototyping kit, at $15 it is hardly expensive (the Nextion was $20) and is insignificant next to the nearly $300 cost of the Sherline electronics.

At this point, I have the quadrature decoders displaying on the Nextion and am working on code to handle input from the touch screen. I also have a custom circuit board in the works to mount the RJ9 connectors used to connect the quadrature encoders to the electronics. The circuit board should be done next week. The custom board was $15 for three, so in the end the DRO will probably cost less than $50 and be considerably nicer than the $300 Sherline.