Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How can I transform the processing.net into oscP5?

$
0
0

Hi. I've made a code for controlling my drone with processing.net library from my computer, and they say that I need to use oscP5 to send messages to my drone from Android because they say processing.net library is not valid in processing for Android. So I transformed processing.net into oscP5 but it didn't work! Would you please help me to check what's wrong? The code below used processing.net

` import processing.net.*; import controlP5.*;

ControlP5 cp5;
Client comPort;

void setup(){
  fullScreen();
  noStroke();
  cp5 = new ControlP5(this);

  cp5.addTextlabel("", "Drone control")
     .setPosition(width/3, height/10)
     .setColorValue(0xffe00000)
     .setFont(createFont("TTF", width/15))
   ;

  comPort = new Client (this, "192.168.4.1", 23);

  sendCommand('T', 0);}


void draw() {
  fill(255);
  triA();
  triC();
  if (mousePressed){if(mouseX<width/3 && mouseY<4*height/5){fill(0,0,255); triA();sendCommand('T', 50);}}
  if(mouseX>2*width/3&&mouseY<4*height/5){fill(0,0,255);triC();sendCommand('T', 0);}}

void triA()
{triangle(width/4,3*height/5,width/3,4*height/5,width/3,2*height/5);}
void triC()
{triangle(3*width/4, 3*height/5, 2*width/3, 4*height/5, 2*width/3, 2*height/5);}

public void sendCommand(char cmdType, int value) {
  comPort.write('$');
  comPort.write('M');
  comPort.write('<');
  comPort.write(cmdType);
  comPort.write(value);}`

And the code below is for oscP5

` import oscP5.*; import netP5.*; import controlP5.*;

ControlP5 cp5;
OscP5 oscP5;
NetAddress myRemoteLocation;

void setup(){
  fullScreen();
  noStroke();
  cp5 = new ControlP5(this);

  cp5.addTextlabel("", "Drone control")
     .setPosition(width/3, height/10)
     .setColorValue(0xffe00000)
     .setFont(createFont("TTF", width/15))
   ;

  oscP5 = new OscP5(this, 23);

  myRemoteLocation = new NetAddress("192.168.4.1", 23);
  sendCommand('T', 0);}


void draw() {
  fill(255);
  triA();
  triC();
  if (mousePressed){if(mouseX<width/3 && mouseY<4*height/5){fill(0,0,255); triA();sendCommand('T', 50);}}
  if(mouseX>2*width/3&&mouseY<4*height/5){fill(0,0,255);triC();sendCommand('T', 0);}}

void triA()
{triangle(width/4,3*height/5,width/3,4*height/5,width/3,2*height/5);}
void triC()
{triangle(3*width/4, 3*height/5, 2*width/3, 4*height/5, 2*width/3, 2*height/5);}

public void sendCommand(char cmdType, int value)
{OscMessage myMessage = new OscMessage("/test");
myMessage.add('$');
myMessage.add('M');
myMessage.add('<');
myMessage.add(cmdType);
myMessage.add(value);
oscP5.send(myMessage, myRemoteLocation);}`

You might think "Those codes are really weird". Well.... that's because I learned about coding just a few days ago and don't know where to start with because there is no one to teach me.

Oh..!! I need to send the message $, M, <, T, 50 in a row and '192.168.4.1' is the net address for the wifi of drone (I used the ESP-8266 model), and 23 is the port number for my drone. Maybe, I think, it's because the error in the port number of OscP5 is the matter.....maybe...maybe.... But I don't know the port number of my phone..... Could you please help me to make it out??


Viewing all articles
Browse latest Browse all 2896

Trending Articles