Update question regarding ControlP5 knob! Newbie to java!
in
Contributed Library Questions
•
10 months ago
Hello!
I have just started programming in Processing and Object oriented programming. Until now I have used only embedded C programming.
My problem is regarding the ControlP5 library.
In the next piece of code the knob I am creating is not updating the value. I want to graphically show the value of the shoulder angle in the knob.
- import SimpleOpenNI.*;
- import controlP5.*;
- SimpleOpenNI kinect;
- ControlP5 cp5;
- Knob myKnobA;
- void setup()
- {
- kinect = new SimpleOpenNI(this);
- kinect.enableDepth();
- kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL);
- kinect.setMirror(true);
- cp5 = new ControlP5(this);
- myKnobA = cp5.addKnob("knob")
- .setRange(0,255)
- .setValue(50)
- .setPosition(700,70)
- .setRadius(50)
- .setDragDirection(Knob.VERTICAL)
- ;
- size(1024,768);
- fill(255,0,0);
- }
- void draw()
- {
- kinect.update();
- image(kinect.depthImage(),0,0);
- IntVector userList = new IntVector();
- kinect.getUsers(userList);
- if(userList.size()>0)
- {
- int userId = userList.get(0);
- if(kinect.isTrackingSkeleton(userId))
- {
- PVector rightHand = new PVector();
- kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND,rightHand);
- PVector convertedRightHand = new PVector(rightHand.x, rightHand.y);//convert to 2d
- PVector rightElbow = new PVector();
- kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW,rightElbow);
- PVector convertedRightElbow = new PVector(rightElbow.x, rightElbow.y);//convert to 2d
- PVector rightShoulder = new PVector();
- kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER,rightShoulder);
- PVector convertedRightShoulder = new PVector(rightShoulder.x, rightShoulder.y);//convert to 2d
- PVector rightHip = new PVector();
- kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HIP,rightHip);
- PVector convertedRightHip = new PVector(rightHip.x, rightHip.y);//convert to 2d
- PVector torsoOrientation = PVector.sub(convertedRightShoulder, convertedRightHip);
- PVector upperArmOrientation = PVector.sub(convertedRightElbow,convertedRightShoulder);
- //calculez unghiurile
- float shoulderAngle = angleOf(convertedRightElbow, convertedRightShoulder, torsoOrientation);
- float elbowAngle = angleOf(convertedRightHand, convertedRightElbow, upperArmOrientation);
- float convertedShoulderAngle = map(shoulderAngle,0,180,0,255);
- myKnobA.setValue(convertedShoulderAngle);
- //printez ce vreau
- fill(255,0,0);
- scale(3);
- text("shoulder: "+ int(shoulderAngle)+" elbow: "+ int(elbowAngle)+" convertedShoulder: "+int(convertedShoulderAngle),20,20);
- }
- }
- }
- float angleOf(PVector one, PVector two, PVector axis)
- {
- PVector limb = PVector.sub(two, one);
- return degrees(PVector.angleBetween(limb, axis));
- }
- void onNewUser(int userId)
- {
- println("start pose detection");
- kinect.startPoseDetection("Psi",userId);
- }
- void onEndCalibration(int userId, boolean successful)
- {
- if(successful)
- {
- println("User calibrated!!!");
- kinect.startTrackingSkeleton(userId);
- }
- else
- {
- println("Failed to calibrate user!!");
- kinect.startPoseDetection("Psi", userId);
- }
- }
- void onStartPose(String pose, int userId)
- {
- println("Started pose for user.");
- kinect.stopPoseDetection(userId);
- kinect.requestCalibrationSkeleton(userId,true);
- }
For verification that the value convertedShoulderAngle is updated I am displaing it on the screen and it does update. Only the function setValue() is not called.
If more information is needed I would provide it.
Thanks in advance!
1