electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Acceleration data overwhleming? (using OSCulator with Chuck)
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Digital Larry



Joined: Feb 19, 2013
Posts: 17
Location: Silicon Valley, CA

PostPosted: Sun Nov 20, 2016 2:04 pm    Post subject: Acceleration data overwhleming? (using OSCulator with Chuck)
Subject description: Wiimote
Reply with quote  Mark this post and the followings unread

I posted this initially at the OSCulator forum.

I've written some Chuck code to connect a Wiimote with OSC using OSCulator. In some places I am tracking button presses and doing various things like toggle a variable every time I press the key, or just flip the variable when the key is held down, but restore it when I release the key. I find that the code works unreliably unless I turn off the wii/remote/1/accel/pry group of messages. If those are turned off then it behaves as I expect. If I turn them on, then my code works only one out of every several presses, but the pattern is not repeatable.

I think that every Wiimote button press or release sends 2 identical messages. parameter = 1.0 for button down and 0.0 for button up.

Any ideas as to how to make this more reliable? Because as it stands, it is not usable for performance if it only works every 2nd or 3rd time.

Chuck is running on a Macbook Air with OS/X 10.9.5.

Here's my Chuck code.

Code:

// OSC variables
// Listen for all incoming messages on port




OscIn oin; // make an OSC receiver
6449 => oin.port; // set port #
oin.listenAll(); // any message at all

OscMsg omsg; // message holder
// OSC msg catch and parsing loop

float f;
0 => int id;
0 => int buttonB;
0 => int buttonA;
0 => int button1;
0 => int button2;
0 => int buttonLEFT;
0 => int buttonUP;
0 => int buttonRIGHT;
0 => int buttonDOWN;

// <<< "About to", "proc" >>>;
procOSCMsgs();

float pitchLast, rollLast, yawLast, accelLast;

fun void procOSCMsgs () {
    while(true) {
        oin => now; // wait for any OSC
        if(oin.recv(omsg))
        {
            // <<< "got message:", omsg.address, omsg.typetag >>>;

            if(omsg.address == "/wii/1/button/Up") {
                if(omsg.typetag == "f") {
                    omsg.getFloat(0) => f;
                    if((1.0 == f) && (buttonUP == 0)) {
                        1 => buttonUP;
                        // project9.muteIt(2, buttonUP);
                    }
                    if((0.0 == f) && (buttonUP == 1)) {
                        0 => buttonUP;
                    }
                    // <<< "Button UP:", buttonUP >>>;
                }
            }
            else if(omsg.address == "/wii/1/button/Down") {
                if(omsg.typetag == "f") {
                    omsg.getFloat(0) => f;
                    if((1.0 == f) && (buttonDOWN == 0)) {
                        // <<< "Argument", f >>>;
                        1 => buttonDOWN;
                    }

                    if((0.0 == f)) {
                        // <<< "Argument", f >>>;
                        0 => buttonDOWN;
                    }
                    // <<< "Button DOWN:", buttonDOWN >>>;
                }
            }
            else if(omsg.address == "/wii/1/button/Left") {
                if(omsg.typetag == "f") {
                    omsg.getFloat(0) => f;
                    if((1.0 == f) && (buttonLEFT == 0)) {
                        // <<< "Argument", f >>>;
                        1 => buttonLEFT;
                    }
                    if((0.0 == f)) {
                        // <<< "Argument", f >>>;
                        0 => buttonLEFT;
                    }
                }
            }
            else if(omsg.address == "/wii/1/button/Right") {
                if(omsg.typetag == "f") {
                    omsg.getFloat(0) => f;
                    if((1.0 == f) && (buttonRIGHT == 0)) {
                        // <<< "Argument", f >>>;
                        1 => buttonRIGHT;
                    }
                    if((0.0 == f) && (buttonRIGHT == 1)) {
                        // <<< "Argument", f >>>;
                        0 => buttonRIGHT;
                    }
                }
            }
            else if(omsg.address == "/wii/1/button/B") {
                if(omsg.typetag == "f") {
                    omsg.getFloat(0) => f;
                    <<< "Button B", f >>>;
                    if((1.0 == f) && (buttonB == 0)) {
                        <<< "Button B", "down" >>>;
                        1 => buttonB;
                        // project9.preset1();
                    }
                    if((0.0 == f) && (buttonB == 1)) {
                        <<< "Button B", "up" >>>;
                        0 => buttonB;
                    }
                }
            }
            else if(omsg.address == "/wii/1/button/A") {
                if(omsg.typetag == "f") {
                    omsg.getFloat(0) => f;
                    // <<< "Button A", f >>>;
                    if((1.0 == f) && (buttonA == 0)) {
                        <<< "Button A", "Down" >>>;
                        1 => buttonA;
                    }
                    if((0.0 == f) && (buttonA == 1)) {
                        <<< "Button A", "Up" >>>;
                        0 => buttonA;
                    }
                }
            }
            else if(omsg.address == "/wii/1/button/1") {
                if(omsg.typetag == "f") {
                    omsg.getFloat(0) => f;
                    if((1.0 == f) && (button1 == 0)) {
                        <<< "Argument", f >>>;
                        1 => button1;
                    }
                    if((0.0 == f)) {
                        <<< "Argument", f >>>;
                        0 => button1;
                    }
                }
            }
            else if(omsg.address == "/wii/1/button/2") {
                0 => int button;
                if(omsg.typetag == "f") {
                    omsg.getFloat(0) => f;
                    if((1.0 == f) && (button == 0)) {
                        <<< "Argument", f >>>;
                        1 => button;
                    }
                }
            }
            else if(omsg.address == "/wii/1/accel/pry") {
                // <<<omsg>>>;
                omsg.getFloat(0) => float pitch;
                omsg.getFloat(1) => float roll;
                omsg.getFloat(2) => float yaw;
                omsg.getFloat(3) => float accel;

                (pitch - pitchLast) => float pitchDiff;

                if(Math.fabs(pitchDiff) > 0.08) {
                    pitch => pitchLast;
                }

                (roll - rollLast) => float rollDiff;

                if(Math.fabs(rollDiff) > 0.16) {
                    roll => rollLast;
                    // <<< "-------- Roll:", roll >>>;
                }
            }
        }
    }
}

Last edited by Digital Larry on Tue Nov 22, 2016 6:15 am; edited 1 time in total
Back to top
View user's profile Send private message
Digital Larry



Joined: Feb 19, 2013
Posts: 17
Location: Silicon Valley, CA

PostPosted: Mon Nov 21, 2016 10:42 am    Post subject: Reply with quote  Mark this post and the followings unread

I used the Mac/Linux command:

nc -ul 6449

to listen for any incoming UDP datagrams on port 6449.

They just come spewing in really rapidly, although currently I don't have any objective measurement for bytes or messages per second.

If I reduce my program to simply printing a message whenever an accelerometer message is received, they come out a few times a second but it seems somewhat herky-jerky and nowhere nearly as fast as my nc test.

I might see if I can get some UDP listener code in C and add something to sort/time/count messasges.

So far, this seems to suggest that Chuck's input queue for OSC is not able to keep up with the rate of incoming messages. I also added an initial check/counter to only process every "nth" accel/pry message but it did not seem to make any difference.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use