Arduino + Johnny five = cat remote control
to use the cat bot you need to require it ...
var catbot = require('catbot');
// callback function that will be called when the board is ready
function catCb (error, hardware) {
/*
Board is ready, use your robot:
hardware = {
board : Board
, x : Servo
, y : Servo
, laser : Led
, to : Function
}
*/
hardware.laser.on() // set the laser on
}
const opts = {
hwJoystick: true // this enable the harware joystick
}
catbot(catCb, opts) // catCb will be ran when the board is ready
see the code above.
move the X axis servo to 30° hardware.x.to(30)
same goes for Y
hardware.laser.on()
see j5 docs for servo
hardware.laser.toggle()
see j5 docs for led
harware.joystick.on('change', function () {...})
see j5 docs for joysticks
hardware.to([90, 90])
note on the 'to' method: this method is using inputRange and servoRange to scale value, see the detailed option for example
default config for the pins, wire your device as follow :
here is a diagram of the cat wiring
the led with in the schematic is the laser, my Fritzing did not have a laser module.
the second argument of the catbot function is an option oject, here are the default and explanation of the settings, this object if optional, and you just need to add the value you want to override
{
hwJoystick: false // this enable/disable creation and pooling of the the harware analogue joystick
catConfig: {
"inputRange": [0, 180],
"servoRange": [10, 170],
"hwJstk": false,
"hw": {
"laser": {
"pin": 12
},
"servoX": {
"pin": 10,
"inverted": true
},
"servoY": {
"pin": 11,
"inverted": true
},
"jstk": {
"x": "A0",
"y": "A1",
"jBt": 9,
"isPullup": true,
"deadZone": 0.05
}
}
}
}
these are two arrays of 2 numbers reprsenting the min-max scale the catbot will match.
example, gamepax axes are usually from a range -1 to 1 with 0 as a center, while servos take a number between 0 and 180 representing the degree. in this case
...
inputRange: [-1, 1]
servoRange: [0, 180]
...
will map the gamepad axes to the coresponding angle
enable or disable listening for the analog joystick, note that this will produce event that will move the turret, so you won't be able to controll it on joystick mode.
pin and option configuration for the catbot harware contain the following options
pin : the pin the laser is attached to (default: 12)