So I’ve been struggling with the servo slider bar on the Look around cat panel of the iPad Makeblock app. It seemed that whenever I was trying to get the servo to align with the iPad slider bar, it would do the opposite. I checked and rechecked my configuration and, to no avail, I could not get it to work.
So i looked at the code for the slider bar:
This code assumes that the slider value’s range just needs to be converted from 100 to 90 and that you just need to add 90 to correct where the servo counts from.
However, it neglects that the servo counts differently from the slider. The servo starts at 0 (which is the slider’s right 100%) and works its way through to 90 (which is the slider’s 0%) and through to 180 (which is the slider’s left -100%). So the code has to account for those negative slider values as increases in the servo’s angle value and those positive slider values as decreases in the servo’s angle value, trending towards 0 as the slider approaches 100%.
I’ve done an attempt to correct the code (I avoided floating point calculations by multiplying by 90 degrees and dividing by 100%) by putting in a test for negative slider values, converting the result to a positive ratio, and adding it to the servo’s 90 degrees (slider’s zero). I then did the same for positive and null slider values, subtracting them from the servo’s 90 degrees.
It seems to work. Hope it helps.