hybridgroup / cylon-gpio

Cylon drivers for GPIO devices
http://cylonjs.com
Other
19 stars 14 forks source link

Servos will not switch directions when using a Spark Core #33

Open occasl opened 10 years ago

occasl commented 10 years ago

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();
deadprogram commented 9 years ago

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

edgarsilva commented 9 years ago

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

ericterpstra commented 9 years ago

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?

edgarsilva commented 9 years ago

@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 commented 9 years ago

@ericterpstra an example using servo driver:

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

ericterpstra commented 9 years ago

@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

edgarsilva commented 9 years ago

@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.

goeker commented 9 years ago

@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?

edgarsilva commented 9 years ago

@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.