cylon-gpio icon indicating copy to clipboard operation
cylon-gpio copied to clipboard

Servos will not switch directions when using a Spark Core

Open occasl opened this issue 11 years ago • 9 comments
trafficstars

I'm trying to write a simple cylon.js program to make a nodebot spin around in circles and alternating directions every second. With the program below I get it to spin, but it will not alternate directions. The output in the console shows that it is attempting to switch the servos cw/ccw but the nodebot continues to go in one direction.

Thinking something was up with my servos, I verified this worked with JohnnyFive so I'm not sure why cylon.js won't work.

Any ideas?

var Cylon = require('cylon');

// Initialize the robot
Cylon.robot({
    connection: {
        name: 'voodoospark',
        adaptor: 'voodoospark',
        accessToken: process.env.SPARK_TOKEN,
        deviceId: process.env.SPARK_DEVICE_ID,
        module: 'spark'
    },
    device: [
        { name: 'leftwheel', driver: 'continuous-servo', pin: 'D0' },
        { name: 'rightwheel', driver: 'continuous-servo', pin: 'D1' }
    ],

    work: function (my) {
        var cw = true;

        // turn right
        my.devices.leftwheel.clockwise();
        my.devices.rightwheel.counterClockwise();

        every((1).second(), function () {
            if (cw) {
                my.devices.leftwheel.counterClockwise();
                my.devices.rightwheel.clockwise();
                cw = false;
            } else {
                my.devices.leftwheel.clockwise();
                my.devices.rightwheel.counterClockwise();
                cw = true;
            }
        });
    }
}).start();

occasl avatar Sep 06 '14 16:09 occasl

Somehow, I just noticed this issue. Sorry about the delayed response @occasl perhaps @edgarsilva can check this one? It is still a problem?

deadprogram avatar Feb 16 '15 01:02 deadprogram

Will add the necessary code, sorry for the late response.

edgarsilva avatar Jul 09 '15 22:07 edgarsilva

I've just run into this issue as well with a Particle Photon. rotate('clockwise') works fine, but rotate('counter-clockwise') does nothing.

@edgarsilva any update?

ericterpstra avatar Aug 29 '15 16:08 ericterpstra

@ericterpstra haven't had a chance to check it out, will try to make some time this weekend and fix up, must be that the value is not low enough to make it counter-clockwise. Two things, can you provide the servo model you are using so I can check the pulse-width values.

In the meantime you can try to use the servo driver which accepts values from 0-180, that way you can test that passing a value between 0-89 makes the servo rotate counter-clockwise. 89 is the default value in continues-servo driver maybe an 80?

That would give you enough flexibility to test your code. I will check it out myself and try to post an update this weekend.

edgarsilva avatar Aug 29 '15 17:08 edgarsilva

@ericterpstra an example using servo driver:

https://github.com/hybridgroup/cylon-firmata/blob/master/examples/servo/servo.js#L25

edgarsilva avatar Aug 29 '15 17:08 edgarsilva

@edgarsilva Thanks for the quick reply! I fiddled with the continuous-servo.js module and set the non-clockwise value to 0, which got it working.

Using your example code above, the servo puttered along ccw at 60, then at 40 or below worked normally. Testing on my own, anything from 0-40 worked ok.

My servo model is: SpringRC SM-S4303R

ericterpstra avatar Aug 29 '15 17:08 ericterpstra

@ericterpstra that's great! do you wanna submit a PR? I can merge afterwards, then the only issue is that the lower the value the faster it goes backwards, we have it setup for 89 which as you mentioned is not enough for it to spin backwards.

Let me know, if you are otherwise busy I'll fix the code later today.

edgarsilva avatar Aug 29 '15 18:08 edgarsilva

@ericterpstra Thanks for the fix. That's what I was looking for the last couple of days. But after applying your fix, I can't get it work the "stop" method for continuous servo. Do you have any ideas? Do you have any problems on your side with the stop method?

goeker avatar Aug 31 '15 05:08 goeker

@goeker have you tried the full range of values with the servo driver? same as @ericterpstra did to check what values made his servos go backwards and stop, that might help figure out what the range for your servos is. I can arrange for custom thresholds to be passed to the driver after we have some sensible defaults.

edgarsilva avatar Aug 31 '15 14:08 edgarsilva