Standard servo hold position

Hi! Please help!

Is it possible for standard servo, controlled by potentiometer, to hold the position?

Potentiometer is gamepads joystick. It returns to center.

I would like the servo to go as the stick, but does not return, so long, until the handle is back in the center. When it is past the center point, the servo would move back as the stick.

My idea is in the picture. I dont know about nodes an connections…

Thank you!!!

I would suggest starting out with a much easier project. Although what you want to do does sound like it should be easy, it is NOT trivial to program. You can’t just say “ignore center position” because letting go of the joystick is going to transition from current position, through other positions, to the center position (and likely bounce beyond center position briefly, causing even more issues). The closest thing I can think of is to record value farthest from center position and use this for servo position so that it ignores transition back to center position, but this means if you move it too far, you would have to got back to center position and retry moving to desired position. As I said, this is not trivial.

It is obvious from your example code that you don’t really understand how XOD works. Starting with the tutorial and working on some simpler programs will cause you a lot less frustration. For starters, POT output will always be between 0 and 1, so it is never going to be less than 0. You are feeding boolean and pulses to the T/F pins of if-else, which is why it is red from type mis-match. You have nothing feeding if-else-COND pin, so the node cannot be doing what you think it will. You are trying to use delay node, but those are only helpful if you know how long to delay. In this case, you want to “wait” until joystick is moved off-center again…there is no way to know how long that will be. You also never send a pulse to delay-SET, so the delay will never start or be active.

I haven’t tested it, but this is a possible solution. It should be closer to functionality you initially requested since it does not depend on remembering min/max values and instead relies on debounce. Debounce will allow ignoring values that are changing (while the joystick is moving), so only values that remain for more than 0.03 seconds will be used (you may need to change this to longer or shorter time for your application). This could actually be a problem if you have a very sensitive POT or shaky hands…

This code also uses a ‘gate’ node to ignore POT output if it is between 0.49 & 0.51 (which should be center position…this may need adjusted for some POTs).

So we read the POT value, make sure it is NOT between 0.49 & 0.51, and ignore any values that change within 0.03 seconds. The pulse-on-change node feeding the buffer updates the buffer any time gate output changes. Buffer is used to control servo position.

If you want something that remembers maximum movement of the joystick until it is returned to center, that is more what I described in my last post and is considerably more complicated.

This still uses debounce to ignore quick changes (like releasing the joystick & having it bounce past center briefly). greater is used to determine which direction the joystick is moving and if we need to save max or min value. between is used to reset our stored value when we leave center position (pulse-on-false will cause select-X2 value to pass to buffer).

The if-else is selecting between max or min value. The select node selects either X1 (the min or max value) or X2 (the center value to ‘reset’ min/max). The defer to the left of select causes X1 to be re-selected each time there is a pulse (so ‘between’ node selecting X2 will only be temporary–this will cause an infinite loop of pulses, which MIGHT cause a problem, but defer node should slow the loop so it is not an issue. Deleting this defer and adding a pulse-on-change between if-else-R and select-S1 should have the same end-result without causing a loop).

pulse-on-change causes buffer to be updated whenever select output changes (which probably means we don’t really need buffer, but it does make it obvious that you are storing some value at this point).

The buffer node is used as servo position, and also goes through defer node so it can loop back up to the top of the program to feed the min/max nodes to compare current value stored with current POT position.

1 Like

Got it!

Will try, THANK YOU!


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