Skip to content

About

Ultrasound sensor mounted on 2-degrees-of-freedom robotic arm for the sampling and 3D reconstruction of surrounding environment

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

AY2021_II_Project_1-1

This repository contains the code and files for the Final Project 1 - Variant 1. Academic Year 2020/2021, II Semester

Our project consists in developing a system able to perform a three-dimensional scanning of an object using two servomotors (MG996R) and one ultrasonic sensor (HCSR04). Our sonar must be opportunely moved to detect the distance surfaces in the field of view of the USS.

Software requirements

In order to let our device perform the functionality previously described, some software requirements must be fulfilled. Since our codes are written in PSoC and python, the following IDEs and softwares must be downloaded:
  • PSoC Creator
  • Kivy
  • Visual Studio Code
  • MATLAB 2017b version with Computer Visio Toolbox
  • Autodesk Fusion 360

Hardware requirements

In order to create our device different components have been used.

  • Two servomotors
  • Connection elements in order to link the two servomotors and create a serial chain able to scan the proximal environment
  • An ultrasonic sensor, the HCSR04
  • A cypress board
  • An homemade wooden box that acts as a housing for the board and guarantees robustness and stability to the serial chain
All these components must be properly handled as follow.

Board settings

The board is placed inside the wooden box with custom sliding plexiglass cover, and it is powered by the computer. The connection between the board and the computer can be performed using any COM the user wants, it will be recognized by our code.

Servomotors settings

The first servomotor must be connected to 2.6 PIN and it must have the crankshaft positioned vertically. The second servomotor must be connected at the 2.7 PIN and placed at the top of the first servomotor with the crankshaft positioned horizontally. Both of the servos need an external power supply in order to work properly.

Ultrasonic sensor settings

The HCSR04 must be linked to the crankshaft of the second servomotor through a special connection element in order to move solidly with this crankshaft. It works thanks to two connections, the Echo, the Trigger, that must be connected respectively to the 2.5 and 2.4 PINs. The cables are shielded with copper wires to prevent interference from the servo motor wiring and help reduce electronic noise.

Complete device arrangement

This repository contains the 'CAD' folder with the solidworks file of our configuration. It is possible to recreate the device following the image, as long as the user has all the components listed before.

Calibration procedure and angle-coordinates conversion

It is possible to see and understand the conversion from angles to three-dimensional coordinates in the image below. In the following chapter the computation, that allows the representation of the object put in front of our device, will be described.

X-Y-Z system

The Z-axis is the extension of the crankshaft of the first servomotor and it remains integral with it. This servomotor is placed in the exact middle of the X-axis so that the bottom of its crankshaft consists in the origin of the reference system. Y-axis is aligned with the direction of the long side of the first servo motor. REMEMBER: the second servomotor rotates jointly and solidally with the crankshaft of the first servomotor.

Angles description

GUI

The rotation of the crankshaft 1 allows to sweep the XY plane, its motion is described by the alpha angle. Alpha is the angle between the Y-axis and the plane perpendicular to XY, containing the point detected and aligned with the direction of the arm to which the sonar is linked.
The rotation of the crankshaft 2 allows to sweep the plane perpendicular to XY and aligned with the direction of the long side of the second servomotor and its motion is described by the beta angle. Beta is the angle between the straight line determined by the arm to which the sonar is attached and the plane on which the crankshaft of the second servo motor lies.
Functions getPosition() and setPosition(X°) allow to, respectively, return and set the angle (degrees) of one servo motor.

First servomotor:

  • 0 angle: lies on the positive portion of the X-axis
  • 90 angle: lies on the positive portion of the Y-axis
  • 180 angle: lies on the negative portion of the X-axis
In order to scan the width of the object put in front of the device, the first servomotor will sweep a 100° angle, starting from 40° up to 140°.

Second servomotor:

  • 0 angle: due to structural reason it consists in a 60° angle between the Z-axis and the straight line which is the extension of the arm to which the sonar is linked.
  • 90 angle: 0 angle + 90° = 150° (almost)
In order to scan the height of the object put in front of the device, the second servomotor will sweep a 60° angle, starting from 60° up to 120°.

According to the information reported:

SERVO_MID_ANGLE=90
ANGLE_ZERO=60
alpha = SERVO_MID_ANGLE-Servo_GetPosition1()
beta = Servo_GetPosition2()+ANGLE_ZERO-SERVO_MID_ANGLE

Coordinates computation

Knowing that :

  • D2 is the distance between the middle of the crankshaft of the second servomotor and the Z-axis
  • ARM_LENGTH is the length of the connection component that allows the rotation of the sonar solidally with the second crankshaft
  • pos_servo1_rad is alpha in rad
  • pos_servo2_rad is beta in rad
  • pos_servo2_z_rad is beta+ANGLE_ZERO° in rad
  • Z1 is the height of the crankshaft of the second servomotor
the coordinates computed using those two angles are:

X=(D2+(ARM_LENGTH+distance_real)*cos(pos_servo2_rad))*sin(pos_servo1_rad);
Y=(D2+(ARM_LENGTH+distance_real)*cos(pos_servo2_rad))*cos(pos_servo1_rad);
Z=Z1-(ARM_LENGTH+distance_real)*cos(pos_servo2_z_rad);

Configuration through GUI

GUI

GUI

Our GUI consists in six buttons:

  • Connect
  • Start
  • Stop
  • Step angle, with two possibilities
  • Display
and in a space filled with a GIF during the acquisition process.

UART communication settings

The user has the chance to connect automatically the GUI with the device through UART communication by pushing the button 'Connect'. If a board programmed with our code is connected to the computer, it will send back the string 'Device succesfully connected$' and our computer will understand which is the right COM to use.
After the 'Connect' button has been pressed, it changes name to 'Disconnect'. If 'Disconnect' button is pressed all the peripherals are turned off.
It will be possible to see at the bottom of the GUI the connection status

Step angle settings

The user can also configure the Step angle of the servomotors through our GUI. This operation allows the user to obtain a more defined image by increasing the steps of the servomotors and so the number of points that describe the surface.

Start and Stop commands

The user has to press the 'Start' button in order to start the three-dimensional scanning and the 'Stop' button can be pressed anytime the user wants. After the 'Stop' button has been pressed our device will come back at the 'zero configuration', ready to begin a new scanning process.

Stop functionality

If our device will not find any point during an entire sweep of the XY plane it will automatically reset to the zero configuration (no object has been found or object scanning ended).

Display command

This button will be disabled until the end of the acquisition. Once the acquisition is done the 'display' button will be activated. The user will be able then to push it and display the reconstructed image.
The reconstructed image consists in a point cloud that appears inside a pop-up.
The user has also the chance to change the perspective of the object using the mouse. Additional functionality: by pushing the 'p' key a screenshot will be performed and saved in the repository.

Operating instructions

Distance suggestion

Due to its dimensions and due to specific hardware limits, this device is able to understand the shape and concavity of an object with small dimensions. The object, moreover, MUST be placed at a distance between approximately 7 and 50 cm in order to have a higher quality reconstruction, otherwise the device will not be able to detect properly the object's surface. Recommended distance is in the 10 - 25 cm range.

Positioning suggestion

Sweep on the XY plane is performed with a 100° angle; more specifically, the first servo motor goes from 40° to 140°, so alpha will go from 50° to -50°. The object should be put at the centre of this range in order to let the device scan the entire shape.

Limits considerations

Please be advised that, by nature, the sonar will return correct distances only for points on planes parallel or almost parallel to it. Our device, instead, works by rotating around two pins, and it does not use sliding tracks. For this reason, distances detected at the limits of our 100° range could be affected by bias. In order to manage this conditions we decided to narrow the sweeping range to 100° and to suggest the user to scan small dimension objects. By doing this we let the sonar to work in its optimal conditions.

Repository organization

Inside this repository you will find the following files and folders:
  • FinalProject_1-1.cydsn: folder containing PSOC Creator files
  • GUI:
    • GUI.kv: graphic implementation of GUI
    • Project_1_1.py: python file containing GUI commands and image reconstruction
    • interpolation_plane.m: MATLAB script with one section to reconstruct point cloud representation with axes (needs Computer Vision Toolbox) and another section that interpolates a plane in the point cloud representation (usefull to understand the quality of the reconstruction for planar objects)
    • requirements.txt: required python libraries and dependencies
  • coordinates: folder that contains acquisition results of relevant objects such as planes and bottles

About

Ultrasound sensor mounted on 2-degrees-of-freedom robotic arm for the sampling and 3D reconstruction of surrounding environment

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages