Kinect/Ardunio/Processing and 5 Motors

Heya, long time viewer first time poster etc...

Anywho's what's the best way of going about setting up a responcive kinect system to an ardunio 5 servo motor set up. I've got a skeletal app in Processing using OpenNI to read in the movements. Now I need to get the ardunio to power 5 servos. I can get an external AC from the lab if needed. I'm using a Duemilanove

Thanks in advance

Here’s some processing code I used at one point to get the kinect to talk to the arduino (I think it was mostly stolen from a book called Making Things See)

import processing.serial.*;
import SimpleOpenNI.*;

SimpleOpenNI kinect;
Serial arduinoport;

void setup() {
  size(1024, 480);
  textSize(20);
  
  if (Serial.list().length < 1) {
    println("No serial port seen. Quitting.");
    exit();
  }
  if (Serial.list().length > 1) {
    print("There are multiple serial ports. Using the first one: ");
    println(Serial.list()[0]);
  }
  
  arduinoport = new Serial(this, Serial.list()[0], 115200);
  //delay(2000); // Wait for arduino to reboot
  
  kinect = new SimpleOpenNI(this);
  kinect.enableDepth();
  
  kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL);
}

void draw() {
  kinect.update();
  PImage depth = kinect.depthImage();
  image(depth, 0, 0);
  
  IntVector userList = new IntVector();
  kinect.getUsers(userList);
  
  while (arduinoport.available() > 0) {
    char inByte = (char)arduinoport.read();
    print(inByte);
  }
  
  boolean stopRobot = true; // Only move robot if someone is there
  for (int i=0; i < userList.size(); i++) {
    int userId = userList.get(i);
    if (kinect.isTrackingSkeleton(userId)) {
      
      float x = 0;
      float y = 0;      
      float rotation = 0;

      // Get the position of the torso
      PVector torsopos = new PVector();
      float torsoconfidence = kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_TORSO, torsopos);
      if (torsoconfidence > 0.5) {
        displayJoint(torsopos);
        float userPos = torsopos.x;
        
        userPos = map(userPos, -600, 600, 1000, -1000);
        userPos = constrain(userPos, -1000, 1000);
      }
      
      PVector rightpos = new PVector();
      float rightconfidence = kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, rightpos);
      PVector leftpos = new PVector();
      float leftconfidence = kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, leftpos);
      if (rightconfidence > 0.5 && leftconfidence > 0.5) {
        displayJoint(rightpos);
        displayJoint(leftpos);
        PVector differenceVector = PVector.sub(rightpos, leftpos);
        x = constrain(map(differenceVector.x, -600, 600, -1000, 1000), -1000, 1000);
        y = constrain(map(differenceVector.z, -200, 200, -1000, 1000), -1000, 1000);

        if (differenceVector.y > 0) { // If left hand is higher
          x = -x;
          y = -y;
        }
        //print(x); print("\t"); print (y); print("\t");
      }
      //println(userPos);
      
      String arduinocmd = String.format("<r,%.0f,%.0f,%.0f>", x, y, rotation);//"<r,"+x+","+y+"," + rotation + ">";
      fill(50);
      rect(725, 175, 250, 250);
      fill(255);
      ellipse(map(x, -1000, 1000, -100, 100) + 850, map(y, -1000, 1000, -100, 100) + 300, 20, 20);
      //println (arduinocmd);
      arduinoport.write(arduinocmd);
      stopRobot = false;
    }
  }
  if (stopRobot) {
    arduinoport.write("<r,0,0,0>");
  }
}

void onNewUser(int userId) {
  background(0);
  fill(255);
  text("Start pose detection", 700, 30);
  kinect.startPoseDetection("Psi", userId);
}

void onEndCalibration(int userId, boolean successful) {
  background(0);
  fill(255);
  if (successful) {
    text("    User Calibrated!", 700, 30);
    kinect.startTrackingSkeleton(userId);
  }
  else {
    text("    Failed to calibrate user", 700, 30);
    kinect.startPoseDetection("Psi", userId);
  }
}

void onStartPose(String pose, int userId) {
  background(0);
  fill(255);
  text("Started pose for user " + userId, 700, 30);
  kinect.stopPoseDetection(userId);
  kinect.requestCalibrationSkeleton(userId, true);
}

void displayJoint(PVector joint) {
  PVector converted = new PVector();
  kinect.convertRealWorldToProjective(joint, converted);
  pushMatrix();
    noStroke();
    fill(255,0,0);
    ellipse(converted.x, converted.y, 20, 20);
  popMatrix();
}

And here’s corresponding arduino code to control a robot with a library I wrote myself (just replace bot.RunMotors with whatever you want to move): arduino/circlebot/move_with_serial at master · AdamCDunlap/arduino · GitHub

ok thanks mate. I'll fiddle with that soon enough so. Is there anything I should be concerned about with running 5 motors off arduino though?

uncleseano: ok thanks mate. I'll fiddle with that soon enough so. Is there anything I should be concerned about with running 5 motors off arduino though?

I would try to get an external 5V power source. Five should be okay but if you start seeing weird issues then it's likely not getting enough power.

Im having great difficulty getting this to work. I'm still stuck on trying to get the kinect to power 5 servo motors. I havent even gotten processing to communicate with the arduino. Any tips?

A good tip it to post the code that doesn't work.

trying to get the kinect to power 5 servo motors.

No not power but control there is a very big difference.

uncleseano: Im having great difficulty getting this to work. I'm still stuck on trying to get the kinect to power 5 servo motors. I havent even gotten processing to communicate with the arduino. Any tips?

You need to do all of this:

  • Control 1 servo with arduino (sweep example) (Arduino -> Servo)
  • Control 5 servos with arduino (sweep example + arrays) (Arduino -> Servos)
  • Make kinect do something interesting on computer (In processing, println("servos should be moving right now"); This is probably the hardest step). (Kinect -> Processing)
  • Make processing talk with arduino (When it sends "hello" the arduino flashes an LED) (Processing -> Arduino)
  • Make kinect talk to arduino via processing (Kinect -> Processing -> Arduino)
  • Kinect -> Processing -> Arduino -> Servos

Which are you having trouble with? Give specific details so that we may help.

I got it sorted thanks. I now its probably a crappy way of going about it but I'm using VB instead of processing. 3 stables servos and counting

heya guys, im nearly done here. the only thing I need help with is the external AC.once I get to 4 servos (I need 5)after a few seconds of testing they all cut out. seems they are not getting enough power but ive no idea how to use this feckin external AC. Any advice?

Shameless Bump

That power supply says on the back as far as I can tell it will supply 300mA. That is hardly enough to power one servo let alone five of them.

Upwards of 12V and 300mA…weird I got it off my lecturer…that’s…disconcerting. Got any links to one that would work?

What about this one:- http://www.ebay.co.uk/itm/Bestec-5V-3A-EU-2-Pin-Power-Supply-Adapter-14-1-NA0151WACA-/170939713587?pt=UK_Computing_CablesConnectors_RL&hash=item27cccd0833

Also, servos generally perform better at ~6v than ~5v.

zoomkat: Also, servos generally perform better at ~6v than ~5v.

They do but power supplies of that voltage are rare and the OP is having trouble with this simple concept let alone trying to make a 6.5V regulator. One step at a time.

Well the AC i have here has a switch on the back for 4.5,6,7.5,9,12 etc (voltage) and one to switch the +/-...For a AC that can go upwards of 12 volts I'm finding it hard to believe that it can't power one RC Servo

I'm finding it hard to believe that it can't power one RC Servo

Then you know little about electricity. There are two things and voltage is only one of them. Most servos work on 6.5V but you can do with 5V at a pinch. However, the other thing is that the power supply has to be able to delver the current asked of it, if it is asked to supply too much then the voltage collapses and everything either over heats or shuts down.

Well the AC i have here has a switch on the back for 4.5,6,7.5,9,12

I think you will find that it is DC or else you have more work yo do turning it into DC

WizenedEE:

uncleseano: Im having great difficulty getting this to work. I'm still stuck on trying to get the kinect to power 5 servo motors. I havent even gotten processing to communicate with the arduino. Any tips?

You need to do all of this:

  • Control 1 servo with arduino (sweep example) (Arduino -> Servo)
  • Control 5 servos with arduino (sweep example + arrays) (Arduino -> Servos)
  • Make kinect do something interesting on computer (In processing, println("servos should be moving right now"); This is probably the hardest step). (Kinect -> Processing)
  • Make processing talk with arduino (When it sends "hello" the arduino flashes an LED) (Processing -> Arduino)
  • Make kinect talk to arduino via processing (Kinect -> Processing -> Arduino)
  • Kinect -> Processing -> Arduino -> Servos

Which are you having trouble with? Give specific details so that we may help.

Hi

I am new user here. I am trying to do the same thing for my senior project and I am having trouble making the servos move when I move in front of the kinect. I am able to see the processing window and the code from what I believe compiles without any issues. Can you please let me know what could be done or any tips would be helpful?

Thanks is advance!

So find out where it is going wrong by using the serial print to send messages for debugging. Just write an arduino sketch to move a servo to check you have that bit right first. Just because code compiles does not mean it will do what you hope it will do, it just means the compiler could make the code do something.

cpt_mellow:

WizenedEE:

uncleseano:
Im having great difficulty getting this to work. I’m still stuck on trying to get the kinect to power 5 servo motors. I havent even gotten processing to communicate with the arduino. Any tips?

You need to do all of this:

  • Control 1 servo with arduino (sweep example) (Arduino → Servo)
  • Control 5 servos with arduino (sweep example + arrays) (Arduino → Servos)
  • Make kinect do something interesting on computer (In processing, println("servos should be moving right now"); This is probably the hardest step). (Kinect → Processing)
  • Make processing talk with arduino (When it sends “hello” the arduino flashes an LED) (Processing → Arduino)
  • Make kinect talk to arduino via processing (Kinect → Processing → Arduino)
  • Kinect → Processing → Arduino → Servos

Which are you having trouble with? Give specific details so that we may help.

Hi

I am new user here. I am trying to do the same thing for my senior project and I am having trouble making the servos move when I move in front of the kinect. I am able to see the processing window and the code from what I believe compiles without any issues. Can you please let me know what could be done or any tips would be helpful?

Thanks is advance!

My same advice that you quoted applies to you, too. Go incrementally (or take stuff out incrementally) so you can isolate any problems you may have. If you made the processing program print out when the servos should be moving and the arduino flash an LED when they should be moving you can narrow down where the problem is very quickly.