collapse

* Posts Recentes

Amplificador - Rockboard HA 1 In-Ear por almamater
[Ontem às 19:13]


O que é isto ? por KammutierSpule
[26 de Março de 2024, 19:35]


Bateria - Portátil por almamater
[25 de Março de 2024, 22:14]


Emulador NES em ESP32 por dropes
[13 de Março de 2024, 21:19]


Escolher Osciloscópio por jm_araujo
[06 de Fevereiro de 2024, 23:07]


TP4056 - Dúvida por dropes
[31 de Janeiro de 2024, 14:13]


Leitura de dados por Porta Serie por jm_araujo
[22 de Janeiro de 2024, 14:00]


Distancia Cabo por jm_araujo
[08 de Janeiro de 2024, 16:30]


Meu novo robô por josecarlos
[06 de Janeiro de 2024, 16:46]


Laser Engraver - Alguém tem? por almamater
[16 de Dezembro de 2023, 14:23]

Autor Tópico: Processing  (Lida 2915 vezes)

0 Membros e 1 Visitante estão a ver este tópico.

Offline TheDeadLives

  • Mini Robot
  • *
  • Mensagens: 398
Processing
« em: 26 de Dezembro de 2011, 20:45 »
Alguém percebe muito de processing? Eu apenas percebo um pouco. Tenho este programa, mas infelizmente não está a funcionar e não percebo porquê.

Código: [Seleccione]
import processing.serial.*;

Serial port;

int M1LX, M1RX, M2LX, M2RX, M3LX, M3RX, M4LX, M4RX, M5LX, M5RX;
int M1LY, M1RY, M2LY, M2RY, M3LY, M3RY, M4LY, M4RY, M5LY, M5RY;

int boxSize = 64;
arrow myRightArrow;
int[]rightArrowxpoints={30,54,30,30,0,0,30};
int[]rightArrowypoints={0,27,54,40,40,15,15};
arrow myLeftArrow;
int[]leftArrowxpoints={0,24,24,54,54,24,24};
int[]leftArrowypoints={27,0,15,15,40,40,54};
PFont myFont;

void setup()
{size(145, 455);
M1LX = 5;
M1LY = 25;
M1RX = 75;
M1RY = 25;
M2LX = 5;
M2LY = 115;
M2RX = 75;
M2RY = 115;
M3LX = 5;
M3LY = 205;
M3RX = 75;
M3RY = 205;
M4LX = 5;
M4LY = 295;
M4RX = 75;
M4RY = 295;
M5LX = 5;
M5LY = 385;
M5RX = 75;
M5RY = 385;

println(Serial.list());
myFont = createFont("verdana", 12);
textFont(myFont);
port = new Serial(this, Serial.list()[1], 9600);
myRightArrow = new arrow(rightArrowxpoints,rightArrowypoints,7);
myLeftArrow = new arrow(leftArrowxpoints,leftArrowypoints,7);
}

void draw()
{
background(0);
noStroke();fill(150);
text("Base Motor (q|Q/w|W)", 5, 5, 200, 75);
text("Shoulder Motor (e|E/r|R)", 5, 95, 200, 75);
text("Elbow Motor (t|T/y|y)", 5, 185, 200, 75);
text("Wrist Motor (u|u/i|I)", 5, 275, 200, 75);
text("Hand Motor (o|O/p|P)", 5, 365, 200, 75);

if(keyPressed)
{
if (key == 'q' || key == 'Q')
{
port.write('Q');
}
if (key == 'w' || key == 'W')
{
port.write('W');
}
if (key == 'e' || key == 'E')
{
port.write('E');
}
if (key == 'r' || key == 'R')
{
port.write('R');
}
if (key == 't' || key == 'T')
{
port.write('T');
}
if (key == 'y' || key == 'y')
{
port.write('Y');
}
if (key == 'u' || key == 'U')
{
port.write('U');
}
if (key == 'i' || key == 'I')
{
port.write('I');
}
if (key == 'O' || key == 'O')
{
port.write('Z');
}
if (key == 'p' || key == 'P')
{
port.write('P');
}
if (key == 'o' || key == 'O')
{
port.write('O');
}
}
else if (mousePressed == true) {
if (mouseX > M1LX-boxSize && mouseX < M1LX+boxSize &&
mouseY > M1LY-boxSize && mouseY < M1LY+boxSize) {
port.write('Q');
}
else if(mouseX > M1RX-boxSize && mouseX < M1RX+boxSize &&
mouseY > M1RY-boxSize && mouseY < M1RY+boxSize) {
port.write('W');
}
else if(mouseX > M2LX-boxSize && mouseX < M2LX+boxSize &&
mouseY > M2LY-boxSize && mouseY < M2LY+boxSize) {
port.write('E');
}
else if(mouseX > M2RX-boxSize && mouseX < M2RX+boxSize &&
mouseY > M2RY-boxSize && mouseY < M2RY+boxSize) {
port.write('R');
}
else if(mouseX > M3LX-boxSize && mouseX < M3LX+boxSize &&
mouseY > M3LY-boxSize && mouseY < M3LY+boxSize) {
port.write('T');
}
else if(mouseX > M3RX-boxSize && mouseX < M3RX+boxSize &&
mouseY > M3RY-boxSize && mouseY < M3RY+boxSize) {fill(200);
port.write('Y');
}
else if (mouseX > M4LX-boxSize && mouseX < M4LX+boxSize &&
mouseY > M4LY-boxSize && mouseY < M4LY+boxSize) {
port.write('U');
}
else if(mouseX > M4RX-boxSize && mouseX < M4RX+boxSize &&
mouseY > M4RY-boxSize && mouseY < M4RY+boxSize) {
port.write('I');
}
else if (mouseX > M5LX-boxSize && mouseX < M5LX+boxSize &&
mouseY > M5LY-boxSize && mouseY < M5LY+boxSize) {
port.write('O');
}
else if(mouseX > M5RX-boxSize && mouseX < M5RX+boxSize &&
mouseY > M5RY-boxSize && mouseY < M5RY+boxSize) {
port.write('P');
}
else {
port.write('G');
}
}

myRightArrow.drawArrow(80,30);
myRightArrow.drawArrow(80,120);
myRightArrow.drawArrow(80,210);
myRightArrow.drawArrow(80,300);
myRightArrow.drawArrow(80,390);
myLeftArrow.drawArrow(10,30);
myLeftArrow.drawArrow(10,120);
myLeftArrow.drawArrow(10,210);
myLeftArrow.drawArrow(10,300);
myLeftArrow.drawArrow(10,390);
}

class arrow extends java.awt.Polygon {
public arrow(int[] xpoints,int[] ypoints, int npoints) {
super(xpoints,ypoints,npoints);

}
void drawArrow(int xOffset, int yOffset){
fill(150);
rect(xOffset-5, yOffset-5, boxSize, boxSize);
fill(255);
beginShape();
for(int i=0;i<npoints;i++){
vertex(xpoints[i]+xOffset,ypoints[i]+yOffset);
}
endShape();
}
}

O erro que me dá é o seguinte:
Citar
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 1, na linha: port = new Serial(this, Serial.list()[1], 9600);.

Se alguém me pudesse ajudar ficaria muito agradecido.


« Última modificação: 27 de Dezembro de 2011, 11:55 por TigPT »

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: Processing
« Responder #1 em: 26 de Dezembro de 2011, 21:38 »
Provavelmente só tens um interface serial, e como estás a escolher o segundo do array dá barraca, experimenta mudar para
  • .
Avr fanboy

Offline TheDeadLives

  • Mini Robot
  • *
  • Mensagens: 398
Re: Processing
« Responder #2 em: 27 de Dezembro de 2011, 00:36 »
Mudo para quê??

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: Processing
« Responder #3 em: 27 de Dezembro de 2011, 03:07 »
Ups, matei os bbcode..
Muda isto:
Código: [Seleccione]
port = new Serial(this, Serial.list()[1], 9600);

Para isto:
Código: [Seleccione]
port = new Serial(this, Serial.list()[0], 9600);
Avr fanboy

Offline TheDeadLives

  • Mini Robot
  • *
  • Mensagens: 398
Re: Processing
« Responder #4 em: 27 de Dezembro de 2011, 13:20 »
Ups, matei os bbcode..
Muda isto:
Código: [Seleccione]
port = new Serial(this, Serial.list()[1], 9600);

Para isto:
Código: [Seleccione]
port = new Serial(this, Serial.list()[0], 9600);


Também já fiz. Continua a dar erro. Mas em vez de dar este erro (Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 1) dá este: Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 0.


Se mudar o 1 para outro valor, por exemplo, 3, o erro que dá é este: Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 3. Depois dos dois pontos, muda para esse valor. E já não sei o que fazer mais.


Se consiguir ajudar-me, ficaria-lhe muito agradecido. Ou se mais alguém conseguir.


Agradecido
« Última modificação: 27 de Dezembro de 2011, 13:23 por TheDeadLives »

Offline senso

  • Global Moderator
  • Mini Robot
  • *****
  • Mensagens: 9.733
  • Helpdesk do sitio
Re: Processing
« Responder #5 em: 27 de Dezembro de 2011, 13:56 »
Comenta tudo e deixa só o println(Serial.list());
Se isso não der nada na consola do processing é porque não tens nada com interface serial ligado ao pc.
Avr fanboy

Offline TheDeadLives

  • Mini Robot
  • *
  • Mensagens: 398
Re: Processing
« Responder #6 em: 27 de Dezembro de 2011, 20:32 »
Continua sem funcionar. Se fizer isso, a seguir vai me dar um erra mais à frente. Se comentar a linha do erro, vai-me dar outro erro. E sempre assim.

Supostamente o programa que o arduino está a correr é este:

Código: [Seleccione]
int baseMotorEnablePin = 2;
int baseMotorPin1 = 3;
int baseMotorPin2 = 4;
int shoulderMotorEnablePin = 14;
int shoulderMotorPin1 = 15;
int shoulderMotorPin2 = 16;
int elbowMotorEnablePin = 8;
int elbowMotorPin1 = 9;
int elbowMotorPin2 = 10;
int wristMotorEnablePin = 5;
int wristMotorPin1 = 6;
int wristMotorPin2 = 7;
int handMotorEnablePin = 11;
int handMotorPin1 = 17;
int handMotorPin2 = 18;
int incomingByte;
 
void setup() {
  pinMode(baseMotorPin1, OUTPUT);
  pinMode(baseMotorPin2, OUTPUT);
  pinMode(baseMotorEnablePin, OUTPUT);
  digitalWrite(baseMotorEnablePin, HIGH);
  pinMode(shoulderMotorPin1, OUTPUT);
  pinMode(shoulderMotorPin2, OUTPUT);
  pinMode(shoulderMotorEnablePin, OUTPUT);
  digitalWrite(shoulderMotorEnablePin, HIGH);
  pinMode(elbowMotorPin1, OUTPUT);
  pinMode(elbowMotorPin2, OUTPUT);
  pinMode(elbowMotorEnablePin, OUTPUT);
  digitalWrite(elbowMotorEnablePin, HIGH);
  pinMode(wristMotorPin1, OUTPUT);
  pinMode(wristMotorPin2, OUTPUT);
  pinMode(wristMotorEnablePin, OUTPUT);
  digitalWrite(wristMotorEnablePin, HIGH);
  pinMode(handMotorPin1, OUTPUT);
  pinMode(handMotorPin2, OUTPUT);
  pinMode(handMotorEnablePin, OUTPUT);
  digitalWrite(handMotorEnablePin, HIGH);
  Serial.begin(9600);
}
 
void loop() {
  if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if (incomingByte == 'Q') {
    digitalWrite(baseMotorPin1, LOW);
    digitalWrite(baseMotorPin2, HIGH);
    }
    if (incomingByte == 'W') {
    digitalWrite(baseMotorPin1, HIGH);
    digitalWrite(baseMotorPin2, LOW);
    }
    if (incomingByte == 'E') {
    digitalWrite(shoulderMotorPin1, LOW);
    digitalWrite(shoulderMotorPin2, HIGH);
    }
    if (incomingByte == 'R') {
    digitalWrite(shoulderMotorPin1, HIGH);
    digitalWrite(shoulderMotorPin2, LOW);
    }
    if (incomingByte == 'A') {
    digitalWrite(elbowMotorPin1, LOW);
    digitalWrite(elbowMotorPin2, HIGH);
    }
    if (incomingByte == 'S') {
    digitalWrite(elbowMotorPin1, HIGH);
    digitalWrite(elbowMotorPin2, LOW);
    }
    if (incomingByte == 'D') {
    digitalWrite(wristMotorPin1, LOW);
    digitalWrite(wristMotorPin2, HIGH);
    }
    if (incomingByte == 'F') {
    digitalWrite(wristMotorPin1, HIGH);
    digitalWrite(wristMotorPin2, LOW);
    }
    if (incomingByte == 'Z') {
    digitalWrite(handMotorPin1, LOW);
    digitalWrite(handMotorPin2, HIGH);
    }
    if (incomingByte == 'X') {
    digitalWrite(handMotorPin1, HIGH);
    digitalWrite(handMotorPin2, LOW);
    }
    // if a O is sent make sure the motors are turned off
    if (incomingByte == 'O') {
    digitalWrite(baseMotorPin1, LOW);
    digitalWrite(baseMotorPin2, LOW);
    digitalWrite(shoulderMotorPin1, LOW);
    digitalWrite(shoulderMotorPin2, LOW);
    digitalWrite(elbowMotorPin1, LOW);
    digitalWrite(elbowMotorPin2, LOW);
    digitalWrite(wristMotorPin1, LOW);
    digitalWrite(wristMotorPin2, LOW);
    digitalWrite(handMotorPin1, LOW);
    digitalWrite(handMotorPin2, LOW);
    }
  }
}

O do Arduino está a correr normalmente. Supostamente, o do processing era para dar um aspecto mais engraçado. Mas não está a funcionar, como já disse, mas ao que me parece, está tudo bem. O senhor também não consegue, não há mais ninguèm? Eu postei o código do arduino, para ver, se quiser, experimentar no seu a ver se dá.