Esempio n. 1
0
function motoresAvance () {
    console.log("Prueba de ambos motores iniciada...");
    vinCheck();  
    motorA.forward(255);
    motorB.forward(255);
    console.log("MotorA y MotorB a delante");
};
Esempio n. 2
0
function motoresReversa () {
    console.log("Prueba de ambos motores iniciada...");
    vinCheck();  
    motorA.reverse(255);      
    motorB.reverse(255);
    console.log("MotorA y MotorB al reves");
};
Esempio n. 3
0
  var checkingHappiness = function (happy) {
    //if (lastMood === null) lastMood = happy;
    //if (!lastMood === happy) {

      if (happy) {
        if (moody) {
          salfordMood.stop();
          glasgowMood.stop();
          teamMood.stop();
          moody = false;
        }
        salfordMood.on();
        glasgowMood.on();
        teamMood.on();
        if (!leftEar.isOn) {
          leftEar.forward(255);
          setTimeout(randomisedLeftEar, Math.floor(Math.random() * 10000));
        }
        if (!rightEar.isOn)  {
          rightEar.forward(255);
          setTimeout(randomisedRightEar, Math.floor(Math.random() * 10000));
        }
      } else {
        salfordMood.blink(500);
        glasgowMood.blink(500);
        teamMood.blink(500);
        leftEar.stop();
        rightEar.stop();
        moody = true;
      }
    //}
    setTimeout(areWeHappy(checkingHappiness), 10000);
  };
Esempio n. 4
0
   board.wait(5000, function() {
   console.log("Prueba de ambos motores iniciada...");
   vinCheck();
   motorA.reverse(255);      
   motorB.reverse(255);
   console.log("MotorA y MotorB al reves");
 });
Esempio n. 5
0
    function fwd(){
                  console.log("in fwd");

      m1.forward(255);
      m2.forward(255);

    }
Esempio n. 6
0
board.on("ready", function() {
  //ここに処理を記述
  var motor = new five.Motor(9);

  //event1
  motor.on("forward", function(err, timestamp) {
    motor.start();
    board.wait(2000, function() {
      motor.stop();
    });
  });

  motor.on("start", function(err, timestamp) {
    board.wait(2000, function() {
      motor.stop();
    });
  });

  //event2
  motor.on("stop", function(err, timestamp) {
    // demonstrate braking after 5 seconds
    board.wait(1000, function() {
      motor.forward(200);
    });
  });

  //start
  motor.forward(200);

});
Esempio n. 7
0
board.on("ready", function() {

  var motor = new five.Motor(5);

  // Start the motor at maximum speed, wait 2 seconds and stop.
  motor.start(0);

});
Esempio n. 8
0
board.on('ready', function() {
	var motor = new five.Motor(9);
	motor.start(200);
	board.wait(2000, function() {
		motor.stop();
		board.wait(1000, function() {
			motor.start(200);
		});			
	});
})
Esempio n. 9
0
    back.on('down', function() {
      logger.log('info','back reached')

      // again verify that its doing something
      if (self.machine_state.SCANNING) {
        // stop the motor
        motor.stop()
        motor.forward(config.FORWARD_SPEED)
        //reset the state
        self.machine_state.SCANNING = false
        global.io.sockets.emit('status', {board: 'portrait'})
      }
    })
Esempio n. 10
0
 function loop() {
     motor.start(200);
     board.wait(2000, function () {
         motor.stop();
         board.wait(1000, loop);
     });
 }
board.on("ready", function() {
  var speed = 100;  
  motor1 = new five.Motor([10, 8]);
  motor2 = new five.Motor([9, 7]);

  board.repl.inject({
  	lmotor: motor1,
  	rmotor: motor2,
  });

  app.io.route('up', function(req) {
      console.log(req.data);            
      motor1.rev( speed * req.data.speed );
      motor2.rev( speed * req.data.speed );
      console.log(' => Up: ' + speed * req.data.speed );
  });

  app.io.route('down', function(req) {      
      motor1.fwd( speed * req.data.speed * -1);
      motor2.fwd( speed * req.data.speed * -1);
      console.log(' => Down: ' + speed * req.data.speed );
  });

  app.io.route('left', function(req) {
      console.log(' => Left: ');
      motor1.fwd( 80 );
      motor2.rev( 80 );
  });

  app.io.route('right', function(req) {
      console.log(' => Right');
      motor1.rev( 80 );
      motor2.fwd( 80 );
  });

  app.io.route('stop', function(req) {
      console.log(' => Stoping...');
      motor1.stop();
      motor2.stop();
  });

  app.listen(7070, function(){
    console.log('Express server listening');
  });

  console.log("Ready event. Repl instance auto-initialized");
});
Esempio n. 12
0
board.on("ready", function() {
  // Create a new `motor` hardware instance.
  motor = new five.Motor({
    pin: 5
  });

  // Inject the `motor` hardware into
  // the Repl instance's context;
  // allows direct command line access
  board.repl.inject({
    motor: motor
  });

  
  // Motor Event API

  // "start" events fire when the motor is started.
  motor.on("start", function(err) {

    // Start the motor at maximum speed
    motor.start(100);
    console.log("start", Date.now());

    // Demonstrate motor stop in 2 seconds
    board.wait(2000, function() {
      motor.stop();
    });
  });

  // "stop" events fire when the motor is stopped.
  motor.on("stop", function() {
    console.log("stop", Date.now());
  });

  // Motor API

  // start([speed)
  // Start the motor. `isOn` property set to |true|
  // Takes an optional parameter `speed` [0-255]
  // to define the motor speed if a PWM Pin is
  // used to connect the motor.
  motor.start();

  // stop()
  // Stop the motor. `isOn` property set to |false|
});
Esempio n. 13
0
  function motorControl(out) {
    var velocity = Math.abs(out);
    if (velocity < 0) {
      velocity = 0;
    }
    if (velocity > 255) {
      velocity = 255;
    }

    if (out > 0) {
      motor1.reverse(velocity);
      motor2.reverse(velocity);
    } else {
      motor1.forward(velocity);
      motor2.forward(velocity);
    }
  }
Esempio n. 14
0
board.on('ready', function () {
  var motor = new five.Motor(9)

  motor.on('start', function () {
    board.wait(2000, function () {
      motor.stop()
    })
  })

  motor.on('stop', function () {
    board.wait(1000, function () {
      motor.start(200)
    })
  })

  motor.start(200)
})
Esempio n. 15
0
 function elevatorDown(){
   if (elevatorPosition != "bottom"){
     console.log("Elevator going down!");
     elevatorState = "moving-down";
     elevatorMotor.reverse(90);
   }else{
     console.log("Elevator is already at the bottom");
   }
 }
Esempio n. 16
0
 function elevatorUp(){
   if (elevatorPosition != "top"){
     console.log("Elevator going up!");
     elevatorState = "moving-up";
     elevatorMotor.forward(120);
   }else{
     console.log("Elevator is already at the top");
   }
 }
Esempio n. 17
0
board.on("ready", function() {
  myMotor = new five.Motor({
    pin: 9
  });
  // event handlers on start and stop
  myMotor.on("start", function( err, timestamp ) {
    console.log( "started", timestamp );

    // stop after 2 seconds
    board.wait(2000, function() {
      myMotor.stop();
    });
  }); 
  myMotor.on("stop", function( err, timestamp ) {
    console.log( "stopped", timestamp );
  });
  myMotor.start();
});
Esempio n. 18
0
board.on("ready", function() {

  // Motor 1
  // var motor = new five.Motor({
  //     pins: { pwm: 11 },
  //     register: { data: 8, clock: 4, latch: 12 },
  //     bits: { a: 2, b: 3 }
  //   }
  //  );
 
  // Motor 2
  var motor = new five.Motor({
      pins: { pwm: 3 },
      register: { data: 8, clock: 4, latch: 12 },
      bits: { a: 1, b: 4 }
    }
   );

  board.repl.inject({
    motor: motor
  });

  motor.on("start", function(err, timestamp) {
    console.log("start", timestamp);
  });

  motor.on("stop", function(err, timestamp) {
    console.log("automated stop on timer", timestamp);
  });

  motor.on("brake", function(err, timestamp) {
    console.log("automated brake on timer", timestamp);
  });

  motor.on("forward", function(err, timestamp) {
    console.log("forward", timestamp);

    // demonstrate switching to reverse after 5 seconds
    board.wait(5000, function() {
      motor.reverse(150);
    });
  });

  motor.on("reverse", function(err, timestamp) {
    console.log("reverse", timestamp);

    // demonstrate stopping after 5 seconds
    board.wait(5000, function() {

      // Apply the brake for 500ms and call stop()
      motor.brake(500);
    });
  });

  // Start the motor at maximum speed
  motor.forward(255);

});
Esempio n. 19
0
board.on('ready', function(){
  motor = new five.Motor({pin:9});
  board.repl.inject({ motor: motor});

  motor.on('start', function(err, timestamp){
    board.wait(2000, function(){
      motor.stop();
    })
  });

  motor.on('stop', function(err, timestamp){
    board.wait(1000, function(){
      motor.start(200);
    })
  })

  motor.start(200);

})
Esempio n. 20
0
board.on("ready", function() {
  var timer;

  // Create a new `motor` hardware instance.
  motor = new five.Motor({
    pin: 5
  });

  // Inject the `motor` hardware into
  // the Repl instance's context;
  // allows direct command line access
  board.repl.inject({
    motor: motor
  });

  // Motor Event API

  // "start" events fire when the motor is started.
  motor.on("start", function( err, timestamp ) {
    console.log( "start", timestamp );

    // Demonstrate motor stop in 2 seconds
    board.wait( 2000, function() {
      motor.stop();
    });
  });

  // "stop" events fire when the motor is started.
  motor.on("stop", function( err, timestamp ) {
    console.log( "stop", timestamp );
  });

  // Motor API

  // start()
  // Start the motor. `isOn` property set to |true|
  motor.start();

  // stop()
  // Stop the motor. `isOn` property set to |false|

});
Esempio n. 21
0
   setInterval(function() {
	curMouse = robot.getMousePos();
		
		if (curMouse.x >= screen.width || curMouse.x <= 0 || curMouse.y >= screen.height || curMouse.y <= 0)
		{
			motor1speed = 0;
			motor2speed = 0;
		}
		
		else if ((curMouse.x < center-10) && curMouse.y < heightCenter) 
		{
			//turn towards left
			motor1speed = curMouse.x / 5.0;
			motor2speed = 100;
		}
		
		else if((curMouse.x > center+10) && curMouse.y < heightCenter)
		{
			//move right
			motor1speed = 100;
			motor2speed = (screen.width - curMouse.x) / 5.0;
		}
		
		else if((curMouse.x > center-10 && curMouse.x < center+10) && (curMouse.y < heightCenter))
		{
			//go straight
			motor1speed = 100;
			motor2speed = 100;
		}
		else 
		{
			//stops both motors.
			motor1speed = 0;
			motor2speed = 0;
		}
		
		//move motors according to individual speed
		motor1.reverse(motor1speed);
		motor2.forward(motor2speed);
		
	
	}, 100);
Esempio n. 22
0
  board.on("ready", function() {

    console.log('HEEERRRRREEEEEe');

    var motor = new five.Motor({
      pins: {
        pwm: 9,
        dir: 10
      }
    });

    motor.start(1);

    var led = new five.Led(2); 
    led.on();

    var led = new five.Led(3); 
    led.strobe();

  });
Esempio n. 23
0
board.on('ready', function(){
  var motor = new five.Motor(9);

  motor.on('start', function(){
    board.wait(2000, function(){
      motor.stop();
    });
  });

  motor.on('stop', function(){
    board.wait(1000, function(){
      motor.start(200);
    });
  });

  //not sure why this only works here and not if I put
  //it up top after the motor variable is initialised
  motor.start(200);

});
Esempio n. 24
0
  motor.on("start", function(err) {

    // Start the motor at maximum speed
    motor.start(100);
    console.log("start", Date.now());

    // Demonstrate motor stop in 2 seconds
    board.wait(2000, function() {
      motor.stop();
    });
  });
Esempio n. 25
0
 function motorDrive(speed, direction)
 {
   switch(direction)
   {
     case 'forward':
       motorGroupRight_1.forward(speed);
       motorGroupRight_2.forward(speed);
       console.log('forward_motorDrive');
       break;
     case 'backward':
       motorGroupRight.reverse(170);
       console.log('reverse_motorDrive');
       break;
     // default:
     // {
     //   //stops all motors
     //   motorGroupRight.stop();
     //   console.log('stop');
     // }
   }
 }
Esempio n. 26
0
        board.on("ready", function () {
            car1 = new five.Motor({
                pin: 6,
                current: {
                    pin: 6,
                    freq: 0,
                    range: [0, 255]
                }
            });

            car2 = new five.Motor({
                pin: 10,
                current: {
                    pin: 10,
                    freq: 0,
                    range: [0, 255]
                }
            });
	        // Start the car with initial speed
            car1.start(45);
        });
Esempio n. 27
0
    start.on('down', function() {
      logger.log('info','start pressed')

      // if we are not in the middle of a process
      if (!self.machine_state.SCANNING){
        logger.log('info','scanning = true')
        // initiate the motion
        motor.reverse(config.FORWARD_SPEED) //buggy
        self.machine_state.SCANNING = true
        global.io.sockets.emit('status', {board: 'scanning'})
      }
    })
Esempio n. 28
0
board.on("ready", function() {
  // Create a new `motor` hardware instance.
  var motor;
  motor = new five.Motor({
    pins: [7, 8],
    controller: "PCA9685",
    address: 0x60
  });

  // Inject the `motor` hardware into
  // the Repl instance's context;
  // allows direct command line access
  board.repl.inject({
    motor: motor,
  });

  // Motor Event API

  // "start" events fire when the motor is started.
  motor.on("start", function() {
    console.log("start", Date.now());

    // Demonstrate motor stop in 2 seconds
    board.wait(2000, function() {
      motor.stop();
    });
  });

  // "stop" events fire when the motor is started.
  motor.on("stop", function() {
    console.log("stop", Date.now());
  });

  // Motor API

  // start()
  // Start the motor. `isOn` property set to |true|
  motor.start();

});
Esempio n. 29
0
board.on("ready", function() {
  myMotor = new five.Motor({
    pin: 9
  });

  // event handler on start
  myMotor.on("start", function( err, timestamp ) {
    console.log( "started", timestamp );

    // stop after 2 seconds
    board.wait(2000, function() {
      myMotor.stop();
    });

  });

  // event handler on stop
  myMotor.on("stop", function( err, timestamp ) {
    console.log( "stopped", timestamp );
  });

  // event handler for the latest added chatter
  firebaseRef.on('child_added', function(snapshot) {
    var addedChatter = snapshot.name();

    // event handler on any message change for that latest chatter
    firebaseRef.child(addedChatter + '/message').on('value', function(snapshot) {
      console.log(addedChatter + ' : ' + snapshot.val());

      // start motor on new message - speed argument (between 0 and 255) is optional
      myMotor.start(250);
    });
  });

  // motor's method can be accessed on Node REPL
  this.repl.inject({
    myMotor: myMotor
  });
});
Esempio n. 30
0
board.on("ready", function() {

  var motor1 = new five.Motor({
      pins: { pwm: 11 },
      register: { data: 8, clock: 4, latch: 12 },
      bits: { a: 2, b: 3 }
    });

  var motor2 = new five.Motor({
      pins: { pwm: 3 },
      register: { data: 8, clock: 4, latch: 12 },
      bits: { a: 1, b: 4 }
    });

  // Start the motors
  motor1.reverse(150);
  motor2.forward(150);
  board.wait(5000, function() {
     motor1.stop();
     motor2.stop();
  });

});