Skip to main content

I know that the arduino Uno can be programmed to do a series of things consecutively. However, I need to be able to start the program with a servo motor running to one end of its travel, holding there, another servo running and holding, a electromagnet firing, then a third servo running. If I can get some direction on how to do it, I'd like to try it myself. After studying what I find on the net I'm totally lost.

Thanks for any suggestions.

Jay

Original Post

Replies sorted oldest to newest

The ticked is as mentioned, you have to start an operation and then go on to the next one, etc.  Then you just loop around and keep tabs on how your processes are proceeding, and do any necessary processing as they proceed and complete.

Most little real-time applications will simply have a processing loop that is continually running, and you just bop out to start and terminate processes as you go.  You'll also likely want to set up a timer block so you can have timers of various resolutions for process control.  Stuff like serial data input is typically handled using an interrupt routine unless your process loop is very small and fast.

GRJ: The Arduino has a setup routine that happens before anything else in your program and a loop that runs repeatedly just as you have described for a real-time system. Interrupts are being used in the belly of the beast but are rarely used at the surface.

Unfortunately, it doesn't appear that the Servo library has a mechanism to sync-up when the servo movement has completed. Your program can issue a command to move to a particular point (say 90 degrees) but there is nothing to say when that movement has actually been accomplished.

As shown in the video, you can issue back to back Servo.write commands in opposite directions and before the first movement is complete, the second command overrides the first.

The only way to ensure that a movement has completed is to estimate a time interval for that to happen. The published interface does not allow for interrupts or other synchronization methods.

...
myServo.write(90);
delay(100);
...

Last edited by Consolidated Leo

RTR12: I'm not sure how these things work either. They have 3 leads; power, ground, and signal. I think it uses PWM through the signal wire. But they don't have to be hooked up to the PWM pins of the Arduino (just the regular Digital I/O pins). There is a circuit board inside the servo and a potentiometer to feed position information to the unit. I'm still learning about these, too.

You can read about how the Arduino uses them in the Servo library.

Consolidated Leo posted:

GRJ: The Arduino has a setup routine that happens before anything else in your program and a loop that runs repeatedly just as you have described for a real-time system. Interrupts are being used in the belly of the beast but are rarely used at the surface.
...

Sure, any uP application needs an initialization procedure that initializes the hardware, etc.

I'm used to writing all the code, including the interrupt routines for various functions.  I'm getting spoiled by the new PIC MPLAB X with all the canned functions for generating code for timers, serial data, etc.

I did some work with the Arduino, and it's very easy to crank out an application with it.  I generally am using the PIC as I'm building stuff that's much smaller than any Arduino processor board, and it includes all the other interface parts as well.

That makes sense, GRJ. Again, all of that is buried in the library code so we don't have to deal with that. But it helps explain how these things work. If I would have had access to servos when I was about 10 years old, I'd have been all over this. 

I understand wanting to go with the smaller footprint for engines and rolling stock. You've got to adjust with working in close quarters.

The Arduino started out as a way to get young people interested in the engineering and science fields of endeavor. They will need to have an understanding of the machines that we develop.

In model railroading, the Arduino is in that sweet spot between technical and simple with a lot of motivation to drive things along. I'm sure that there are a lot of modelers here that would be using them for all sorts of things if they only knew how. After all, these are electric trains.

Consolidated Leo posted:

RTR12: I'm not sure how these things work either. They have 3 leads; power, ground, and signal. I think it uses PWM through the signal wire. But they don't have to be hooked up to the PWM pins of the Arduino (just the regular Digital I/O pins). There is a circuit board inside the servo and a potentiometer to feed position information to the unit. I'm still learning about these, too.

You can read about how the Arduino uses them in the Servo library.

Thanks, I will check out the library. I think after that I might order a couple to play with and experiment with the software for feedback as GRJ indicates below.

gunrunnerjohn posted:

The PWM servos use feedback internally for positioning, typically a pot, but you don't have visibility to the position.  It's assumed that you know the pulse width you're feeding it, so you should know the position.

I gotta look at the library above, but from your post there must be a way to keep track of position in software then. Maybe the library will explain further about software workings. Feedback seems nice, but maybe not needed like I thought it would be? Gotta read up on servos too!

It is my understanding that there are all kinds of servos available with lots of different features including feedback from the internal potentiometer. This would be one way to determine what the actual position of the servo is. Then the program could react acordingly.

The price range goes from about $3 for a hobby servo from Asia, to astronomical. The cost for the feedback seems excessive for anything that I would want to try for a switch machine on a model railroad.

In GRJ's sample code, they are using an external potentiometer connected to one of the analog input pins to determine the position for the servo. As I said before, there is no synchronization method for the program to use to determine when the servo has completed its movement. A suitable time interval is the only way to be sure when it's done.

It's funny that the hobby servos are all advertised as being really fast. I guess in the RC (radio control) world of racing cars, airplanes, and quad-copters, that's an important issue. Speeds are touted as being about 0.12 seconds to move 60 degrees.

In the railroad world, switch machines are meant to run slowly to achieve a more realistic look and operation. But I think that by giving the servo small increments in succession, a slower movement can be accomplished. That's a good thing.

If you buy a servo that has feedback, I suspect you'll be paying more than you might imagine.  I worked with a lot of servo driven aircraft instruments in the 1970's and 1980's, and providing external angle feedback was a big deal.

As you correctly observe, you can simply change the PWM code slowly to achieve the result you desire, that doesn't preclude using the inexpensive model servos.

Add Reply

Post

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653
800-980-OGRR (6477)
www.ogaugerr.com

×
×
×
×
Link copied to your clipboard.
×
×