Closed neonag closed 10 years ago
Have you seen this example?
http://cylonjs.com/documentation/examples/cylon/js/leap_arduino/
hi Solojavier yeah worked on it and worked fine .. but i am not able to take it to the next step ... i want to make use of pitch and roll to control leds but not able to do stuck with lots of confusions on how to take a data .. for e.g. just using the hand pitch i.e, if i move my hand downward one lead should switch on and backward another should switch on
@stewart could you provide some information about the data returned by leap? I don't have a leap motion available with me right now.
Hey @neonag. For the cylon-leapmotion
adaptor, we just pass through the data we get from Leap Motion's own LeapJS adaptor. A good place to start for figuring out how to parse the data is their own docs.
So, for example, if you had a Cylon program like this:
var Cylon = require('cylon');
Cylon.robot({
connection: { name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437' },
device: { name: 'leapmotion', driver: 'leapmotion' },
work: function(my) {
my.leapmotion.on('hand', function(hand) {
// your hand processing here
});
}
}).start();
Inside that block, hand
is an instance of the Hand
class in the Leap docs. So you could probably use something like hand.pitch()
to get the current state of your hand.
Please let me know if you have any more questions, but hopefully those LeapMotion docs can get you on the right track.
Has this issue now been addressed?
hi yeah i have solved this issue thnx stewart and solojavier ... things are working fine with the led but when i use the motor in place of leds with l293d the motors are not running properly even after giving 9v external supply for those motors :(
Perhaps you can share your schematic, cause it sounds like possible miswiring?
it works fine if i make the program run on individual motor but when both motors are used to control then it gets no power no idea why :(
At first glance, looks like pin 16 should be +5V. This article shows how to wire up an L293D http://www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/
hey i got the solution .. the problem was only a new 9v battery it was solved :) now the tricky part i use my roll and pitch to control the 2 motors when i use the code of if command with both then the motors wont work properly but if i use it for only roll movement or pitch movement individually it works .. i dont know whats wrong :(
i used variables m11, m12 for Motor 1 with two points, m21, m22 for Motor 2 two points
when i program like
//turns the robot right
if( rollrad > 0.5) {
m12.turnOn();
m22.turnOn();
} else {
m12.turnOff();
m22.turnOff();
}
//turn the robot left
if(rollrad < -0.5) { m11.turnOn(); m21.turnOn();
} else { m11.turnOff(); m21.turnOff(); }
similarly for forward and backward for pitch backward: i use m11, m22 forward: i use m12, m21
i assume there is a clash of the motor number on turn on and turn off !!!
but if i use the code individually it works but when i use the same code together the motors wont work, is there any work around to this problem ?
@stewart , @deadprogram can you please help me from this coding blunder
@neonag can you pls share the entire code? so we can check it out, either here or gist would be ok.
@edgarsilva thanks for your response below is my entire code
code works fine if i use it individually with Roll or Pitch but together it doesn't
var Cylon = require('cylon');
Cylon.robot({ connections: [{ name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437' }, { name: 'arduino', adaptor: 'firmata', port: '/dev/tty.usbmodem621' }],
devices: [{ name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion' }, { name: 'led', driver: 'led', pin: 13, connection: 'arduino' }, { name: 'led1', driver: 'led', pin: 12, connection: 'arduino' }, { name: 'led2', driver: 'led', pin: 11, connection: 'arduino' }, { name: 'led3', driver: 'led', pin: 10, connection: 'arduino' } ],
work: function(my) { my.leapmotion.on('hand', function(hand) { var pitchRadians = hand.pitch(); var rollRadians = hand.roll();
if(pitchRadians > 0.2){
my.led.turnOn();
my.led3.turnOn();
} else {
my.led.turnOff();
my.led3.turnOff();
}
if(pitchRadians < -0.2){
my.led1.turnOn();
my.led2.turnOn();
} else {
my.led1.turnOff();
my.led2.turnOff();
} if(rollRadians > 0.3){
my.led1.turnOn();
my.led3.turnOn();
} else {
my.led1.turnOff();
my.led3.turnOff();
}if(rollRadians < -0.3) {
my.led.turnOn();
my.led2.turnOn();
} else {
my.led.turnOff();
my.led2.turnOff();
}
if( pitchRadians > 0.1){
my.led.turnOn();
my.led3.turnOn();
} else {
my.led.turnOff();
my.led3.turnOff();
}
if (pitchRadians < -0.1 ) {
my.led1.turnOn();
my.led2.turnOn();
} else {
my.led1.turnOff();
my.led2.turnOff();
}
*/
if(rollRadians > 0.3){
my.led1.turnOn();
my.led3.turnOn();
} else {
my.led1.turnOff();
my.led3.turnOff();
} if(rollRadians < -0.3) {
my.led.turnOn();
my.led2.turnOn();
} else {
my.led.turnOff();
my.led2.turnOff();
}
});
} }).start();
Hey @neonag; I lent my leap to a friend, I'll go pick it up tomorrow morning so I can test this code and give you hand.
I'll update here afterwards.
Thanks a lot @edgarsilva
@neonag I just tried your example with very few minor modifications and it, works, it seems you just have conflicting instructions, so sometimes you are saying to turnOff an LED on pitch but on on roll, etc... That is why it seems like it is not working.
The last four if
statements are causing conflict with what you have in the first four, in other words the logic seems a bit off.
The four leds work fine with just the pitch and roll in the first four if
.
var Cylon = require('cylon');
var robot = {
connections: [
{ name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437' },
{ name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }
],
devices: [
{ name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion' },
{ name: 'led', driver: 'led', pin: 13, connection: 'arduino' },
{ name: 'led1', driver: 'led', pin: 12, connection: 'arduino' },
{ name: 'led2', driver: 'led', pin: 11, connection: 'arduino' },
{ name: 'led3', driver: 'led', pin: 10, connection: 'arduino' }
],
work: function(my) {
var leapCB = function(hand) {
var pitchRadians = hand.pitch();
var rollRadians = hand.roll();
console.log('PitchRadians: ', pitchRadians);
console.log('RollRadians: ', rollRadians);
if(pitchRadians > 0.2){
my.led.turnOn();
my.led3.turnOn();
} else {
my.led.turnOff();
my.led3.turnOff();
}
if(pitchRadians < -0.2){
my.led1.turnOn();
my.led2.turnOn();
} else {
my.led1.turnOff();
my.led2.turnOff();
}
if(rollRadians > 0.3){
my.led1.turnOn();
my.led3.turnOn();
} else {
my.led1.turnOff();
my.led3.turnOff();
}
if(rollRadians < -0.3) {
my.led.turnOn();
my.led2.turnOn();
} else {
my.led.turnOff();
my.led2.turnOff();
}
/*
if( pitchRadians > 0.1){
my.led.turnOn();
my.led3.turnOn();
} else {
my.led.turnOff();
my.led3.turnOff();
}
if (pitchRadians < -0.1 ) {
my.led1.turnOn();
my.led2.turnOn();
} else {
my.led1.turnOff();
my.led2.turnOff();
}
if(rollRadians > 0.3){
my.led1.turnOn();
my.led3.turnOn();
} else {
my.led1.turnOff();
my.led3.turnOff();
}
if(rollRadians < -0.3) {
my.led.turnOn();
my.led2.turnOn();
} else {
my.led.turnOff();
my.led2.turnOff();
}
*/
};
my.leapmotion.on('hand', leapCB);
}
};
Cylon.robot(robot).start();
In other words it seems a logic problem not an issue with the devices or connections.
Can we close this too @neonag ?
yup can be done :)
:)
i was successful in testing the led on off with cylon.js but i am having difficulties to start of with how to control led by moving the hand forward and backward or sidewards .. anyone who can guide me