Hello, 

i have a problem of receiving a buffered data from AX12 servo motor. 
I'm using processing in this project. i have succeed to send the data. and 
make the motor move. 
but the receiving part remain unsolved. here is my code 


import ioio.lib.api.*;
import ioio.lib.api.exception.*;
import com.pinkhatproductions.pioio.*;
import java.io.*;


// for connection to pc host
static {
  // leave commented out to auto-discover serial port (SLOW!)  
  //System.setProperty("ioio.SerialPorts", "/dev/tty.usbmodem1411");
}


char iPING        =0x01; //obtain a status packet
char iREAD_DATA    =0x02; //read Control Table values
char iWRITE_DATA  =0x03; //write Control Table values
char iREG_WRITE   =0x04; //write and wait for ACTION instruction
char iACTION     =0x05; //triggers REG_WRITE instruction
char iRESET       =0x06; //set factory defaults
char iSYNC_WRITE  =0x83; //simultaneously control multiple actuators
char  GOAL_POSITION_L=0x1E;
char  PRESENT_POSITION_L=0x24; 
char  PRESENT_POSITION_H=0x25; 
char  PRESENT_SPEED_L=0x26; 
char  PRESENT_SPEED_H=0x27; 
char  PRESENT_LOAD_L=0x28; 
char  PRESENT_LOAD_H=0x29; 
char  LED=0x19;
char  TORQUE_ENABLE=0x18;
char  PRESENT_VOLTAGE=0x2A; 
PIOIOManager ioioManager = new PIOIOManager(this);

Uart uart;
DigitalOutput led;
DigitalOutput DTR;
OutputStream out;
InputStream in;
BufferedReader bufrd;
char checksum=0;
char[] TxBuff = new char[16];
char[] reading = new char[16];
char packet_len;

void setup() {
  size(800, 600);
  ioioManager.start();
  
  
  
}

void draw() {
  background(200);
  fill(0);
  textSize(28);
  text(" ground motor value :" +reading, 10, height/2);
  
}

void mouseReleased() {
    destroy();
}

void mousePressed() {
  
  get_pos(char(6));
  
  
}

void destroy() {
  led_torq(char(6));
}



void ioioSetup(IOIO ioio) throws ConnectionLostException {
  
  uart = ioio.openUart(4, 6, 115200, Uart.Parity.NONE, Uart.StopBits.ONE);
  led = ioio.openDigitalOutput(IOIO.LED_PIN, true);
  DTR = ioio.openDigitalOutput(18, true);
  
  
  in = uart.getInputStream();
  out = uart.getOutputStream();
  

        bufrd = new BufferedReader(new InputStreamReader(in));
     
  
}

void ioioLoop(IOIO ioio) throws ConnectionLostException {
  
  led.write(false);
  
  
  try {
    
    

    Thread.sleep(20);
  }
  catch (InterruptedException e) {
  }
}


void led_torq(char id){
  
  try {
    
    DTR.write(true);
    
  try{
  
    
           //clear checksum value
         out.write(0xFF);                         
         out.write(0xFF);
         out.write(0x06);
         out.write(0x05);
         out.write(0x03);
         out.write(0x18);
         out.write(0x00);
         out.write(0x01);
         out.write(0xDD);
         
  }
  
  catch (IOException e){
    }
    
}
catch (ConnectionLostException e) {
  }
}

     

void get_pos (char id){
  
   try {
    
    DTR.write(true);
    
    checksum=0;          //clear checksum value
    TxBuff[0] = 0xFF;      //0xFF not included in checksum
    TxBuff[1] = 0xFF;
    TxBuff[2] = id;               
    checksum += TxBuff[2];  
    TxBuff[3] = char(4);          // param_len +2
    checksum += 
TxBuff[3];                                                                      
                               

    TxBuff[4] = iREAD_DATA;        // instruction       
    checksum += TxBuff[4];
    TxBuff[5] = PRESENT_POSITION_L;  //Control Starting Address
    checksum += TxBuff[5];
    TxBuff[6]=char(~checksum);
    
     packet_len =char(7);     //TxBuff[3] + 4     number  of bytes for the 
whole packet
    
    try {
    for(int i=0; i<packet_len;i++)
    {
      out.write(TxBuff[i]);           //the library waits for transfer 
complete, output.flush() is called
    }
    }
    catch (IOException e){
    }
    
    delay(20);
    
    DTR.write(false);
    
     try {
       int count = in.available();
    println(" bytes = " + count);
    
    if (count > 0){
//    for(i=0; i<count;i++)
//    {
     bufrd.read(reading);           //the library waits for transfer 
complete, output.flush() is called
//    }
    }
     }
    catch (IOException e){
    }
    

   
  }
  catch (ConnectionLostException e) {
  }
}

-- 
You received this message because you are subscribed to the Google Groups 
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to