Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

man page updates #41

Open
knoxvillesjoker opened this issue Aug 22, 2020 · 0 comments
Open

man page updates #41

knoxvillesjoker opened this issue Aug 22, 2020 · 0 comments

Comments

@knoxvillesjoker
Copy link

the next key is to remap the accelerometer and stick values into values that the servos can use. There are two value options a pwm signal length (0ish to 2200ish), or an angular reading(0ish.

There is not a clean way to do this built into the library. Nor is there a good remap or constrain function I could easily locate for the need.
The basic remap formula is: new value = ((old value - old min)/(old max - old min))(new max-new min) + new min
The stick has a value range on the nunchuk of 28-220 and we are remapping to the typical servo range of 0-180 degrees. So the formula simplified is: new value = (( old value - 28)/(220-28))
(180 - 0) + 0 = ((old value - 28)/(192))* 180
so if our nunchuk value is a neutral 124 for the x access and has a value name of nstickx and we are going to name the new remapped value as nstickxr, we would have something like this:
nstickr = ((nstickx -28)/(192))*180 (now in the next line lets substitute in the value of 124)
nstickr = ((124-28)/192))*180 = ((96)/192))*180 = 0.5 * 180 = 90 = nstickr
Now if you are not sure that you will always get a non integer value we will need to remap the number as an integer value. That is done with the int() function like so:
nstickri = int(nstickr)
but how can we simplify?
nstickr= int(((nstickx-28)/192))*180)
This works, but, can we simplify the equation and variables any more? Let us try to include the calculations into the readings we actually pull from the data array we are getting from the wiimote with minimal steps. for this case example lets pull the x axis reading on the nunchuk joystick
nunbut=wm.state['nunchuk']; nstick=nunbut['stick']; print(nstick); nstickx=int(((nstick[0]-28)/192)*180); print(nstickx);
that yields a result of (in neutral position):
(124, 129)
90

Now the wiimote accelerometer is a little bit different as it has a max value of 255 (range 0-255.) The accelerometer in it is a true accelerometer in purpose and design and was intended to be used with the IR pointer and a light bar to track cursor movements. Not a good reader of movement, though I might play with a motion plus once I get one to see if I can get better acceleration readings with it.

The wii nunchuk is a little bit different on its accelerometer readings as it is setup as more of a agyroscope position type sensor and as such is better at detecting yaw and pitch changes (x and z values.) the readings range on it seems to vary between 180 and 70
nunbut=wm.state['nunchuk']; nacc=nunbut['acc']; print(nstick); naccx=int(((nacc[0]-70)/110)*180); print(naccx);
And this yields:
(76, 104, 100)
9

And who thought that after highschool and college that they would no longer be doing polynomial math?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant