Well, not everything is exciting...this post will be detailing how the server and the rest of the code is integrated. In an different post, Ashan detailed the integration of the arm, hand and sensors together. Here, we'll just do a brief description of what needs to be changed for everything to be integrated.
See the following two code snippets:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
controller.on('frame', function(frame) { | |
handslength = frame.hands.length; | |
if (handslength>0) { | |
var hand = frame.hands[0]; | |
Pitch = Math.round(180 * (hand.pitch())/Math.PI); | |
Roll = Math.round(180 * (hand.roll())/Math.PI); | |
var handPosition = frame.hands[0].palmPosition; | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
io.sockets.on("connection",function(socket){ | |
console.log("User-Client Connected!"); | |
socket.on('frame', function(data) { | |
var index = data.search('Raw JSON'); | |
var json = data.slice(index+14); | |
var frame = JSON.parse(json); | |
handslength = frame.hands.length; | |
if (handslength>0) { | |
var hand = frame.hands[0]; | |
// extracted from API | |
var handpitch = Math.atan2(hand.direction[1], -hand.direction[2]); | |
var handroll = Math.atan2(hand.palmNormal[0], -hand.palmNormal[1]); | |
Pitch = Math.round(180 * (handpitch/Math.PI); | |
Roll = Math.round(180 * (handroll/Math.PI); | |
var handPosition = hand.palmPosition; | |
... |
Looking at the second code snippet, you can see that the bulk of the data is actually slotted within the WebSocket method. Every time a frame is passed in, the Arm Code is triggered and the rest of the code can run.
More changelog:
- Synchronize all the loops and calls to code to the same frequency, namely, 250 ms
- Make sure that the computer we attached to had the correct ports, and had set up the multi-board correctly
- Test whether the data works correctly
- ???
- Profit when it does!
No comments:
Post a Comment