Multiple position servo control

Please let me know which node should I use to conntect to servo multiple positions controled by buttons
button1 on position of servo 10deg
button1 off postition of servo 0deg

button2 on position of servo 30deg
button2 off position of servo 0deg

something like that :smiley:

The easiest solution is to use an if-else node. Button will connect to COND, then T/F values will be the value for servo position (which will be a number between 0 & 1, not 0 & 360deg). Output of if-else then feeds servo POS

Can I also use it if I would use 5 buttons and potentiometer?

Yes. If all 5 buttons are controlling 1 servo, a “select” node might be a better option. Each button ties directly to one of the S# pins and the corresponding X# pin has the value for that button. To get new values each time a button is released, run button output to a pulse-on-false node, then to another S# pin. The select node can be expanded to have any number of X#/S# pins. The output for the select node will feed your servo position.

How to wire the POT depends on what you want it to do. If button5-on indicates to use POT to position servo, then button5 output would probably tie to select-S9 and POT output would tie to select-X9. S10/X10 would then be used for button5 pulse-on-false to provide new position when button5 is released.

this works grate !! thank you :smiley:
I still have a problem with potentiometer - when I connect it to select node nothing works :frowning:

I want to do program to my tractor which will work lakie so:
1 - (impulse button) work on/off
2 - (impulse button) transport on/off
3 - (impulse button) tool one on/off
4 - (impulse button) tool two on/off
5 - (impulse button) tool three on/off
6 and 7 (impulse button) will move servo one manualy up and down
and potentiometer as throttel
all this will control two servo
servo 1 throttle
servo 2 lift

It should work like this:
when transport (2) is on servo 2 goes all the way up
when off nothing happens :slight_smile:

when work is on and tool one is on
servo 1 (throttle) angle position 50
Servo 2 (lift) angle position 10

when work is off and tool one on
servo 1 (throttle) angle position 5
Servo 2 (lift) angle position 2

potentiometer will control throttle when all tools are off
6and7(impuls button) will control lift when all tools, transport and work is off

Is it possible to do it with XOD and arduino ? :smiley:

This is WAY different than you originally asked for. A single button press is toggling on/off state, not turning on with press and off with release. To do this, you need something to remember the current state. flip-flop is the easiest solution with only 2 states (on or off).

Buttons 6 & 7 increase/decrease a stored value, so you will need a way to store that value. buffer is probably the easiest solution. Since there are multiple ways to change the buffer value, you need to select between multiple inputs. Each input event is generating a pulse, so select node is probably the easiest to implement.

To disable buttons 6 & 7 when any tool/transport/work are active, we use a ‘gate’ node (changes to button are ignored if gate-EN is false).

There were WAY too many wires crossing over, so I switch to bus nodes (to-bus & from-bus). These are labelled with some meaning (W+T1 is Work on + Tool1 on; !W+T1 is Work off + Tool1 on; !All is everything off; Lift for value of lift servo; etc.)

Note that this is untested, so there could well be errors…

The and/or/not nodes under the flip-flops are translations of your descriptions like Work is on AND tool on is on => W+T1. Each time one of these values changes to true, the select node registers that change from false to true as a pulse and selects the appropriate value. You gave values like “all the way up”, 50, 10, 5, 2, but servo values will be between 0 and 1, so I used 1, 0.5, 0.05, 0.02; adjust as appropriate.

select lift X4 and X5 are bigger and smaller values of current Lift value, so selecting them (pushing buttons 6 or 7) will increase or decrease the lift value. You don’t have to add/subtract 0.1 (or even use the same number for add & subtract); adjust to your needs. Note that a pulse is only generated when switching from false to true, so holding down button 6 or 7 will only change the value once. You must release & press again to continue to change the value. You can change this functionality by replacing the button6/7 code and using a continuously-pausible node:
Turn on the pulsing if everything is off and a button is being pressed (pressing both buttons is going to be a mess…). This will generate a lot of pulses quickly, so you will want to add/subtract very small values if you do this.

Note that there are still several undefined states. For example, there is no way to change throttle while using Tool2 or Tool3. It might make more sense to use POT for throttle if Tool1 is off instead of requiring all tools to be off. Now that you have the general techniques and structure, you should be able to make changes like that on your own.

I conected everything and copied your code but it dosn’t want to work correctly.
I will try to worki it out but these are my first steps with Arduino and programing :slight_smile:
Where did you lern all xod ?
is there any tutorial or online training?

When you launch XOD, there is a link in the workspace for the built-in tutorial. There is also

You don’t specify what “doesn’t want to work correctly” means, so I don’t know what part you didn’t think worked. I changed buttons to tweak-pulse, POT to tweak-number, and servos to watch and it seemed to work to me. The only problem I did notice is that the up/down buttons didn’t limit how high/low the lift values can go. Here I add greater/less and if-else nodes to make sure it doesn’t get bigger than 1 or smaller than 0. You could also use clip nodes instead. If you want to use a single clip node, you could put it between select-lift and buffer.

There are a lot of conditions this doesn’t handle because you did not specify what should happen. For example, if Tool1 is on, this will totally ignore the other tools turning on or off. Throttle changes to POT value when all tools are turned off, but ignores Tool2 or Tool3 getting turned back on. Lift will change if Transport or Tool1 are turned on, but does NOT change when they are turned off. If Tool2 or Tool3 is on when Tool1 is turned off, you cannot even use buttons to change the lift until all tools are turned off. Maybe this is what you want; maybe you need to add more conditions; maybe you need to re-think how you really want it to work. These are things you need to decide since you will be using it; XOD doesn’t care how it works, it just does what it is told (even if you tell it the wrong thing or forget to be explicit enough).

If by “doesn’t work” you mean that nothing happens when you push any of the buttons, there is a chance the buttons are just wired wrong or the port numbers in the button nodes are incorrect. You can put a watch node on each button and verify it goes on/off correctly with each button push/release. Without more information, it is impossible to determine what might be the cause of your problems. For example, if each button is connecting an Arduino pin to +V when pressed, there needs to be a resistor between that pin and GND so Arduino knows for sure when the button is released (or a resistor from the pin to +V if button connects pin to GND). Depending on which way you wire the switch, the XOD button node might read a button press as turning off and a button release as turning on, which is not what the code I have written is expecting. Adding watch nodes and using debug mode can be VERY helpful in determining where the problem starts. Just knowing the end result is wrong doesn’t usually help much in finding the cause of the problem.

I don’t know if this helps, but if you don’t want to measure positions in degrees and convert all angles to radians, you might want to experiment with one of these cool and unique servo items. I used them in a class and a student built an excellent project using two of them.
It’s just like other servos, but it has analog readback! You know how with power off you can by hand move the servos and the mechanisms they control to arbitrary positions? With this, after you do that to one or more servos, your program can read back that position from the servo, which you can save in a variable, or even EEPROM memory.
Then, to return one or all to those same positions, you just read back those servo positions and do analogWrites to have them all move there. Here’s the link; they come in 180 or 270 degree versions.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.