Pages: 1 2 [3] 4 5   Go Down
 Author Topic: Controlling an animatronics bust  (Read 1208 times) 0 Members and 1 Guest are viewing this topic.
Offline
Full Member
Karma: 5
Posts: 166
 « Reply #30 on: February 07, 2013, 04:28:56 pm » Bigger Smaller Reset

See above edited comment^
Quote
I am trying to think of a clever way to always control these in a way that they are never high at the same time.

Somebody can tell me if I'm wrong but true/false should resolve as 1 and 0
Code:
//send to h-bridge
digitalWrite(pin1,output>1e-6);
digitalWrite(pin2,output<-1e-6);
if output is 0 then h-bridge gets 0 0
if output is >0 then h-bridge gets 1 0
if output is <0 then h-bridge gets 0 1
Notice I used 1e-6 and -1e-6.  I don't like to use exactly zero to allow a little lee-way.  Mileage may vary.
 Logged

Offline
God Member
Karma: 27
Posts: 827
 « Reply #31 on: February 07, 2013, 04:37:48 pm » Bigger Smaller Reset

1e-6

e as in logarithmic e, engineering exponent or is that a variable of some sort?

I apologize if that seems like a dumb question.

Otherwise, I completely understand what you are doing there. Just converting the output into expressions that will evaluate true or false based on the sign of the error. Right?
 Logged

Offline
Full Member
Karma: 5
Posts: 166
 « Reply #32 on: February 07, 2013, 04:42:17 pm » Bigger Smaller Reset

Quote
1e-6

e as in logarithmic e, engineering exponent or is that a variable of some sort?
1e-6 as an exponential number 1x10^-6 or 0.00001.  You can use any value slightly greater than and slightly less than 0.  This makes sure that you don't continue to oscillate around zero due to machine precision.

C isn't my strong suit but I know programming well, regardless of the language.

Quote
Just converting the output into expressions that will evaluate true or false based on the sign of the error. Right?
That's correct.

How do you control the speed of the motor?
 Logged

Offline
God Member
Karma: 27
Posts: 827
 « Reply #33 on: February 07, 2013, 04:59:34 pm » Bigger Smaller Reset

How do you control the speed of the motor?

That is what I expected that you meant. Exponent in C is a bit more complicated. I can figure that out, though.

Speed is another issue entirely. I am looking at a softPWM library right now, but I will have to heavily modify it, I think. Obviously I need 20 PWMs, so the hardware PWM isn't going to work. I am trying to get enough of the gist of it to try to write something very basic to do it.

I will be duplicating the stock way it is done (I am modifying existing hardware) right now, it uses a 125Hz frequency PWM. That's 8ms per period. The motor speed is controlled in 1ms increments (12.5% duty cycle steps.) So there are only 8 speeds + zero/off. It seems that I should be able to come up with something even simpler than the library to manage this. I am trying my best not to have to use external libraries (unless I make my own) as they tend to be bloated with lots of extra stuff that increases your code size, and sometimes hog resources I might need, for functions that I am not using.

The grand result is for me to package this up and make it portable enough that people could use it in their own similiar projects. That's not a priority, but I am trying to keep that in mind as I go.
 Logged

Offline
God Member
Karma: 27
Posts: 827
 « Reply #34 on: February 07, 2013, 06:33:10 pm » Bigger Smaller Reset

come to think of it, I am really fine with an error of 1 or -1. The original application only supported 32 possible positions in the first place. My movements are quite small, so 255 steps wouldn't even be noticeable.
 Logged

Offline
Full Member
Karma: 5
Posts: 166
 « Reply #35 on: February 07, 2013, 07:31:08 pm » Bigger Smaller Reset

Be careful with that.  You'll end up oscillating around your set point if you don't land on it exactly.
 Logged

Offline
God Member
Karma: 27
Posts: 827
 « Reply #36 on: February 07, 2013, 07:47:45 pm » Bigger Smaller Reset

So is there a way to set a deadband (or we call it hystiresis in the electronics world) where it is fine as long as it is within a range of the desired position? Like I don't really care all that much if it stops at 5 or 9 when I commanded 7. The difference would not be noticeable in my application. It seems like that would prevent a lot of oscillation.

A good PID algorithm would have this included. In a thermostat for example, you wouldn't want it turning your heater on, then your air conditioner over and over trying to maintain an exact temp.
 « Last Edit: February 07, 2013, 07:50:54 pm by Retroplayer » Logged

Offline
Full Member
Karma: 5
Posts: 166
 « Reply #37 on: February 07, 2013, 09:14:28 pm » Bigger Smaller Reset

Code:
tolerance=2
digitalWrite(pin1,output>tolerance);
digitalWrite(pin2,output<-tolerance);

You can do something like this.  Also thermostats have heat/cool settings for this reason.  You don't try to cool your house you just turn off the heat.  This only works because your house will gravitate towards the outdoor temperature.
 Logged

Offline
Full Member
Karma: 5
Posts: 166
 « Reply #38 on: February 08, 2013, 12:41:58 pm » Bigger Smaller Reset

What H-Bridge are you using?  Shouldn't you be able to send an analog signal to your h-bridge to control the speed?
 Logged

Offline
God Member
Karma: 27
Posts: 827
 « Reply #39 on: February 08, 2013, 01:08:16 pm » Bigger Smaller Reset

The H-Bridges are already built into the hardware. They are 6-transistor (Mark Tilden style) H-Bridges. I can put the PWM on either the forward or reverse lines depending one which direction I want to go, but no, there isn't a separate PWM input.

It "may" be possible to use gates to allow PWM.... hey wait a minute....

In the original controller, all of the motor lines are on latches. I beeeeeeeeet, they are providing PWM on the OE lines. That way they just set which pins they want to be HIGH, and pulse the OE line with the PWM signal.

I would have to add latches into my circuit, but that reduces my PWM needs down to the point that I can use the hardware PWM. Though I can't use the built in analogWrite because it is too fast and makes the motors go nuts and I don't see a way of changing that without changing the built in arduino code.

I was hoping to do this without adding additional circuitry, but now I am thinking that may be the best way.
 Logged

Offline
Full Member
Karma: 5
Posts: 166
 « Reply #40 on: February 08, 2013, 01:17:41 pm » Bigger Smaller Reset

I just thought of something.  To make sure you don't fry your H-Bridge your gonna want to zero out your pins before sending the next command.  Lets say your last command was 0 1.  When you reverse the direction the first thing you do is set pin1 to 1.  So then you have a 1 1 state because your 2nd pin hasn't been set yet.  You don't have to worry about it when you go from 1 0 to 0 1 because your 1 pin is set first.

I'm not even sure it really matters and would depend on how much time passes between digital writes.

Code:
tolerance=2
digitalWrite(pin2,0);//make sure a 1 1 state isn't sent to h-bridge.

digitalWrite(pin1,output>tolerance);
digitalWrite(pin2,output<-tolerance);
 Logged

UK
Offline
Tesla Member
Karma: 89
Posts: 6326
-
 « Reply #41 on: February 08, 2013, 01:20:28 pm » Bigger Smaller Reset

I beeeeeeeeet, they are providing PWM on the OE lines. That way they just set which pins they want to be HIGH, and pulse the OE line with the PWM signal.

That's how my motor driver shield works and seems like the most sensible design to me.

It's possible to change the PWM frequency and I'm sure you'll find that Nick Gammon's forum has a tutorial covering that.
 Logged

Offline
God Member
Karma: 27
Posts: 827
 « Reply #42 on: February 08, 2013, 01:38:07 pm » Bigger Smaller Reset

Thanks, I am digging now. My lord this will so greatly simplify things for me. Actually, I have ust about everything else done (still have to experiment a bit with the PID library) so this just might get it finished!

I don't know why I hadn't occurred to me before. Well, actually I do know why, it was a variety of things along the path of this project. laadams85's question asking me to explain the H-bridges forced me to go back to the beginning... THIS is why I love discussions. Sometimes things just click when you are trying to explain it to someone else.

Now, if I could just find an I2C or SPI shift register or latch that has an OE as well, I will be golden. Near the beginning of this project, I was actually going to use 2 PCA9555 port expanders to save pins. I even ordered them and experimented a little with them. I passed on them mainly for the lack of OE control. Now I have a really good reason why.

You guys are great, thank you!
 Logged

Offline
God Member
Karma: 27
Posts: 827
 « Reply #43 on: February 08, 2013, 01:42:48 pm » Bigger Smaller Reset

BTW, here's some great info on changing some things about the PWM. http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

I guess I just need to figure out if changing them in my code will break anything else using the same timers.

Finding stuff showing the 74HC595 being used on the SPI bus... good things so far...
 « Last Edit: February 08, 2013, 01:59:05 pm by Retroplayer » Logged

Offline
God Member
Karma: 27
Posts: 827
 « Reply #44 on: February 08, 2013, 02:31:02 pm » Bigger Smaller Reset

Some promise in the NXP PCA9506. 40 bits, true OE, I2C interface. Downside is 56pin TSSOP

http://cache.freescale.com/files/analog/doc/data_sheet/MC33996.pdf has some promise. No OE pin, but has a dedicated PWM pin.
 Logged

 Pages: 1 2 [3] 4 5   Go Up