Pages: [1]   Go Down
Author Topic: ControlP5 help  (Read 250 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 221
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to write code using Processing editor to control my robot. I'm using the ControlP5 library to create an user interface let lets me click on buttons to control my robot. How do I get the walking code to loop after clicking on the button? The walking code plays once after clicking on the button. I want to post a message on Processing.org's forum but I don't know how to post message on that forum.

Code:
import controlP5.*;
ControlP5 cp5;
int myColor = color(255);
int c1,c2;
float n,n1;
import processing.serial.*;
Serial myPort;
void setup()
{
  size(700,400);
  noStroke();
  cp5 = new ControlP5(this);
  cp5.addButton("Stand").setValue(0).setPosition(100,100).setSize(100,20);
  cp5.addButton("Sit").setValue(0).setPosition(100,130).setSize(100,20);
  cp5.addButton("Squat").setValue(0).setPosition(100,160).setSize(100,20);
  cp5.addButton("Walk").setValue(0).setPosition(100,190).setSize(100,20);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 115200);
  myPort.write("#0 P1500 T0 \r ");
  myPort.write("#1 P1500 T0 \r ");
  myPort.write("#2 P1500 T0 \r ");
  myPort.write("#3 P1500 T0 \r ");
  myPort.write("#4 P1500 T0 \r ");
  myPort.write("#5 P1500 T0 \r ");
  myPort.write("#6 P1500 T0 \r ");
  myPort.write("#7 P1500 T0 \r ");
  myPort.write("#8 P1500 T0 \r ");
  myPort.write("#9 P1500 T0 \r ");
  myPort.write("#10 P1500 T0 \r ");
  myPort.write("#11 P1500 T0 \r ");
  myPort.write("#12 P500 T0 \r ");
  myPort.write("#13 P2500 T0 \r ");
  myPort.write("#14 P1500 T0 \r ");
  myPort.write("#15 P1500 T0 \r ");
  myPort.write("#16 P1500 T0 \r ");
  myPort.write("#17 P1500 T0 \r ");
  myPort.write("#18 P1500 T0 \r ");
  myPort.write("#19 P1500 T0 \r ");
  myPort.write("#20 P1900 T0 \r ");
  myPort.write("#21 P1900 T0 \r ");
  myPort.write("#22 P1500 T0 \r ");
  myPort.write("#23 P1500 T0 \r ");
}
void draw()
{
  background(0);
  fill(255);
}
void robotstand01()
{
  myPort.write("#0 P1500 T10 \r ");
  myPort.write("#1 P1500 T10 \r ");
  myPort.write("#2 P1500 T10 \r ");
  myPort.write("#3 P1500 T10 \r ");
  myPort.write("#4 P1500 T10 \r ");
  myPort.write("#5 P1500 T10 \r ");
  myPort.write("#6 P1500 T10 \r ");
  myPort.write("#7 P1500 T10 \r ");
  myPort.write("#8 P1500 T10 \r ");
  myPort.write("#9 P1500 T10 \r ");
  myPort.write("#10 P1500 T10 \r ");
  myPort.write("#11 P1500 T10 \r ");
  myPort.write("#12 P500 T10 \r ");
  myPort.write("#13 P2500 T10 \r ");
  myPort.write("#14 P1500 T10 \r ");
  myPort.write("#15 P1500 T10 \r ");
  myPort.write("#16 P1500 T10 \r ");
  myPort.write("#17 P1500 T10 \r ");
  myPort.write("#18 P1500 T10 \r ");
  myPort.write("#19 P1500 T10 \r ");
  myPort.write("#20 P1900 T10 \r ");
  myPort.write("#21 P1900 T10 \r ");
  myPort.write("#22 P1500 T10 \r ");
  myPort.write("#23 P1500 T10 \r ");
}
void robotsit01()
{
  myPort.write("#0 P1500 T10 \r ");
  myPort.write("#1 P1500 T10 \r ");
  myPort.write("#2 P1500 T10 \r ");
  myPort.write("#3 P1500 T10 \r ");
  myPort.write("#4 P1000 T10 \r ");
  myPort.write("#5 P2000 T10 \r ");
  myPort.write("#6 P2000 T10 \r ");
  myPort.write("#7 P1000 T10 \r ");
  myPort.write("#8 P2500 T10 \r ");
  myPort.write("#9 P500 T10 \r ");
  myPort.write("#10 P1500 T10 \r ");
  myPort.write("#11 P1500 T10 \r ");
  myPort.write("#12 P500 T10 \r ");
  myPort.write("#13 P2500 T10 \r ");
  myPort.write("#14 P1500 T10 \r ");
  myPort.write("#15 P1500 T10 \r ");
  myPort.write("#16 P1500 T10 \r ");
  myPort.write("#17 P1500 T10 \r ");
  myPort.write("#18 P1500 T10 \r ");
  myPort.write("#19 P1500 T10 \r ");
  myPort.write("#20 P1900 T10 \r ");
  myPort.write("#21 P1900 T10 \r ");
  myPort.write("#22 P1500 T10 \r ");
  myPort.write("#23 P1500 T10 \r ");
}
void robotsquat01()
{
  myPort.write("#0 P1500 T10 \r ");
  myPort.write("#1 P1500 T10 \r ");
  myPort.write("#2 P500 T10 \r ");
  myPort.write("#3 P2500 T10 \r ");
  myPort.write("#4 P500 T10 \r ");
  myPort.write("#5 P2500 T10 \r ");
  myPort.write("#6 P2500 T10 \r ");
  myPort.write("#7 P500 T10 \r ");
  myPort.write("#8 P2500 T10 \r ");
  myPort.write("#9 P500 T10 \r ");
  myPort.write("#10 P1500 T10 \r ");
  myPort.write("#11 P1500 T10 \r ");
  myPort.write("#12 P500 T10 \r ");
  myPort.write("#13 P2500 T10 \r ");
  myPort.write("#14 P1500 T10 \r ");
  myPort.write("#15 P1500 T10 \r ");
  myPort.write("#16 P1500 T10 \r ");
  myPort.write("#17 P1500 T10 \r ");
  myPort.write("#18 P1500 T10 \r ");
  myPort.write("#19 P1500 T10 \r ");
  myPort.write("#20 P1900 T10 \r ");
  myPort.write("#21 P1900 T10 \r ");
  myPort.write("#22 P1500 T10 \r ");
  myPort.write("#23 P1500 T10 \r ");
}

void robotwalk01()
{
  myPort.write("#0 P1500 T1000 \r ");
  myPort.write("#1 P1500 T1000 \r ");
  myPort.write("#2 P1250 T1000 \r ");
  myPort.write("#3 P1250 T1000 \r ");
  myPort.write("#4 P1500 T1000 \r ");
  myPort.write("#5 P1500 T1000 \r ");
  myPort.write("#6 P1500 T1000 \r ");
  myPort.write("#7 P1500 T1000 \r ");
  myPort.write("#8 P1250 T1000 \r ");
  myPort.write("#9 P1250 T1000 \r ");
  myPort.write("#10 P1500 T1000 \r ");
  myPort.write("#11 P1500 T1000 \r ");
  myPort.write("#12 P500 T1000 \r ");
  myPort.write("#13 P2500 T1000 \r ");
  myPort.write("#14 P1500 T1000 \r ");
  myPort.write("#15 P1500 T1000 \r ");
  myPort.write("#16 P1500 T1000 \r ");
  myPort.write("#17 P1500 T1000 \r ");
  myPort.write("#18 P1500 T1000 \r ");
  myPort.write("#19 P1500 T1000 \r ");
  myPort.write("#20 P1900 T1000 \r ");
  myPort.write("#21 P1900 T1000 \r ");
  myPort.write("#22 P1500 T1000 \r ");
  myPort.write("#23 P1500 T1000 \r ");
}
void robotwalk02()
{
  myPort.write("#0 P1500 T1000 \r ");
  myPort.write("#1 P1500 T1000 \r ");
  myPort.write("#2 P1750 T1000 \r ");
  myPort.write("#3 P1750 T1000 \r ");
  myPort.write("#4 P1500 T1000 \r ");
  myPort.write("#5 P1500 T1000 \r ");
  myPort.write("#6 P1500 T1000 \r ");
  myPort.write("#7 P1500 T1000 \r ");
  myPort.write("#8 P1750 T1000 \r ");
  myPort.write("#9 P1750 T1000 \r ");
  myPort.write("#10 P1500 T1000 \r ");
  myPort.write("#11 P1500 T1000 \r ");
  myPort.write("#12 P500 T1000 \r ");
  myPort.write("#13 P2500 T1000 \r ");
  myPort.write("#14 P1500 T1000 \r ");
  myPort.write("#15 P1500 T1000 \r ");
  myPort.write("#16 P1500 T1000 \r ");
  myPort.write("#17 P1500 T1000 \r ");
  myPort.write("#18 P1500 T1000 \r ");
  myPort.write("#19 P1500 T1000 \r ");
  myPort.write("#20 P1900 T1000 \r ");
  myPort.write("#21 P1900 T1000 \r ");
  myPort.write("#22 P1500 T1000 \r ");
  myPort.write("#23 P1500 T1000 \r ");
}
public void controlEvent(ControlEvent theEvent)
{
  n = 0;
}
public void Stand(int theValue)
{
  robotstand01();
}
public void Sit(int theValue)
{
  robotsit01();
}
public void Squat(int theValue)
{
  robotsquat01();
}
public void Walk(int theValue)
{
  robotwalk01();
  delay(1000);
  robotwalk02();
  delay(1000);
  redraw();
}
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45960
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

draw() is like loop() on the Arduino. Repeating code belongs in draw(). Doesn't the ControlP5 class have a refresh type method? If not, I guess I'd move the declarations into draw() and see what happens.
Logged

Pages: [1]   Go Up
Jump to: