Hardi Kurnianto
Published

Robot A.P.R.I.L.I.A

A robot that can move objects with voice commands from android by setting the speed of movement based on the dimensions of the object to be

IntermediateShowcase (no instructions)24 hours252
Robot A.P.R.I.L.I.A

Things used in this project

Hardware components

MG995 Servo
×1
Arduino Nano R3
Arduino Nano R3
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
NVIDIA Jetson Nano Developer Kit
NVIDIA Jetson Nano Developer Kit
×1
Webcam, Logitech® HD Pro
Webcam, Logitech® HD Pro
×1

Software apps and online services

Arduino BlueControl
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Code

Program Robot

Arduino
#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial hc05(2,3);

Servo base;
Servo dof1;
Servo dof2;
Servo dof3;
Servo dof4;
Servo dof5;

int database,posbase;
int datadof1,posdof1;
int datadof2,posdof2;
int datadof3,posdof3;
int datadof4,posdof4;
int datadof5,posdof5;

void setup() 
{
  Serial.begin(9600);
  hc05.begin(9600);
  base.attach(12);
  dof1.attach(11);
  dof2.attach(10);
  dof4.attach(9);
  dof3.attach(8);
  dof5.attach(7);
  rumah();
}

void loop() 
{
 if(hc05.available())
 {
  unsigned char data = hc05.read();
  if(data=='q'){
                database=base.read(); datadof1=dof1.read(); datadof2=dof2.read(); datadof3=dof3.read(); datadof4=dof4.read();
                
                if(datadof3>=50){for(posdof3=datadof3; posdof3>=50; posdof3-=1){dof3.write(posdof3); delay(30);}}
                if(datadof3<=50){for(posdof3=datadof3; posdof3<=50; posdof3+=1){dof3.write(posdof3); delay(30);}}
                
                if(datadof4>=180){for(posdof4=datadof4; posdof4>=180; posdof4-=1){dof4.write(posdof4); delay(30);}}
                if(datadof4<=180){for(posdof4=datadof4; posdof4<=180; posdof4+=1){dof4.write(posdof4); delay(30);}}
                
                if(datadof1>=100){for(posdof1=datadof1; posdof1>=100; posdof1-=1){dof1.write(posdof1); delay(30);}}
                if(datadof1<=100){for(posdof1=datadof1; posdof1<=100; posdof1+=1){dof1.write(posdof1); delay(30);}}
                
                capit();         delay(1000);
                database=base.read(); datadof1=dof1.read(); datadof2=dof2.read(); datadof3=dof3.read(); datadof4=dof4.read();

                if(datadof4>=90){for(posdof4=datadof4; posdof4>=90; posdof4-=1){dof4.write(posdof4); delay(30);}}
                if(datadof4<=90){for(posdof4=datadof4; posdof4<=90; posdof4+=1){dof4.write(posdof4); delay(30);}}

                if(datadof3>=90){for(posdof3=datadof3; posdof3>=90; posdof3-=1){dof3.write(posdof3); delay(30);}}
                if(datadof3<=90){for(posdof3=datadof3; posdof3<=90; posdof3+=1){dof3.write(posdof3); delay(30);}}

                if(datadof1>=160){for(posdof1=datadof1; posdof1>=160; posdof1-=1){dof1.write(posdof1); delay(30);}}
                if(datadof1<=160){for(posdof1=datadof1; posdof1<=160; posdof1+=1){dof1.write(posdof1); delay(30);}}
               
                if(database>=120){for(posbase=database; posbase>=120; posbase-=1){base.write(posbase); delay(30);}}
                if(database<=120){for(posbase=database; posbase<=120; posbase+=1){base.write(posbase); delay(30);}}
                }
  if(data=='w'){
                database=base.read(); datadof1=dof1.read(); datadof2=dof2.read(); datadof3=dof3.read(); datadof4=dof4.read();
                
                if(datadof1>=100){for(posdof1=datadof1; posdof1>=100; posdof1-=1){dof1.write(posdof1); delay(30);}}
                if(datadof1<=100){for(posdof1=datadof1; posdof1<=100; posdof1+=1){dof1.write(posdof1); delay(30);}}

                if(datadof4>=180){for(posdof4=datadof4; posdof4>=180; posdof4-=1){dof4.write(posdof4); delay(30);}}
                if(datadof4<=180){for(posdof4=datadof4; posdof4<=180; posdof4+=1){dof4.write(posdof4); delay(30);}}

                if(datadof3>=50){for(posdof3=datadof3; posdof3>=50; posdof3-=1){dof3.write(posdof3); delay(30);}}
                if(datadof3<=50){for(posdof3=datadof3; posdof3<=50; posdof3+=1){dof3.write(posdof3); delay(30);}}
      
                lepas();         delay(1000);
                database=base.read(); datadof1=dof1.read(); datadof2=dof2.read(); datadof3=dof3.read(); datadof4=dof4.read();

                if(datadof1>=160){for(posdof1=datadof1; posdof1>=160; posdof1-=1){dof1.write(posdof1); delay(30);}}
                if(datadof1<=160){for(posdof1=datadof1; posdof1<=160; posdof1+=1){dof1.write(posdof1); delay(30);}}

                if(datadof3>=90){for(posdof3=datadof3; posdof3>=90; posdof3-=1){dof3.write(posdof3); delay(30);}}
                if(datadof3<=90){for(posdof3=datadof3; posdof3<=90; posdof3+=1){dof3.write(posdof3); delay(30);}}

                if(datadof4>=90){for(posdof4=datadof4; posdof4>=90; posdof4-=1){dof4.write(posdof4); delay(30);}}
                if(datadof4<=90){for(posdof4=datadof4; posdof4<=90; posdof4+=1){dof4.write(posdof4); delay(30);}}
                
                //if(database>=30){for(posbase=database; posbase>=30; posbase-=1){base.write(posbase); delay(10);}}
                //if(database<=30){for(posbase=database; posbase<=30; posbase+=1){base.write(posbase); delay(10);}}
                } 
  if(data=='h'){rumah();}
  if(data=='m'){Serial.println("Data Informasi Posisi Servo Robot");
                Serial.print("Base   = " ); Serial.println(base.read());
                Serial.print("DOF1   = " ); Serial.println(dof1.read());
                Serial.print("DOF2   = " ); Serial.println(dof2.read());
                Serial.print("DOF3   = " ); Serial.println(dof3.read());
                Serial.print("DOF4   = " ); Serial.println(dof4.read());
                datadof5=dof5.read();
                Serial.print  ("GRIPER = " ); 
                if(datadof5==0){Serial.println("Lepas");} 
                if(datadof5==50){Serial.println("Capit");}
                }
 }
}

void rumah()
{
if(database>=30){for(posbase=database; posbase>=30; posbase-=1){base.write(posbase); delay(10);}}
if(database<=30){for(posbase=database; posbase<=30; posbase+=1){base.write(posbase); delay(10);}}
dof1.write(160); delay(50);
dof2.write(160); delay(50);
dof4.write(90);  delay(50);
dof3.write(90);  delay(50);
dof5.write(0);   delay(50);
}

void capit(){dof5.write(50);delay(10);}
void lepas(){dof5.write(0);delay(10);}

 
 

Program Dimensi

Python
import cv2
from object_detector import *
import numpy as np

# Load Aruco detector
parameters = cv2.aruco.DetectorParameters_create()
aruco_dict = cv2.aruco.Dictionary_get(cv2.aruco.DICT_5X5_50)


# Load Object Detector
detector = HomogeneousBgDetector()

# Load Cap
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while True:
    _, img = cap.read()

    # Get Aruco marker
    corners, _, _ = cv2.aruco.detectMarkers(img, aruco_dict, parameters=parameters)
    if corners:

        # Draw polygon around the marker
        int_corners = np.int0(corners)
        cv2.polylines(img, int_corners, True, (0, 255, 0), 5)

        # Aruco Perimeter
        aruco_perimeter = cv2.arcLength(corners[0], True)

        # Pixel to cm ratio
        pixel_cm_ratio = aruco_perimeter / 20

        contours = detector.detect_objects(img)

        # Draw objects boundaries
        for cnt in contours:
            # Get rect
            rect = cv2.minAreaRect(cnt)
            (x, y), (w, h), angle = rect

            # Get Width and Height of the Objects by applying the Ratio pixel to cm
            object_width = w / pixel_cm_ratio
            object_height = h / pixel_cm_ratio

            # Display rectangle
            box = cv2.boxPoints(rect)
            box = np.int0(box)

            cv2.circle(img, (int(x), int(y)), 5, (0, 0, 255), -1)
            cv2.polylines(img, [box], True, (255, 0, 0), 2)
            cv2.putText(img, "Width {} cm".format(round(object_width, 1)), (int(x - 100), int(y - 20)), cv2.FONT_HERSHEY_PLAIN, 2, (100, 200, 0), 2)
            cv2.putText(img, "Height {} cm".format(round(object_height, 1)), (int(x - 100), int(y + 15)), cv2.FONT_HERSHEY_PLAIN, 2, (100, 200, 0), 2)



    cv2.imshow("Image", img)
    key = cv2.waitKey(1)
    if key == 27:
        break

cap.release()
cv2.destroyAllWindows()

Credits

Hardi Kurnianto

Hardi Kurnianto

17 projects • 16 followers
Master student at Intelligent Control and Systems Engineering Department

Comments