Leonardo Noccilicenziato assuntoGiovanni Burresi
Created January 22, 2016 © GPL3+

Rapiroo

Various control mode for Rapiro robot using UDOO NEO board, like App Inventor 2 app, python. php and maybe Kinect.

IntermediateWork in progress356
Rapiroo

Things used in this project

Hardware components

UDOO NEO
UDOO NEO
×1
Ktec Cavo Adattatore Universale di Alimentazione, 12V, 2A, 2000 mAh, 5.5 x 2.1 mm, 1.5 m, Nero/Antracite
×1

Hand tools and fabrication machines

Rapiro

Story

Read more

Code

Python comunication for Rapiro

Python
Python program to send Rapiro's command over LAN
#SENDING PROGRAM
#example of packet to send  <1180> 1 Idservo   180 angle

import socket
import sys

UDP_IP = "0.0.0.0"#default IP address
UDP_PORT = 5005#default 
default ="<190><290><330><4140><5170><6100>"#rapiro initial position
MESSAGE = default

UDP_IP = raw_input("select rapiro IP: ")
print "UDP target IP:", UDP_IP
print "UDP target port:", UDP_PORT
print "message:", MESSAGE

#connection to Rapiro   
sock = socket.socket(socket.AF_INET, # Internet
                        socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))#first message send

while True:#only if the command "exit" is pressed the program is closed
    MESSAGE = raw_input("Insert command: (type exit to close)")
    if MESSAGE == "exit":
        exit()
        
    sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
    print "Message sent: " + MESSAGE

exit()

Python comunication for Rapiro

Python
Python program to receive Rapiro's command over LAN
#RECEIVING PROGRAM (open on UDOO board)
import socket
import serial
UDP_IP = "0.0.0.0"
UDP_PORT = 5005
UDP_IP= raw_input("select IP: ")

sock = socket.socket(socket.AF_INET, # Internet
			socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))

ser=serial.Serial("/dev/ttyMCC")

while True:
	try:
		data, addr = sock.recvfrom(1024) # buffer size is 1024 byte
		print "received message:", data
		ser.write(data)
	except KeyboardInterrupt:
		ser.close()
		sys.exit()

Arduino code to control Rapiro

Arduino
#include <Servo.h>

char value[20],let,Idservo;
int angle,err,c=0;

Servo head,waist,shld_dx,shld_sx,arm_dx,arm_sx;

void setup(){
  Serial.begin(9600);//inizialize serial port
  head.attach(11);//inizialize servo motors
  waist.attach(10);//
  shld_dx.attach(9);//
  shld_sx.attach(6);//
  arm_dx.attach(5);//
  arm_sx.attach(3);//
}

void loop(){
if(Serial.available()>1){//begin the read only if there are data in the buffer 
  let=Serial.read();
  if(let=='<'){//if the first characters read is equal to"<" start the loop
    Serial.readBytesUntil('>',value,20);//store the values into value array after "<" characters until the ">" characters in found
    Idservo=value[0]; //the first character is the Idservo
    if(value[4]!=0){
      
      goto invalidPacket;//discards the packet if the number of digits is more than 4
      
       }
    for(int i=0;i<4;i++){
       value[i]=value[i+1];
    }//move 1-->0  2-->1   3-->2  4-->3
            
    angle=atoi(value);//converts the value array into int number
    Serial.print(Idservo);
    Serial.print("\t\t");
    Serial.println(angle);
    switch(Idservo){
      case '1'://Head's Idservo 
      head.write(angle);
      break;
      case '2'://waist'sIdservo
      waist.write(angle);
      break;
      case '3'://right shoulder's Idservo
      shld_dx.write(angle);
      break;
      case '4'://left shoulder's Idservo
      shld_sx.write(angle);
      break;
      case '5'://right arm's Idservo
      arm_dx.write(angle);
      break;
      case '6'://left arm's id servo
      arm_sx.write(angle);
      case 's'://if s is pressed,go to initial position
      head.write(90);
      waist.write(90);
      shld_dx.write(30);
      shld_sx.write(140);
      arm_dx.write(170);
      arm_sx.write(100);
      break;
      default:
      break;
    }
  }
    else{//if the first character in the buffer is different from"<" discards it 
    err=let;
    Serial.println(err);
    }  
    
}
invalidPacket://if the packet have more than 3 digit,discards it and go into the main loop
memset(value,0,20);//reset array
//Serial.flush();
}

Receiving program using bluetooth

Arduino
//use the program with Rapiroo's app

#include <SoftwareSerial.h>

#include <Servo.h>

char value[20],let,Idservo;
int angle,err,c=0;
#define Tx 2
#define Rx 4
Servo head,waist,shld_dx,shld_sx,arm_dx,arm_sx;
SoftwareSerial bluetooth =  SoftwareSerial(Rx, Tx);//initialize Serial port on bluetooth (attach Bluetooth RX to Arduino TX and vice versa)

void setup(){
  Serial.begin(9600);
  bluetooth.begin(9600);//inizialize serial port
  head.attach(11);//inizialize servo motors
  waist.attach(10);//
  shld_dx.attach(9);//
  shld_sx.attach(6);//
  arm_dx.attach(5);//
  arm_sx.attach(3);//
}

void loop(){
if(bluetooth.available()>1){//begin the read only if there are data in the buffer 
  let=Serial.read();
  if(let=='<'){//if the first characters read is equal to"<" start the loop
    bluetooth.readBytesUntil('>',value,20);//store the values into value array after "<" characters until the ">" characters in found
    Idservo=value[0]; //the first character is the Idservo
    if(value[4]!=0){
      
      goto invalidPacket;//discards the packet if the number of digits is more than 4
      
       }
    for(int i=0;i<4;i++){
       value[i]=value[i+1];
    }//move 1-->0  2-->1   3-->2  4-->3
            
    angle=atoi(value);//converts the value array into int number
    Serial.print(Idservo);
    Serial.print("\t\t");
    Serial.println(angle);
    switch(Idservo){
      case '1'://Head's Idservo 
      head.write(angle);
      break;
      case '2'://waist'sIdservo
      waist.write(angle);
      break;
      case '3'://right shoulder's Idservo
      shld_dx.write(angle);
      break;
      case '4'://left shoulder's Idservo
      shld_sx.write(angle);
      break;
      case '5'://right arm's Idservo
      arm_dx.write(angle);
      break;
      case '6'://left arm's id servo
      arm_sx.write(angle);
      case 's'://if s is pressed,go to initial position
      head.write(90);
      waist.write(90);
      shld_dx.write(30);
      shld_sx.write(140);
      arm_dx.write(170);
      arm_sx.write(100);
      break;
      default:
      break;
    }
  }
    else{//if the first character in the buffer is different from"<" discards it 
    err=let;
    Serial.println(err);
    }  
    
}
invalidPacket://if the packet has more than 3 digit,discards it and go into the main loop
memset(value,0,20);//reset array
//Serial.flush();
}

Credits

Leonardo Nocci

Leonardo Nocci

1 project • 3 followers
licenziato assunto

licenziato assunto

1 project • 3 followers
Giovanni Burresi

Giovanni Burresi

2 projects • 9 followers
i'm a PhD student at University of Florence. I work with UDOO Team and I love to build un-useful things! :D Love tech, music, and especially SMART People!!

Comments