Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package org.friendularity.bundle.test.facedetect.r50;
  
  import java.util.List;

Author(s):
Jason G. Pallack <jgpallack@gmail.com>
 
 public class FaceMonitor implements Listener<ImageRegionList> {
     private final static int CAMERA_FRAME_WIDTH = 320;
     private final static int CAMERA_FRAME_HEIGHT = 240;
     private final static double MOVE_AMT = 0.01;
     
     private RemoteRobot myRobot;
     private double myYaw;
     private double myPitch;
     private JointId myNeckYaw;
     private JointId myNeckPitch;
     
     public FaceMonitor() {
          = MechIO.connectRobot();
         RobotPositionMap posMap = .getDefaultPositions();
          = new JointId(.getRobotId(),
                 new Joint.Id(.));
          = new JointId(.getRobotId(),
                 new Joint.Id(.));
         
         .move(posMap, 1000);
         
         TimeUtils.sleep(1000);
         
          = posMap.get().getValue();
          = posMap.get().getValue();
     }
     
     public FaceMonitor(String ipAddress) {
         UserSettings.setRobotAddress(ipAddress);
         UserSettings.setAnimationAddress(ipAddress);
         UserSettings.setSpeechAddress(ipAddress);
         UserSettings.setRobotId("myRobot");
          = MechIO.connectRobot();
         RobotPositionMap posMap = .getDefaultPositions();
          = new JointId(.getRobotId(),
                 new Joint.Id(.));
          = new JointId(.getRobotId(),
                 new Joint.Id(.));
         
         .move(posMap, 1000);
         
         TimeUtils.sleep(1000);
         
          = posMap.get().getValue();
          = posMap.get().getValue();
     }
 
     @Override
     public void handleEvent(ImageRegionList t) {
         List<ImageRegionregions = t.getRegions();
         
         for(ImageRegion regionregions) {
             RobotPositionMap goals = .getGoalPositions();
             double centerX =  / 2;
             double centerY =  / 2;
             double x = region.getX() + region.getWidth() / 2;
             double y = region.getY() + region.getHeight() / 2;
 
             if(x > centerX) {
 //                double xDiff = x - centerX;
 //                System.out.println("X is " + xDiff + " past center.");
                 
                 if( -  > 0) {
                      -= ;
 //                    System.out.println("Moving yaw to " + myYaw);
                 } else {
                      = 0;
                 }
                 
                 goals.put(new NormalizedDouble());
             } else if(x < centerX) {
 //                double xDiff = centerX - x;
 //                System.out.println("X is " + xDiff + " before center.");
                 
                 if( +  < 1) {
                     += ;
//                    System.out.println("Moving yaw to " + myYaw);
                } else {
                     = 1;
                }
                
                goals.put(new NormalizedDouble());
            }
            
            if(y > centerY) {
//                double yDiff = y - centerY;
//                System.out.println("Y is " + yDiff + " past center.");
                
                if( -  > 0) {
                     -= ;
//                    System.out.println("Moving pitch to " + myPitch);
                } else {
                     = 0;
                }
                
                goals.put(new NormalizedDouble());
            } else if(y < centerY) {
//                double yDiff = centerY - y;
//                System.out.println("Y is " + yDiff + " before center.");
                
                if( +  < 1) {    
                     += ;
//                    System.out.println("Moving pitch to " + myPitch);
                } else {
                     = 1;
                }
                
                goals.put(new NormalizedDouble());
            }
            
            .move(goals, 100);
        }
    }
New to GrepCode? Check out our FAQ X