Hi All,
I’m looking for some help and will pay money for the help in creating a Sketch that covers the following.
I have.
2 10k pots
1 Nema 34 Bipolar Stepper Motor
1 MA860H Stepper Driver
1 Power supply
1 Ardunio Uno
3 Click Buttons
3 Resistors
wires etc
Layman understanding of Logic control and perameters not really Arduino related
Steps to Take per step CW or Step CCW = 50
Button 0 settings
RPM range / 250
Map range / (val 0, 1023, 0, 1023 )
Analog Resolution / 5
Delay Factor / 5
Button 1
RPM range / 150
Map range (val 0, 1023, 255, 767 )
Analog Resolution / 10
Delay Factor / 5
Button 2
RPM range / 50
Map range (val 0, 1023, 383, 640 )
Analog Resolution / 15
Delay Factor / 5
Logic path predicted based on button 1 being active selection
Step 1# Read PotA ( Value is ? out of 1023 )
Step 2# Read Which Button is active ( 0, 1, 2 )
Step 3# If button (1) is active then use map range (val 0, 1023, 255, 767 )
Step 4# Convert PotA value of ? to new map value.
Step 5# Check active buttons Analog Resolution ammount = (10)
Step 6# Read PotB.
Step 7# Compare PotA mapped value to PotB.
Step 8# Check if they are within the (10) digits of each other.
Step 9# If yes. Do nothing and run loop again from step 1.
Step 10# If No. Find out how much that value is.
Step 11# Take the Value and Multiply By ( Steps to Take ) to increase frame range of movement.
Step 11# Find out if it’s higher or Lower than PotA value.
Step 12# Send signal to Move Frame
Step 13# Take ammount of Steps and multiply by delay factor before starting loop again.
Arduino Sketch Something like this (But with correct language code if below is wrong?)
// Generic for all 3 options
int StepsToTake = 50; // Ammount of Steps to take per analog reading missmatch
// Low Setting
int LowRPM = 250; // RPM Value of Stepper Motor
int LowTrack = map ( 0, 1023, 0, 1023 ); // limiting physical range of frame to 1:1.
int LowRes = 20; // Amount of difference between PotA & PotB before stepper action is taken.
int LowPosAtoB = 3 // Amount of delay factor waiting for stepper to go from point A-B
// Med Setting ( This will be used in this example )
int MedRPM = 150; // RPM Value of Stepper Motor
int MedTrack = map ( 0, 1023, 255, 767 ); // limiting physical range of frame to 1:2.
int MedRes = 10; // Amount of difference between PotA & PotB before stepper action is taken.
int MedPosAtoB = 2 // Amount of delay factor waiting for stepper to go from point A-B
// High Setting
int HighRPM = 50; // RPM Value of Stepper Motor
int HighTrack = map ( 0, 1023, 383, 640 ); // limiting physical range of frame to 1:4.
int HighRes = 5; // Amount of difference between PotA & PotB before stepper action is taken.
int HighPosAtoB = 1 // Amount of delay factor waiting for stepper to go from point A-B
What should happen step by step in detail
-
Upon powering up there are 3 buttons. These buttons labelled Low, Med, High. When pressed define a range of numbers to be used later in the sketch. These Values will be used later for tweaking the physical functionality of the hardware. These setting should be the only thing adjusted within the sketch if possible ( assuming the rest of it is working ok ). The button could be pressed any time after power up so will need to be checked per loop. For the example and figures below I am going to imagine what should or could happen if the button was on the Medium Setting.
-
The first Potentiometer is within a hand held controller and adjustable. The knob is dampened so that it can’t be turned really quickly. It could take a second or two to fully rotate the knob within it’s 0-1023 range. This will be automated when final tweaking is complete and therefore automated in future, hence the reason for PotB.
-
The second Potentiometer is attached to a sliding frame that moves forwards and backward within a set physical range, giving an analog signal positional feedback from (0-1023) from full backwards to forward positions as per usual. ( Centre position would be calibrated to (512.5) )
-
The stepper is attached to the frame and drives the frame forwards and backwards, this done under instruction from the Sketch-Driver. The stepper motor is attached to a slip clutch so under heavy quick loads may slip or loose it’s position count. ( 2nd Reason for PotB )
-
If PotA analog raw reading from hand jog controller, for example is 247 out of the full 1023 range. The following int on button 1 should be called up “int = MedTrack map ( 0, 1023, 255, 767 );” in order to define a new figure.
1023 mapped and seen as a percentage is 10.23 positions per 1% so (247) potA reading is equal to 24.14% of the full range.
So if the Medium mapping is between (255 & 767) then this has a full range of only 512 within the (255, 767) range. And should if I’m correct give a figure where by it’s centre position is still 512 but the conversion dulls the amount of movement PotB needs to take to follow the figure, therefore keeping the frame centrally biased regardless of the map value.
So if 24.14% of the 512 range should give a new PotA position of (379) which means the frame will need to move a shorter amount from centre to match the PotA & PotB figures as per step 8.
It needs to work this way rather than just reduce the pot value by a fraction as I need the frame to be central when the PotA is central. if I just divide the 1023 value and apply this to the code the frame will be biased to the low end as the value isn’t relative to the central position.
-
In a bid to stop the Stepper jumping around trying to match PotA and PotB values perfectly within the (0-1023) range there needs to be some code that reduces the resolution of the (0-1023) signal so as to compare the values for our example in 10’s not 1’s, effectively having 102 positions. This figure should be adjustable via the button option as above ( int MedRes = 10; ) By increasing or decreasing the int MedRes figures I can compensate for the Mapping value changes from the Pot’s.
-
If PotA and PotB are within the same ( int MedRes = 10 ); value then it shouldn’t move the Motor. PotA might be the converted figure as per step 5) at (372), PotB might be (376) but the MedRes values are still within the Med set 10 range ( 5 either side of PotA ) and so don’t need to move.
8.) If PotA and PotB are however different, say PotA now reads (405) and potB still reads (376) then this difference should be converted and an appropriate signal of steps should be sent to the driver.
-
When the Stepper moves the frame assuming it hasn’t slipped on the way and PotB now matches the PotA figure of (405) or within 5 either way, PotA is read again and if still within the 10 signal reading it doesn’t move as per step 7). If it isn’t the same because PotA has moved again whilst the stepper has been moving then it repeats Step 8.
-
To allow the motor to “get there” an appropriate delay should be put in place after it sets off. This delay value should dynamically adjust based on how far PotA is to PotB and the motor needs to move. So under Medium settings if it needs to take 500 steps to get from A-B then the delay could be perhaps the step figure of 500 multiplied by the ( int MedPosAtoB = 2 ) so 1000 microseconds if it needs to travel 500 steps
Hopefully this will stop or at least minimise stuttering when it’s in motion as the programme loops and takes another reading from PotB to soon?
To consider are:
These values will be tweaked when the hardware is assembled as this part is not an exact science yet and timing, steps ect won’t be known…
Attachments:
1 wiring diagram showing my current board layout and current pin formation.
Cheers
Jason.