Go to Post Achieving a goal by merely finishing, or reaching mediocrity is not acceptable; Excellence is the only satisfactory result. - AdamHeard [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-16-2018, 11:47 AM
spyguy518 spyguy518 is offline
Registered User
FRC #2147 (CHUCK)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2015
Location: Spokane
Posts: 4
spyguy518 is an unknown quantity at this point
Exclamation Arduino Linear Actuator Joystick Control - Please Help

I am a programmer working on a project involving an Arduino Mega 2560, a Microsoft Sidewinder Force Feedback 2 Joystick, and a Firgelli Automations OS Series linear actuator.

My goal is to create a program that will move the actuator a particular distance, based on the position of the joystick.

I have successfully written functions to extend and retract the actuator a specified distance. But, I am having issues with joystick integration.

The readings from the potentiometers on the joystick are not steady, causing the actuator to be jumpy. I have attempted to write a code so that the actuators only move if the joystick has moved past a certain threshold from its previous position. The issue that I am running into is that the joystick value is constantly being updated by the loop, so there is never a big enough separation between the previous and current values to cause the actuator to move.

Does anybody have any ideas as to how to write a threshold code that will work like this? Preferably without using PID control.

Any help would be much appreciated!
Reply With Quote
  #2   Spotlight this post!  
Unread 03-16-2018, 01:58 PM
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Mentor
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 5,649
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Arduino Linear Actuator Joystick Control - Please Help

Save the last value you actually set the position to, and use that to detect change.

Something like:

Code:
int lastpos=-999; // erroneous value more than thresh away from any realistic value
int thresh=20;

loop()
{
    int currpos=joystick.get();
    if abs(currpos-lastpos) > thresh {
        lastpos=currpos;
    }
    actuator.set(lastpos);
}
Another way to stabilize the joystick without losing minor changes held for a long time is to keep a running, decaying average:

Code:
int avgpos=-999; // erroneous value for avgpos which succeeds if statement below
int weight=0.1;

loop()
{
    int currpos=joystick.get();
    if (avgpos < -1) { // first pass only
        avgpos = curpos;
    } else {
        avgpos = avgpos * (1-weight) + currpos * weight;
    }
    actuator.set(avgpos);
}
This last bit of code averages out the "recent" joystick positions. After it stabilizes, the most recent is weighed 0.1, the one before it 0.09, the ones before that 0.081, 0.0729, 0.06561, and so forth, each preceding point weighed 90% of the previous one. A larger weight will result in faster tracking; a smaller weight in less jitter. A weight of one is no jitter control at all; a weight of zero will always use the first value.

OBTW, both examples assume that the scales of joystick.get() and actuator.set() are the same; otherwise some rescaling is required.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 03-16-2018 at 02:11 PM.
Reply With Quote
  #3   Spotlight this post!  
Unread 03-16-2018, 02:25 PM
ARaulinaitis ARaulinaitis is offline
Registered User
FRC #4999 (Momentum Robotics)
Team Role: Mentor
 
Join Date: Jan 2018
Rookie Year: 2015
Location: Long Beach, CA
Posts: 146
ARaulinaitis is just really niceARaulinaitis is just really niceARaulinaitis is just really niceARaulinaitis is just really nice
Re: Arduino Linear Actuator Joystick Control - Please Help

Quote:
Originally Posted by GeeTwo View Post
OBTW, both examples assume that the scales of joystick.get() and actuator.set() are the same; otherwise some rescaling is required.
Since he's on an Arduino, it has a built-in map() function.
__________________
Don't limit others to the level of your own creativity.

Spec sheets are your friend.

A problem that you don't want to solve is an opportunity to better yourself.
Reply With Quote
  #4   Spotlight this post!  
Unread 03-16-2018, 02:40 PM
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Mentor
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 5,649
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Arduino Linear Actuator Joystick Control - Please Help

Quote:
Originally Posted by ARaulinaitis View Post
Since he's on an Arduino, it has a built-in map() function.
I had almost forgot about this because I never used this function; it didn't do the integer math right when I started using Arduinos about six years ago. I see now that it was fixed in 2014.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #5   Spotlight this post!  
Unread 03-16-2018, 02:49 PM
ARaulinaitis ARaulinaitis is offline
Registered User
FRC #4999 (Momentum Robotics)
Team Role: Mentor
 
Join Date: Jan 2018
Rookie Year: 2015
Location: Long Beach, CA
Posts: 146
ARaulinaitis is just really niceARaulinaitis is just really niceARaulinaitis is just really niceARaulinaitis is just really nice
Re: Arduino Linear Actuator Joystick Control - Please Help

Quote:
Originally Posted by GeeTwo View Post
I had almost forgot about this because I never used this function; it didn't do the integer math right when I started using Arduinos about six years ago. I see now that it was fixed in 2014.
It's annoying because there's no map() function for floats, so you either have to overload it, or just copy/paste their map equation to a new function and just change ints to floats.

It's pretty useful, especially when converting analog inputs to some sort of output
__________________
Don't limit others to the level of your own creativity.

Spec sheets are your friend.

A problem that you don't want to solve is an opportunity to better yourself.
Reply With Quote
  #6   Spotlight this post!  
Unread 03-16-2018, 05:17 PM
spyguy518 spyguy518 is offline
Registered User
FRC #2147 (CHUCK)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2015
Location: Spokane
Posts: 4
spyguy518 is an unknown quantity at this point
Re: Arduino Linear Actuator Joystick Control - Please Help

Quote:
Another way to stabilize the joystick without losing minor changes held for a long time is to keep a running, decaying average
Thanks for your help, I will test it out and see how it works. I was also thinking about wiring a capacitor into the circuit to stabilize the readings electrically. Thoughts?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 07:09 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi