Go Down

Topic: Kinect/Ardunio/Processing and 5 Motors (Read 11961 times) previous topic - next topic

uncleseano

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

WizenedEE

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)
Code: [Select]
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): https://github.com/AdamCDunlap/arduino/tree/master/circlebot/move_with_serial

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?

WizenedEE


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.

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?

Grumpy_Mike

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

Quote
trying to get the kinect to power 5 servo motors.

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

WizenedEE


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.

uncleseano

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

uncleseano

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?



Grumpy_Mike

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.

uncleseano

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


zoomkat

Also, servos generally perform better at ~6v than ~5v.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Grumpy_Mike


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.

Go Up