Pages: [1]   Go Down
Author Topic: OSC data to Arduino  (Read 892 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
#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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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*'
Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 22
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if ((rcvMes->getOSCAddress()).checkAddress("/accxyz")==true)

with something like

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


Logged

C.

Pages: [1]   Go Up
Jump to: