Trying to create multiple arms, with differente segments size, using controlP5 Library.

edited March 2017 in Library Questions

Trying to create multiple arms, with different segments size, using controlP5 Library to create a easy 'robot arm drive simulator', but the code only work if all arm are equal in segment size. If not we get a a arm segments Overlap!!

Could you give me a topic just to fixe my code?

Tks in advance. Jose Peres.

// JPeres: 20-MAR-2017 import controlP5.*; ControlP5 cp5;

float x, y; float angle1, angle2, angle3 = 0.0;

float segLength = 100; float segLength1 = 100; // Must be equal to var segLength!!! - How to fix ?? float segLength2 = 100; // Must be equal to var segLength!!! - How to fix ??

int V01 = 0; int V02 = 0; int V03 = 0;

void setup() { size(1080, 640); strokeWeight(25); stroke(255, 160);

x = width * 0.40; y = height * 0.7;

cp5 = new ControlP5(this);

cp5.addSlider("V01") .setPosition(900, 80) .setSliderMode(Slider.FLEXIBLE) .setValue(0) .setSize(20, 300) .setRange(-90, 90);

cp5.addSlider("V02") .setPosition(940, 80) .setSliderMode(Slider.FLEXIBLE) .setValue(0) .setSize(20, 300) .setRange(-90, 90);

cp5.addSlider("V03") .setPosition(980, 80) .setSliderMode(Slider.FLEXIBLE) .setValue(0) .setSize(20, 300) .setRange(-90, 90);

cp5.addSlider("H00") .setPosition(280, height-40) .setSliderMode(Slider.FLEXIBLE) .setValue(0) .setSize(300, 30) .setRange(-90, 90);

cp5.addButton("ARM_RESET") .setPosition(900, height-100) .setSize(140, 40) .setValue(0) .activateBy(ControlP5.RELEASE);

cp5.addButton("ARM_HOME") .setPosition(900, height-50) .setSize(140, 40) .setValue(0) .activateBy(ControlP5.RELEASE); } void draw() { background(80); angle1 = ((-V01+90)/float(180)) * -PI; angle2 = (-90+V02/float(180)) * PI;

pushMatrix(); segment(x, y, angle1); segment(segLength1, 0, angle2); segment(segLength2, 0, angle3);

popMatrix(); line(x, y, x, y+80); rect(0, y+80, width, y+80); } void segment(float x, float y, float a) { translate(x, y); rotate(a); line(0, 0, segLength, 0); } public void ARM_RESET(int value) { cp5.getController("V01").setValue(0); cp5.getController("V02").setValue(0); cp5.getController("V03").setValue(0); cp5.getController("H00").setValue(0); } public void ARM_HOME(int value) { cp5.getController("V01").setValue(90); cp5.getController("V02").setValue(-90); cp5.getController("V03").setValue(-90); cp5.getController("H00").setValue(0); } // That's the end!

Answers

  • Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code

    Kf

  • Answer ✓

    ok. Thank's for your notice. I just fixe my program code. It´s running now with different arm segments. Thanks you for your time. Regards. Jose Peres

Sign In or Register to comment.