Go Down

Topic: OSC data to Arduino (Read 1 time) previous topic - next topic

Nubee

I'm getting OSC data from the iPhone accelerometer to my Arduino that I need to separate out. This snippet of a Processing sketch suggests that "/accxyz" has 3 address 0, 1 and 2 for x, y and z respectively.
Code: [Select]
void oscEvent(OscMessage theOscMessage) {
  if(theOscMessage.checkAddrPattern("/accxyz")==true) {
      xrot_targ = (theOscMessage.get(0).floatValue()*90);
      zrot_targ = (theOscMessage.get(1).floatValue()*90)*-1;
      orientation = theOscMessage.get(2).floatValue();

I need to separate the x and y values to send to servos. My sketch below is giving me compiling errors but I'm not sure why.
Code: [Select]
#include <Ethernet.h>
#include <Servo.h>
#include <ArdOSC.h>
#include <WString.h>


byte myMac[] = { 0x90, 0xA2, 0x2A, 0x00, 0x2D, 0x00 };
byte myIp[]  = { 10, 0, 0, 10 };
int  serverPort  = 8000;
float x = 0;
float y = 0;

 
OSCServer server;

OSCMessage *rcvMes;

Servo ltservo;
Servo rtservo;


void setup(){
 
Serial.begin(19200);
ltservo.attach (5);
rtservo.attach (6);

Ethernet.begin(myMac ,myIp);

server.sockOpen(serverPort);
   
}
 
void loop(){

if(server.available()){
   
  rcvMes=server.getMessage();

  logMessage();
   
}   
}
 
 
void logMessage(){
    uint16_t i;
    byte *ip=rcvMes->getIpAddress();
   
    long int intValue;
    float floatValue;
    char *stringValue;
   
   /* Serial.print(ip[0],DEC);
    Serial.print(".");
    Serial.print(ip[1],DEC);
    Serial.print(".");
    Serial.print(ip[2],DEC);
    Serial.print(".");
    Serial.print(ip[3],DEC);
    Serial.print(":");
   
    Serial.print(rcvMes->getPortNumber());
   */ Serial.print(" ");
    Serial.print(rcvMes->getOSCAddress());
    Serial.print(" ");
    Serial.print(rcvMes->getTypeTags());
    Serial.print("--");
         
          floatValue = rcvMes->getFloat(i);
     
       if ((rcvMes->getOSCAddress()).checkAddress("/accxyz")==true)
        Serial.println ((rcvMes->getOSCAddress()).get(0).floatValue());
        Serial.println ((rcvMes->getOSCAddress()).get(1).floatValue());
         
}


Right now I'm just trying to see the different values for x and y printed out. I've tried to recreate how Processing separates it out, but to no avail. I'm using IDE 018 (that's what ArdOSC likes) if that helps.

Thanks,
Dave

Nubee

Sorry...

This is the line that errors out:
if ((rcvMes->getOSCAddress()).checkAddress("/accxyz")==true)

Error is:
request for member 'checkAddress' In 'rcvMes->OSCMessage::getOSCAddress()', which is non-class type 'char*'

cmaglie


if ((rcvMes->getOSCAddress()).checkAddress("/accxyz")==true)

Error is:
request for member 'checkAddress' In 'rcvMes->OSCMessage::getOSCAddress()', which is non-class type 'char*'


getOSCAddress() method returns a C-string (char*) that is not a class and can't have a method called "checkAddress".
If you want to compare that string with "/accxyz" you must use strcmp and replace

Code: [Select]

if ((rcvMes->getOSCAddress()).checkAddress("/accxyz")==true)


with something like

Code: [Select]

if (strcmp(rcvMes->getOSCAddress(), "/accxyz")==0)



C.

Go Up