Freesteel Blog » Servo motor sine waves

Servo motor sine waves

Friday, April 14th, 2017 at 4:32 pm Written by:

Building on the weighted servo motor (having spent the first 20 minutes of the day trying to find where I left my code) I’ve tried to code it to run on a sine wave as an oscillation.

It’s not easy, of course.
voltssinwave

How did I get this?

From the fixed voltage experiments I computed the function from the voltage and velocity to the acceleration for motor1 as follows:

cv0, cm0, cv1, cm1, cvm, cvc = 53.202, -1036.634, 56.027, -974.375, -7.497, -1521.571
acceleration1 = (velocity1 - (min(volts1-cv0, 0)*cm0 + max(volts1-cv1, 0)*cm1))*cvm + cvc

Therefore, given the velocity, if you want a particular acceleration, you need the following voltage:

tq = velocity1 - (acceleration1 - cvc)/cvm
if tq < 0:
    volts1 = tq/cm1 + cv1
else:
    volts1 = +tq/cm0 + cv0

The above was the result of trying to make the motor oscillate like a pendulum by setting the acceleration to a negative number times the displacement:

acceleration1 = -acc1fac*(position1 - position1c)

Of course, one source of the problem is knowing the velocity. I've bodged this by recording a couple of positions up to 0.2seconds in the past and measuring to them.

if currenttime - prevtime > 0.1:
    position1prev2 = position1prev
    position1prev = position1
    prev2time = prevtime
    prevtime = currenttime
velocity1 = (position1 - position1prev2)/(currenttime - prev2time)

Unfortunately, this produces lots of bumps, so I think I'll have to do this properly by applying, say, an exponential filter to the position value which delays the position, and use the difference between that and the current position as a measure of velocity.

Like all such runtime velocity measurements (unlike the ones done in pandas that have been calculated by picking a position on either side of the current time, like so:

(df.shift(-10).position1 - df.shift(10).position1)/(df.time.shift(-10) - df.time.shift(10))

...it's also going to be delayed by a certain amount and be invalid under accelerations.

Probably not going to work. I need to take a break from it now and go look at some ESP8266s. I've been without a computer for 3 days, having left my lead in Lancaster when I went for a fly on Wether Fell alone with too much wind on Monday. It was a miracle I didn't groundloop. And then I was in London for a day for a fintech conference where the UK government ministers gave speeches that started like: "Britain is the greatest place for financial tech innovation..." when they really meant: "Britain was the greatest place for financial tech innovation...".

This might not be a bad thing, as most of the financial innovation that's happened in London in recent times seems to have been about new ways to scam citizens and tax collecting governments without the slightest notion of the damage being done. So cutting off Europe does reduce the number of victims the finance sector can prey on, as well as preventing their wholly owned subsidiary -- the UK government -- from blocking financial reforms in that set of nations.

Among the presentations at the conference, I particularly approved of salary finance because they came right out with the observation:

We believe that the financial services industry is regressive and that it is one of the big problems in society today. Higher earners get access to better-value financial products than lower earners, driving inequality in society.

This comes as a revelation, because the rules of finance are always expressed from the point of view of the guy with the money who feels entitled to be compensated for the "risk" of lending it to someone who actually needs the money and might not pay it all back. Generally a person's employer has a lower credit "risk" and so should be able to get a better interest rate, and that's how the loan is worked out, because they can get the repayments directly out of the salary at low risk.

Of course, a lot of people's employers are the government, so they are really borrowing via the government. We could extend the theory further and let me borrow money against my tax collection, with debt repayments added to my tax bill, subject to all the serious consequences should they not be repaid on time. There's a pretty low risk to that scheme, so there's no reason the government couldn't make such loans available at bank of england base rate -- a loan rate only available to large bankrupt London banks that are generally run and owned by rich people. But we can't have that, because then we wouldn't need these useless private banks with their high interest rates charged to poor people.

The problem is the system works a bit and people are too confused about the alternatives (such a public option) to demand some sanity. So while a publicly funded police force, fire service, NHS and network of public highways have been established specifically for the express benefit of the users of said infrastructure rather than the owners of it, the same is not yet happening with the finance system in much of a hurry.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>