[quote=“BrandonM”]Moving the initialization (
dup 0 servo) just inside of the main loop should not have any impact on the tracking since it is the same line of code that is at the end of the loop. That line of code reads the target value stored on the stack and updates the servo with that target, so moving it inside of the loop just sends the servo the same target position twice.
Can you post a video showing the behavior of your system? Do you have a standard servo (instead of a 4-turn servo) that you could try? Do you have any speed or acceleration limits set on your servo channel? Have you changed the Min and Max pulse width values in the “Channel Settings” tab of the Maestro Control Center? Can you post your Maestro settings file? You can save your settings file by selecting the “Save settings file…” option within the “File” drop-down menu in the Maestro Configuration Utility.
To understand that part of code, it is important to know that at this point in the script, there are two values already on the stack: the target position and the error (which is the difference in the sensor readings). For example, if this is the first time through the code and the error between the sensors is -200, the stack would looks like this:
dup -120 less_than if line of code is duplicating the top value of the stack (-200 in this example) and comparing it to -120. Since -200 is less than -120, the if statement will run. If it was not, it would skip down to
endif. Also, since the error value was duplicated before being compared to the -120 threshold, the stack will be unchanged after running that line of code. The next line,
swap dup 3600 greater_than if swaps the position of the two values on the stack, then duplicates the top value (now 6000) and compares it to 3600. If the target value (6000) is greater than 3600, it will subtract 5 from it, creating a new target value of 5995. Note that the target does not get updated if it is less than 3600, which limits the target to a minimum of 3600. This value was found experimentally to be the minimum pulse width accepted by the servo I used. Also note that the script uses units of quarter microseconds, so this translates into a pulse width of 900us.
Thanks for explaining the code I needed it , I think I found the problem , I had set the threshold low ( -60 to -80 ) and this was causing it to move from the noise causing it to trigger , it would go to MAX or MIN then it must have gotten lost while in that position , this caused it to reverse for some reason. Probably a math in the stack issue.
After changing the threshold back to 140 , -140 it seems to be ok now , There is quite a bit of noise on the analog ch. I am going to try a cap on the sensor to smooth out the noise some. I was trying to increase the sensitivity for objects further away , the material the the sensor sees has a ALOT to do with how it functions , I am thing about getting some Ultrasonic sensors to try later .
OK I just made it go to one extreme and it sat there now it will not center now ( when triggered it goes all the way to the opposite extreme. It does this on 1 turn or 4 turn motors.
It SNAPS back and forth ,