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

TypeError: keyFrames.map is not a function #1499

Closed
arindamghoshal opened this issue Sep 2, 2018 · 14 comments
Closed

TypeError: keyFrames.map is not a function #1499

arindamghoshal opened this issue Sep 2, 2018 · 14 comments

Comments

@arindamghoshal
Copy link

Not sure what I am doing. I am getting this error while animating servos based on the code in eg/phoenix.js. I am trying to animate 4 legs. Attached is the code file. The error gets triggered while executing bot.sleep(); [line 109 in the attached file]

TypeError: keyFrames.map is not a function
at Servo.(anonymous function) [as @@normalize] (/home/pi/projects/quadBot/node_modules/johnny-five/lib/servo.js:346:20)
at Servos. (/home/pi/projects/quadBot/node_modules/johnny-five/lib/servo.js:646:46)
at Array.map ()
at Servos.(anonymous function) [as @@normalize] (/home/pi/projects/quadBot/node_modules/johnny-five/lib/servo.js:620:22)

index.js.zip

@dtex
Copy link
Collaborator

dtex commented Sep 2, 2018

Hmmm, it looks like you've properly written your code to handle just four legs so the problem doesn't jump out at me. I'll have to some hardware from the lab this afternoon to run the code (and console.log a lot).

One thing does jump out at me, though it has nothing to do with your current issue... I've never successfully controlled multiple servos at a high rate of speed over I2C. I think there is some limit as to how fast those messages can be sent, and even though the PCA9685 can receive instructions for multiple servos in one message, we are only sending one at a time from Johnny-Five.

Also, there is a newer, better way to control walking robots. It's not as well documented (there is no book to go with it), but https://github.com/dtex/tharp uses an inverse kinematics layer on top of Johnny-Five to make controlling the robot much easier (and dynamic).

I guess I really only need an Arduino to run the code with little modification. I'll see if I can replicate the error.

@arindamghoshal
Copy link
Author

Thanks @dtex. I will look into https://github.com/dtex/tharp library.

@dtex
Copy link
Collaborator

dtex commented Sep 3, 2018

I was able to replicate. Still investigating.

@dtex
Copy link
Collaborator

dtex commented Sep 3, 2018

We have a collection of a collection of servos. Your code (like mine) expects the coxa, femur, tibia collections to all be passed the same value so we should be normalizing them using the Servo normalize method instead of the Servos normalize method. For some reason they are being normalized as Servos even though we have insufficient keyFrames (which is why the error is being thrown).

I changed the sleep object to this dirty hack and it got past the error:

const sleep = {
        target: bot.joints,
        duration: 500,
        cuePoints: [0, 0.5, 1.0],
        fps: 100,
        oncomplete: function() {
            bot.state = "sleep";
        },
        keyFrames: [
            [
                [null, false, { degrees: 45, easing: easeOut }],
                [null, false, { degrees: 45, easing: easeOut }],
                [null, false, { degrees: 45, easing: easeOut }]
            ],
            [
                [null, { degrees: 136, easing: easeInOut }, { degrees: 180, easing: easeInOut }],
                [null, { degrees: 136, easing: easeInOut }, { degrees: 180, easing: easeInOut }],
                [null, { degrees: 136, easing: easeInOut }, { degrees: 180, easing: easeInOut }]
            ],
            [
                [null, { degrees: 120, easing: easeInOut }, { step: 60, easing: easeInOut }],
                [null, { degrees: 120, easing: easeInOut }, { step: 60, easing: easeInOut }],
                [null, { degrees: 120, easing: easeInOut }, { step: 60, easing: easeInOut }]
            ]
        ]
    };

Unfortunately it just hit another error so it really needs to be fixed properly. I'm going to try some old versions of Johnny-Five and see if I can find where we stopped getting the expected behavior.

@dtex
Copy link
Collaborator

dtex commented Sep 3, 2018

It broke at v0.10.1 so if you roll back to v0.10.0 it should work. I'll get to work on the real fix.

@dtex dtex self-assigned this Sep 3, 2018
dtex added a commit to dtex/johnny-five that referenced this issue Sep 11, 2018
If an array of keyFrames are passed to Servos, those keyFrames should be used as values for the whole collection and should not be normalized as a keyFrameSet.
dtex added a commit to dtex/johnny-five that referenced this issue Sep 11, 2018
If an array of keyFrames are passed to Servos, those keyFrames should be used as values for the whole collection and should not be normalized as a keyFrameSet.
dtex added a commit to dtex/johnny-five that referenced this issue Sep 11, 2018
If an array of keyFrames are passed to Servos, those keyFrames should be used as values for the whole collection and should not be normalized as a keyFrameSet.
@dtex
Copy link
Collaborator

dtex commented Sep 11, 2018

Hi @arindamghoshal

I think I have a fix for you at this PR. It passes unit tests, but I'd really appreciate real world testing if you have a chance.

@arindamghoshal
Copy link
Author

Thanks, @dtex. Happy to test on my bot which is still work in progress.

@arindamghoshal
Copy link
Author

arindamghoshal commented Sep 14, 2018

I took the updated servo.js and tested the same code. Received a different error in animation.js

/home/pi/projects/quadBot/node_modules/johnny-five/lib/animation.js:473
calcValue = this.target[Animation.keys].reduce(function(accum, key) {
^

TypeError: Cannot read property 'reduce' of undefined
at Animation. (/home/pi/projects/quadBot/node_modules/johnny-five/lib/animation.js:473:49)
at Array.map ()
at Animation.tweenedValue (/home/pi/projects/quadBot/node_modules/johnny-five/lib/animation.js:422:41)
at Animation.loopFunction (/home/pi/projects/quadBot/node_modules/johnny-five/lib/animation.js:293:38)
at Immediate.processQueue (/home/pi/projects/quadBot/node_modules/temporal/lib/temporal.js:195:20)
at runCallback (timers.js:693:18)
at tryOnImmediate (timers.js:664:5)
at processImmediate (timers.js:646:5)
at process.topLevelDomainCallback (domain.js:121:23)

@dtex
Copy link
Collaborator

dtex commented Sep 15, 2018

Okay, thanks. I'm able to replicate. Need to figure out why my tests are working and this is not. Will keep you posted.

@dtex
Copy link
Collaborator

dtex commented Sep 15, 2018

Ah, my tests only checked the keyframe normalization, not the rendering. I see the cause of this new error now and am working on a solution.

dtex added a commit to dtex/johnny-five that referenced this issue Sep 15, 2018
If an array of keyFrames are passed to Servos, those keyFrames should be used as values for the whole collection and should not be normalized as a keyFrameSet.
dtex added a commit to dtex/johnny-five that referenced this issue Sep 15, 2018
If an array of keyFrames are passed to Servos, those keyFrames should be used as values for the whole collection and should not be normalized as a keyFrameSet.
@dtex
Copy link
Collaborator

dtex commented Sep 15, 2018

Okay, it's good for another go. I've updated servo.js again. Servo animation was originally crafted to receive keyFrame values with the property degrees, but was changed to expect the more generic property value. I was catching that in the normalization method for a single Servo, but not a collection of Servos.

@arindamghoshal
Copy link
Author

Just ran the same code, the servos are reacting good. No more errors. My movement degrees are off, which I need work on. Thanks @dtex.

@dtex
Copy link
Collaborator

dtex commented Sep 15, 2018

This is great news. This issue will close when I land that PR. I want to add some tests and bump the version so it'll be a couple of days, but keep an eye out for version 1.0.1.

Best of luck with your bot. Oh, and please share video(s) when you get it up and running. Nothing makes us happier than seeing nodebots.

dtex added a commit to dtex/johnny-five that referenced this issue Sep 16, 2018
If an array of keyFrames are passed to Servos, those keyFrames should be used as values for the whole collection and should not be normalized as a keyFrameSet.
dtex added a commit to dtex/johnny-five that referenced this issue Sep 16, 2018
If an array of keyFrames are passed to Servos, those keyFrames should be used as values for the whole collection and should not be normalized as a keyFrameSet.
dtex added a commit to dtex/johnny-five that referenced this issue Sep 16, 2018
If an array of keyFrames are passed to Servos, those keyFrames should be used as values for the whole collection and should not be normalized as a keyFrameSet.
rwaldron pushed a commit that referenced this issue Sep 18, 2018
If an array of keyFrames are passed to Servos, those keyFrames should be used as values for the whole collection and should not be normalized as a keyFrameSet.
@dtex
Copy link
Collaborator

dtex commented Sep 22, 2018

The fix has landed

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

No branches or pull requests

2 participants