Gr01rapport2021 02

Download as pdf or txt
Download as pdf or txt
You are on page 1of 74

DEGREE PROJECT IN TECHNOLOGY,

FIRST CYCLE, 15 CREDITS


STOCKHOLM, SWEDEN 2021

Kinetic Art Table


Polar sand plotter

SERHAT TÜRK

KRISTOFFER MÜLLER

KTH ROYAL INSTITUTE OF TECHNOLOGY


SCHOOL OF INDUSTRIAL ENGINEERING AND MANAGEMENT
Kinetic Art Table

Polar sand plotter

SERHAT TÜRK, SERHATT@KTH.SE


KRISTOFFER MÜLLER, KMUL@KTH.SE

Bachelor’s Thesis at KTH


Supervisor: Nihad Subasic
Examiner: Nihad Subasic

TRITA-ITM-EX 2021:19
Abstract
CNC machines are used with plenty of different implemen-
tations, one of which is in this project where a polar CNC
machine was used to draw mesmerizing patterns on a table
with fine sand. This construction read G-code and con-
verted it to polar coordinates. The capabilities of what the
plotter could draw were tested, everything from ODE plots
to custom-made patterns and drawings with the help of
Sandify. Although the patterns were drawn properly with
small errors the ODE was too difficult to draw because it
required a smaller magnetic ball and an even more precise
system than what was used. This machine also generated
noise at roughly 33 dB when it was in use.

Keywords: Mechatronics, Stepper-motor, Arduino, Polar


plotter, forward Euler method.
Referat

CNC-maskiner används med massor av olika implementa-


tioner, en av dem är i det här projektet där en polar CNC-
maskin användes för att rita fascinerande mönster på ett
bord fylld med fin sand. Denna konstruktion läste in G-kod
och konverterade det till polära koordinater. Förmågan av
vad maskinen kunde rita testades, allt från ODE grafer till
specialtillverkade mönster och ritningar med hjälp av San-
dify. Även om de olika mönstren ritades ordentligt men med
mindre små fel var ODE för svårt att rita på grund av att
det krävde en mindre magnetisk kula och ännu mer nog-
grannhet jämfört med detta system. Denna maskin alstrade
också ljud på cirka 33 dB under användning.

Nyckelord: Mekatronik, Steg-motor, Arduino, Polär plot-


ter, Eulers stegmetod.
Acknowledgements

We would like to thank our examiner Nihad Subasic for increasing our understanding
of the field of mechatronics and giving us a proper base of knowledge to proceed
with this construction. Thank you goes out to the assistants Amir Avdic and Malin
Lundvall for giving us advice in great times of need and guide us to the right path.
We would also like to thank our fellow students Kristian Jandric, Algot Lindestam,
and Viktor Kårefjärd that helped us with some of the programming parts of the
project. A big thanks to Staffan Qvarnström for helping us with the purchases of
parts and different electronics. This project would not have been possible without
these humbling people.
Contents

1 Introduction 1
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Theory 3
2.1 Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Different moving mechanisms . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Shields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.5 Ordinary Differential equations . . . . . . . . . . . . . . . . . . . . . 5
2.5.1 Forward Euler Method . . . . . . . . . . . . . . . . . . . . . . 6

3 Demonstration 7
3.1 Problem formulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Electronics and components . . . . . . . . . . . . . . . . . . . . . . . 7
3.2.1 Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2.2 Stepper motors . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3.1 System control . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3.2 G-code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3.3 Generate coordinates . . . . . . . . . . . . . . . . . . . . . . . 10
3.3.4 Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3.5 Solving the ODE . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.4 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.4.1 Computer-aided design . . . . . . . . . . . . . . . . . . . . . 12
3.4.2 Rotating part . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4.3 Linear part . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.4.4 Linear and rotation . . . . . . . . . . . . . . . . . . . . . . . 15
3.4.5 Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

4 Application testing and results 19


4.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 Ratio between linear and rotating part . . . . . . . . . . . . . . . . . 19
4.3 Noise comparison of the sand . . . . . . . . . . . . . . . . . . . . . . 20
4.4 Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

5 Discussion and conclusion 23

Bibliography 25

6 Appendix A 29

7 Appendix B 33

8 Appendix C 54
8.1 Stepper motor datasheet . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.2 l293d motor shield datasheet . . . . . . . . . . . . . . . . . . . . . . 55
List of Figures

2.1 The principle of a stepper motor.[17] . . . . . . . . . . . . . . . . . . . . 4


2.2 Arduino Uno, Imagen take by Kristoffer Müller . . . . . . . . . . . . . . 5

3.1 Connection diagram and overview of the electronics made in the program
Fritzing. [16] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2 This is a pattern generated with the Sandify program. [12] . . . . . . . 10
3.3 Flowchart made with app.diagrams.net.[19] . . . . . . . . . . . . . . . . 11
3.4 Finished CAD assembly in Solid Edge. [1] . . . . . . . . . . . . . . . . . 13
3.5 Rotating part in Solid Edge. [1] . . . . . . . . . . . . . . . . . . . . . . . 14
3.6 Linear part in Solid Edge. [1] . . . . . . . . . . . . . . . . . . . . . . . . 15
3.7 ρ and θ. Image taken by Serhat Türk. . . . . . . . . . . . . . . . . . . . 16
3.8 Final table. Image taken by Serhat Türk. . . . . . . . . . . . . . . . . . 17

4.1 Spiral in Sandify.[12] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21


4.2 Spiral drawing on table. Image taken by Serhat Türk. . . . . . . . . . . 21
4.3 Spiral into a star in Sandify.[12] . . . . . . . . . . . . . . . . . . . . . . . 21
4.4 Expanding star drawn after a spiral. Image taken by Serhat Türk. . . . 21
4.5 Square drawn in Sandify. [12] . . . . . . . . . . . . . . . . . . . . . . . . 22
4.6 Square drawing test in sand. Image taken by Serhat Türk. . . . . . . . . 22
4.7 The ODE plot in the sand. Image taken by Serhat Türk. . . . . . . . . 22
4.8 The ODE displayed in Matlab. [13] . . . . . . . . . . . . . . . . . . . . . 22

6.1 Mechanical parts side view. Image taken by Serhat Türk. . . . . . . . . 29


6.2 Mechanical parts over view. Image taken by Serhat Türk. . . . . . . . . 30
6.3 Table side view. Image taken by Serhat Türk. . . . . . . . . . . . . . . . 30
6.4 Table over view. Image taken by Serhat Türk. . . . . . . . . . . . . . . 31
6.5 Finished construction. Image taken by Serhat Türk. . . . . . . . . . . . 31
List of Abbreviations

• CNC - Computer Numerical Control

• DC - Direct current

• SEK - Swedish Kronor

• IDE - Integrated Development Environment

• PMW - Pulse-Width Modulation

• USB - Universal Serial Bus

• 3D - Three-dimensional space

• 2D - Two-dimensional space

• ODE - Ordinary Differential Equation

• CAD - Computer-aided design

• SKF - Svenska Kullagerfabriken

• mm - Millimeters

• min- Minimum

• max - Maximum

• dB - Decibel
List of Tables

4.1 Noise measured with Sound Meter. [23] . . . . . . . . . . . . . . . . . . 20


Chapter 1

Introduction

1.1 Background
Being able to create mesmerizing patterns has always been a huge part of human
creativity throughout centuries. Having a machine that expresses those patterns
while people are taking a coffee break would be soothing. Not only would it be
entertaining but also a fascinating way to recreate differential equations on a layer
of sand.
This thesis will improve the understanding of how to use coding and comput-
ing to replicate and calculate digital movement in a real-life machine. This type
of technology is called CNC, also known as Computer Numerical Control. CNC
essentially uses two or three-dimensional movements to complete certain tasks.
Usually, CNC technology is utilized to complete different tasks such as control
of workshop machines, 3D printers, or in the medical field where a tool like this can
be used with precise movements for surgery. However, this technology could also
be used to create something which is the opposite of that. In this case, it will be
used to move a magnetic ball in very fine sand that prevents jagged drawings and
disturbing noise.

1.2 Purpose
The purpose of this project was to build and program a table that draws patterns
in fine sand using a magnetic ball, motors, and 3D-printed parts for the arms. The
following thesis and questions will be answered:

• How to design and build an arm allowing movement in two dimensions

• How to create a program which allows user input and to print patterns in
sand?

• Is it possible with the program to plot approximations of Ordinary differential


equations into the sand?

1
CHAPTER 1. INTRODUCTION

• How to reduce the sound for different parts of the machine?

1.3 Scope
This thesis will be limited so that it becomes possible to complete the project with
the given time and resources. The budget was limited to 1000 SEK and because of
the corona virus pandemic, some places in the university were limited. The main
goal was to construct a functioning art table, therefore the sound analysis was not
prioritized. Another limiting factor was the storage of the Arduino. With regards
to that, the focus of plotting differential equations will be on Ordinary Differential
Equations (ODE).

1.4 Method
To create this table system multiple tools were utilized. At first, to create a proto-
type and then later on the finished product, a program called Solid Edge was used.
Solid Edge is a Computer-Aided Designing program that makes 3D models digitally.
[1] With the use of that program, it was possible to later on 3D print some parts
of the project and the other parts were ordered online from Electrokits website [2]
such as stepper motors and a bearing. Those parts together with an Arduino UNO,
L293D motor shield as well as software and code from a computer to control the
motors led to this project construction.

2
Chapter 2

Theory

2.1 Motor

For this build, the system will revolve around motors to achieve movement in two
dimensions. There are different types of motors that can be used in projects. Di-
rect current (DC) motors are one of them. The DC motor has a wide variety of
applications. The way they work is by simply applying voltage for the motor to
start spinning. If the direction of the current changes, so will the rotation of the
motor. The basic principle of DC motors is simply using electricity and magnetism
to make the motor rotate, usually with electromagnets and normal magnets. With
that comes different types of motors. One of them is the servo motor. [6]
Servomotors are often seen in robotic arms and it is most likely because of their
compact form factor and using their feedback to control their movement. The closed
feedback system makes it easy to control exactly how much the motor is supposed
to rotate and keeping it constant is not difficult. The feedback system often consists
of a sensor that keeps track of the rotor. [9]
Another motor is a stepper motor. A stepper motor is essentially a brush-
less DC motor that can move with precision which was necessary for this build.
It achieves accurate movement because the motors are constructed with multiple
toothed electromagnets that surround a gear in the center as seen in figure 2.1. The
electromagnets are then utilized by multiple micro-controllers or driver circuits to
drive the iron gear. It is done by powering on and off these electromagnets sur-
rounding the gear which is dependant on the alignment of the cogs on the gear.
When the cogs are aligned with one of the electromagnets, the next one will be
slightly offset. Once that is the case, the aligned one will turn off and automatically
power on the offset electromagnet, which in turn makes the gear spin.
The position and exact movement of the motor is accurate which is essential to
always know when and where the magnet will be on the table. [7]
The stepper motor also has its benefits with high torque at low speed but this
requires higher current. Another asset of the motor is that by changing the direction
of the current, the motor can then be used to move forward and backward.

3
CHAPTER 2. THEORY

Figure 2.1: The principle of a stepper motor.[17]

2.2 Different moving mechanisms


There are different ways to systematically move a ball in a limited orientation. The
balls are going to move in a two-dimensional plane.
The first possible build was to use normal Cartesian coordinates the same way
a 3D printer works except it is in 2D. It uses a square-based system to move the
ball using x and y coordinates. Although this should be easy to build and program
it takes up space.
The second system is more challenging which is polar coordinates. This makes
use of an angle and a distance from the origin to calculate the position of the ball
and where it is going to move, which makes this a better choice since a lot of patterns
that are drawn will have circular characteristics. The space of the table might also
be smaller compared to the Cartesian system.

2.3 Arduino
The open-source electronics platform Arduino offers simple and easy-to-use hard-
ware and software such as boards and Integrated Development Environment (IDE)
software. It offers all kinds of micro-controllers for different usages and comes in
different sizes making it a useful controller for various projects: from small school
projects to more advanced projects.[3] Arduino boards are able to read input signals
and transmit output signals to various objects such as motors or sensors. The IDE
software used to program the Arduino is based on C and open source. The Arduino
boards are based on the ATMega microcontroller. All of this makes the Arduino a
good controller for this Bachelor’s thesis. [4]
One of the most popular Arduino boards is the Arduino UNO as seen in figure
2.2, which was used in this project. It was powered by an ATmega328 processor

4
2.4. SHIELDS

which operates at 16MHz. It includes 14 digital Input/Output pins, 6 analog pins,


and supports 5V and 3.3V of power.[8] The 6 analog pins 3, 5, 6, 9, 10, 11 can be
used as Pulse Width Modulation, or PWM, outputs.

Figure 2.2: Arduino Uno, Imagen take by Kristoffer Müller

The Arduino board consists of two parts. The first part is the hardware. The
Arduino Uno consist of many different components such as the Digital Pins, USB
connector, Reset Switch, Power Port, and a micro-controller which all together
make it function. The second part is the software which consists of the Integrated
development environment which translates the code the user writes to the language
the Arduino reads.

2.4 Shields
An Arduino Shield is a modular circuit, often simplifying a specific task or giving
the Arduino extra functions, for example, an Ethernet Shield, that is piggybacked
onto the Arduino. An Arduino L293D Motor Driver Shield allows the Arduino to
operate DC motors, stepper motors and different kinds of relays. It supports up to
4 DC motors or 2 Stepper and 2 servo motors.[24] It also features an extra power
port enabling to connect motors having voltages between 4.5 to 25V.[6] [27]

2.5 Ordinary Differential equations


This build should theoretically be able to plot graphs or other equations in the sand
other than just patterns. Another feature is that it could potentially use different
methods to approximate the solution to an ODE and then draw it in the sand.
Normally when a function is drawn in a calculator or other tools it is easy to draw

5
CHAPTER 2. THEORY

a function that is simple or even more complex. For instance to draw y = x2 is not
very difficult. However, to go even further and seeing if drawing ODE in the sand is
possible would test the upper limits of the construction. There are different ways to
plot differential equations, one is to actually solve it mathematically to get a proper
plot or graph. The other option is to approximate the values of the solution using
the unsolved equation instead as a baseline together with iterative calculations.

2.5.1 Forward Euler Method


The method used to approximate any ODE is called the forward Euler method.
The requirement to use this method is to have a starting position of the ODE as
well as the ODE itself. With the Euler formula

yn+1 = yn + hf (tn , yn ) (2.1)


It is possible to iterate multiple points for each ODE. The formula utilizes the
derivative of the function in the ODE to take steps. Meaning that it takes one
point, tries to predict where the next point is supposed to be using a tangent on
that point. From the tangent, it moves with a small step h in the tangent direction.
Where the h is how big of a step the iteration is taking between each calculated
point. h decides how sharp and accurate each calculated point will be compared
to the exact solution. Once the new point is found in the tangent, a new tangent
is calculated and the procedure continues until the boundary limits are met. The
f (tn , yn ) is essentially set to what the equation is equal to, usually the derivative
in the equation, one example is y 0 for y 0 = y. The tn defines the interval of the
equation which is usually on the x-axis. Finally, the yn are the answers to each
solution that is used as input, the yn+1 is then set back to yn so the iteration can
continue until the end of tn .[18]

6
Chapter 3

Demonstration

3.1 Problem formulation


During the project there were some problems and obstacles that had to be cleared:
• Convert a pattern or an ODE into polar coordinates and draw these coordi-
nates in sand using motors and gears.
• Design proper mechanical parts for the construction.
• Write code to calibrate the system.

3.2 Electronics and components


Some components were purchased and the rest was 3D printed. For this design of
the project it was necessary to have:

• two stepper motors


• an Arduino UNO
• a belt drive kit
• different 3D printed parts
• two linear bearings
• axial bearings
• Arduino L293D Motor Driver Shield

3.2.1 Microcontroller
To control the kinetic table an Arduino UNO with an Arduino L293D Motor Driver
Shield was used. The Driver Shield was piggybacked onto the Arduino UNO. Both
stepper motors were connected to the Driver Shield.

7
CHAPTER 3. DEMONSTRATION

3.2.2 Stepper motors


The polar CNC table was driven by two of the same stepper motors. One that
moved the arm and the other one that was driving the angle of the arm itself. Both
of them were bipolar stepper motors with a step-angle of 0.9° and sustainability of
0.41 Nm from the website electrokit. [11] How everything was set up can be seen
in figure 3.1.

Figure 3.1: Connection diagram and overview of the electronics made in the program
Fritzing. [16]

8
3.3. SOFTWARE

3.3 Software
3.3.1 System control
The code that was written in the Arduino can be seen under Appendix B. This code
manages and controls how the motors were supposed to operate and move together
to draw properly in the sand. The coordinates were downloaded and used as input
for the Arduino. The prerequisite settings for the stepper motors were to calculate
how long one step from the motors were, as well as the area on which the machine
could draw on. The motors always made the metal ball move in straight lines from
point to point mapped out by G-code which will be explained under section 3.3.2.
Each point was usually close to one another and makes the straight-line hard to
see. From there the code calculates an angle and the distance from the origin to
understand where the magnet ball was supposed to position itself. The lines and
coordinates, however, had to be drawn continuously without any jumps because the
magnet arm could not move in the Z- directions.[27] So the coordinates need to stay
consistently close to each other. The base of the codes for the project was found
online but had to be modified and changed to work with this construction. [15]

3.3.2 G-code
G-code is basically the programming language generally used in 3D printers or
other machines similar to CNC machines, where each row in the code represents
the actions together with a position and speed. An example of one block written in
G-code looks something like this: G01 X240 Y250. The G01 tells the machine to
move in a straight line, and the X240 and Y250 translate to coordinates of a point
where that straight line is supposed to move towards.[26] The numbers are usually
in mm.[5] There are plenty of different functions in G-code but these are the only
ones necessary for the machine to work. Since the code is used by 3D printers it
also takes care of the z-axis. This was not considered in the project because the
magnetic ball for this build could not move in that direction. The speed did not
need to be modified either which is why it stayed constant when it performed.[14]
Although the system was built with polar characteristics, the inputs for the
Arduino were in G-Code which is read in Cartesian X and Y coordinates. The
Arduino had to recalculate the coordinates from the G-code and describe them
with a ρ distance from the origin and a θ angle from the X-axis.[25]

9
CHAPTER 3. DEMONSTRATION

3.3.3 Generate coordinates


To generate coordinates, the program Sandify [12] was used. The interface can be
seen in figure 3.2. It allowed the creation of different patterns and output different
points in terms of G-code. There were different basic patterns like a star shape, cir-
cle, and polygon which could be customized and added into more complex patterns.
Other components could also be customized such as:

• Size of the pattern can also be scaled with a mathematical function

• Offset in X and Y-axis

• Rotation of the pattern

• The spin of the shape can also be scaled with a mathematical function

• The green dot indicates the starting point and the red dot is the end point

Figure 3.2: This is a pattern generated with the Sandify program. [12]

The way the entire process works from the Arduino reading G-code to the metal
ball being moved was easily explained with a flowchart in figure 3.3.

10
3.3. SOFTWARE

Figure 3.3: Flowchart made with app.diagrams.net.[19]

3.3.4 Storage
To store these patterns and send them over to the Arduino required a memory
card. Since all the Arduino input pins where occupied its was not possible to
install a memory card. The solution was to save all the files from the website
Sandify to a computer and to send it to the Arduino through a code called GCTRL
written in Processing 3.[20] Processing 3 is a software-based of Java code with added
functionalities to make it easier to create mechanical art. What GCTRL essentially
did was to read text files and sends the information over to the Arduino where the
rest of the interpreting was done.[15]

3.3.5 Solving the ODE


For the ODE solution at first, the Arduino was used to solve the differential equa-
tions. Due to the limited storage on the board, another solution was required. Mat-
lab is capable of creating and editing text files with the command fprintf. This
made it possible to solve the ODEs in Matlab and then export the points given

11
CHAPTER 3. DEMONSTRATION

by the Euler method in G-code format. From there GCTRL was used to upload
the G-code similarly to the patterns download from Sandify. Allowing the usage of
Matlab which can solve more complex differential equations than first anticipated
when starting with the project.

3.4 Hardware

3.4.1 Computer-aided design

To be able to create the mechanism for the table, a 3D model was created with
the CAD program Solid Edge.[1] All of the created parts were based on the stepper
motors dimension. The larger pulley and the axial bearings had both premade CAD
files which were imported into the project. The remaining parts were all created
to fit with the pre-existing parts. The finished project consisted of two main parts,
the rotating part which was responsible for the rotation in theta direction, and the
linear part which was responsible for the radius in the ρ direction. This can be seen
in figure 3.4.

12
3.4. HARDWARE

Figure 3.4: Finished CAD assembly in Solid Edge. [1]

3.4.2 Rotating part


The rotation was made using a stepper motor connected with a belt drive which
can be seen in figure 3.5. The whole belt drive system was bought. [10] Given the
smaller pulley having 10 numbers of teeth and the larger pulley, 60, the gear ratio
can be calculated using equation 3.1.

# teeth large pulley 60


Gear ratio = = =6 (3.1)
# teeth small pulley 10

The larger pulley was mounted on top of the second stepper motor. To be able
to rotate the pulley independently from the stepper motor it was mounted on an
axial bearing which was mounted between the pulley and the stepper motor.
The axial bearing was a 51104 from SKF and both stepper motors were a 42BYGHM809
from JiangSu WanTai Motor Co., Ltd. Stepper motor datasheet seen under ap-
pendix C 8.1.

13
CHAPTER 3. DEMONSTRATION

Figure 3.5: Rotating part in Solid Edge. [1]

3.4.3 Linear part


The linear movement was created using a pinion mounted to the stepper motor axis.
The rack was fixated onto the magnet carrier seen in figure 3.6. The magnet carrier
was mounted on two linear bearings which were on two axes only allowing linear
movement. The rack and pinion, magnet carrier, and the mounts for the axis were
all 3D printed. The linear bearing and axis were bought. [10] The construction
for this project was designed in a way that when the rotating part was moved the
linear part would also move along. To determine the ratio between the linear and
rotating part a few tests were conducted, see section 4.2.

14
3.4. HARDWARE

Figure 3.6: Linear part in Solid Edge. [1]

3.4.4 Linear and rotation


For both the linear and rotational systems to work simultaneously, they had to be
built so that the cables did not tangle and move at all. This is why the system is
built around the motors. For the ρ and θ movement, an example can be seen in
figure 3.7.

15
CHAPTER 3. DEMONSTRATION

Figure 3.7: ρ and θ. Image taken by Serhat Türk.

3.4.5 Table
To be able to draw patterns in the sand a table was designed to hold the sand and
have the right diameter to support the arm. The table was made out of wood. The
main parts for the table are the body which holds the sand and the legs, see figure
3.8.
The sand which was used was at first normal aquarium sand[21], due to it being
too rough it was creating too much noise. The size of the grains was roughly between
0,4 mm - 1,4 mm. The second sand which was used was chinchilla sand[22] which
was more silent compared to the aquarium sand. A comparison was conducted, see
section 4.3.

16
3.4. HARDWARE

Figure 3.8: Final table. Image taken by Serhat Türk.

17
Chapter 4

Application testing and results

4.1 Hardware
The first problem that came up when the build was completed was that the linear
and rotating part was too heavy to be balanced on their own. The easiest solution
was to attach a wheel and a LEGO structure to the construction to support the
weight. This helped the construction to maintain the balance even when the weight
of the magnet carrier was shifted throughout the process of creating patterns.

4.2 Ratio between linear and rotating part


The ratio between the linear moving part and the rotating part was estimated
with a simple test. The rotating part was set to move 100 steps around the own
axis, by then measuring how many rotations the linear part would make a ratio
of approximately 6:1 was estimated. That ratio was implemented into the code so
that when the rotating part would take 6 steps the linear part compensates with
one extra step so that the arm does not move forward or backwards while it rotates.

19
CHAPTER 4. APPLICATION TESTING AND RESULTS

4.3 Noise comparison of the sand


Due to the difference in the size of the sand grains the noise produced by rolling a
metal ball over it is different. The noise was measured using an app for the phone
[23] and the values for the three different tests can be seen in table 4.1. These values
were measured one meter above the table.

Sand type Aquarium sand Chinchilla sand


Size of the grain 0,4 mm - 1,4 mm 0,1 mm - 0,3 mm
Test 1 Min: 32 dB 22 dB
Max: 61 dB 50 dB
Average: 49 dB 33 dB
Test 2 Min: 30 dB 22 dB
Max: 60 dB 47 dB
Average: 47 dB 34 dB
Test 3 Min: 32 dB 23 dB
Max: 55 dB 48 dB
Average: 46 dB 32 dB

Table 4.1: Noise measured with Sound Meter. [23]

From table 4.1 the chinchilla sand was more silent than the aquarium sand. Not
only did the finer chinchilla sand provide a more silent drawing, but it also gave a
smoother path.

20
4.4. PATTERNS

4.4 Patterns
The table is supposed to make different patterns in the sand. To test the accuracy
and how well the mechanism works some simple and little more complex ones were
tested.
The first one was a spiral that started in the middle and was drawn outwards
eight spins. As seen in figure 4.2 and the corresponding drawing in Sandify in figure
4.1.

Figure 4.2: Spiral drawing on table. Im-


Figure 4.1: Spiral in Sandify.[12] age taken by Serhat Türk.

This was well drawn with some minor vibration patterns in the path of the ball
as well as slightly worse resolution at the end spin.
The second test was to draw the same spiral but with an expanding star on top
afterward to test if drawing a second pattern right after the first one is possible as
seen in figure 4.4 and figure 4.3.

Figure 4.3: Spiral into a star in Figure 4.4: Expanding star drawn after a
Sandify.[12] spiral. Image taken by Serhat Türk.

21
CHAPTER 4. APPLICATION TESTING AND RESULTS

Although the patterns were drawn properly, the drawing kept getting stuck on
the Arduino cable and therefore the drawing was not exactly as anticipated.
Since the coordinates were converted from cartesian to polar. A test to draw a
default square was done as seen in figure 4.6 and from Sandify in figure 4.5.

Figure 4.5: Square drawn in San- Figure 4.6: Square drawing test in sand.
dify. [12] Image taken by Serhat Türk.

The ordinary differential equation that was tested was

x3 x2
y0 = + + 2x − 8. (4.1)
10 2
To use the Euler method in Matlab the initial value was y(1) = 0 with the increments
of h = 51 .
The resulting drawing in the sand is seen in figure 4.7. The ball rotated around
the center of the table before the straight line was drawn. For comparison, figure
4.8 was the plot made in Matlab using the Euler method approximation.

Figure 4.7: The ODE plot in


the sand. Image taken by Serhat Figure 4.8: The ODE displayed
Türk. in Matlab. [13]

22
Chapter 5

Discussion and conclusion

The goal for this project was to see if it was possible to draw patterns and differential
equations. This was achieved using two stepper motors and several 3D printed and
bought parts.
For the construction, there were multiple flaws. The first problem was with
the linear motor, axial bearing, and larger pulley arrangement. The 3D printed
carrier for the axial bearing was slightly skew which gave a slight shift in the weight
distribution.
Another flaw in the construction was that the weight of the metal axes was
underestimated. To solve this problem a quick and easy solution was provided in
form of adding a LEGO structure with some wheels to counteract the weight of the
axis. Another problem that occurred was that the wheels rolled over the USB cable
connection to the Arduino. That resulted in a wobbling construction and sometimes
the arm got stuck on the cable.
Other flaws were mainly related to the 3D printers not having sufficient precision
and reoccurring technical difficulties. Which resulted in some parts sightly faulty
constructed.
For the code part of the project drawings that lines crossing the y-axis, x-axis,
or other straight lines could not be drawn from Sandify. Since the Arduino had
to convert points from G-code to polar coordinates that automatically came with
some conversion problems. For instance, to draw a square in the middle of the table.
When the square is drawn in Sandify, the drawing only requires coordinates in each
corner to be drawn. However, when later converted to polar coordinates on the
Arduino, the conversion did not take care of the ρ difference between each corner.
This was because the ρ was the same distance from the origin to each corner of the
square. Meaning that drawing a square would result in a circle. What the drawing
needed was one extra coordinate in between each corner so that the ρ difference was
accounted for. This could have been solved by either inputting extra coordinates
manually in between each point or use some form of interpolation.
Some complex patterns could not be drawn properly simply because of the
extensive coordinate changes. Having 180 ◦ difference between each coordinate

23
CHAPTER 5. DISCUSSION AND CONCLUSION

gave some difficulty converting that to proper linear movement since the entire
build had to rotate 180 ° after the arm was back to the origin and from there move
the ball in a straight line again. Instead, the arm moved to the new distance and
afterward was rotated to the right position. Although the coordinates were correct,
the execution had some room for improvement. This was a computational flaw in
the code.
The ODE plots that were tested in this project were difficult to plot properly in
the sand. The reason why was because of the G-code that was created in Matlab,
the values had a very small difference in the beginning as seen in figure 4.8. Later
on, the values increased tremendously with each new step that was taken. The small
changes were not possible to draw because the machine itself could not draw that
small of a change in the values. The magnetic ball was also too big to show tiny
movement, so for this to work a smaller ball is needed. When the ODE increased
significantly, the drawing attempted to draw a line because the value did not change
that much.
In conclusion, this was a successful project with regard to the drawing capa-
bilities. The art table can draw different patterns as well as anything made with
G-code. Although the table can draw almost anything, there are some errors such
as the construction of the arm that could not work properly with regards to the
rotation. The ODE drawings essentially needed better resolution and more precise
movement than what was constructed during the build.
As for the sound levels, it depends on the environment. It was possible to ignore
the sound levels if focused on other tasks but for daily use as a table, this might
have been inconvenient.
A number of improvements for the future could be to modify the code so that
the machine can draw squares, straight lines, and better precision. With regards
to the construction, these could also improve by modifying the weight distribution,
correct the errors and improve the faulty 3D printed parts.

24
Bibliography

[1] Siemens PLM Software, 2013, Solid Edge. accessed 2021-02-10.


https://solidedge.siemens.com/en/
[2] Electrokit.com. accessed 2021-02-10.
https://www.electrokit.com

[3] Zoe Romano, 2013, Using Arduino on industrial digital printing machines, accessed
2021-02-10. https://blog.arduino.cc/2013/07/04/using-arduino-on-industrial-
digital-printing-machines/

[4] ARDUINO, 2021, Arduino, accessed 2021-02-06.


https://www.arduino.cc/

[5] A. C. Brown and D. de Beer, ”Development of a stereolithography (STL) slicing


and G-code generation algorithm for an entry level 3-D printer,” 2013 Africon,
2014. How G-code works and it is generated., accessed 2021-02-06.
https://ieeexplore.ieee.org/abstract/document/6757836?
casa_token=13WVGxZJEVUAAAAA:U7juTojtluahDY2AcNvhslJQeNCEaOTBSLDsXwSqbKsw3k
5UusRO17vZLQyKHQ8oEWevxfn3tw

[6] Arduino L293D Motor Driver Shield Tutorial, accessed 2021-02-06.


https://create.arduino.cc/projecthub/electropeak/arduino-l293d-motor-
driver-shield-tutorial-c1ac9b

[7] What is a Stepper Motor : Types Its Working, accessed 2021-02-15.


https://www.elprocus.com/stepper-motor-types-advantages-applications/

[8] Robin Mitchell, 2018, Use this comparison of the UNO, Nano, Mega, and Due Arduino
boards to help you choose the best board for your projects., accessed
2021-02-10. https://maker.pro/arduino/tutorial/a-comparison-of-popular-
arduino-boards

[9] Dejan, How Servo Motor Works How To Control Servos using Arduino, accessed
2021-02-15. https://howtomechatronics.com/how-it-works/how-servo-motors-
work-how-to-control-servos-using-arduino/

25
BIBLIOGRAPHY

[10] Rotating parts were bought from Electrokit.com. accessed 2021-02-10.


https://www.electrokit.com/produkt/kuggremskiva-xl-60t-1-3-80/

[11] Motors were bought from Electrokit.com. accessed 2021-02-10.


https://www.electrokit.com/produkt/stegmotor-400-steg-varv-bipolar/

[12] The patterns were generated with Sandify program, accessed 2021-04-01.
https://sandify.org/

[13] MathWorks Matlab, 2021, Matlab. accessed 2021-02-10.


https://se.mathworks.com/products/matlab.html

[14] An Introduction to G-Code and CNC Programming, accessed 2021-03-25.


https://www.thomasnet.com/articles/custom-manufacturing-fabricating/
introduction-gcode/

[15] Sandeep, 2019, How to make Arduino mini CNC plotter machine, accessed
2021-03-28. https://electricdiylab.com/how-to-make-arduino-mini-cnc-plotter-
machine/

[16] Connection Diagram was generated with Fritzing program, accessed 2021-04-04.
https://fritzing.org/

[17] Stepper Motor, accessed 2021-04-06.


https://www.electronicwings.com/sensors-modules/stepper-motor

[18] University of Cambridge, 2003, A First Course in the Numerical Analysis of


Diferential Equations, page 4-6, accessed 2021-04-06.
https://bit.ly/31S7R97

[19] Flowchart designer, accessed 2021-04-09.


https://app.diagrams.net/

[20] Processing 3 program, accessed 2021-03-15.


https://processing.org/

[21] Aquarium sand from hornbach.se, accessed 2021-04-15.


https://www.hornbach.se/shop/Akvariesand-5kg-vit/4066916/artikel-detaljer.html

[22] Chinchilla sand from zoo.se, accessed 2021-04-15.


https://www.zoo.se/vitapol-chinchilla-sand-badsand.html

[23] Sound Meter app, downloaded 2021-05-05. App used to measure the sound levels
https://play.google.com/store/apps/details?id=com.gamebasic.decibelhl=svgl=US

[24] Kalhapure Vrushali Arun, 2015, Implementation of Carving Machine Con-


troller Based on L293D, accessed 2021-02-10.
https://www.ijaent.org/wp-content/uploads/papers/v2i3/C0263022315.pdf

26
BIBLIOGRAPHY

[25] D. L. Zhang, X. S. Chen, R. Du, 2013, A CNC program module based on polar
coordinate system, accessed 2021-02-10.
https://link.springer.com/article/10.1007/s00170-013-4974-1

[26] Kaushik Kumar, Chikesh Ranjan, J. Paulo Davim, 2020, Polar Coordinates,
accessed 2021-02-11.
https://www.ijaent.org/wp-content/uploads/papers/v2i3/C0263022315.pdf

[27] Wisnu Wijaya et al. 2020, Two Axis Simple CNC Machines Based on Micro-
controller and Motor Driver Shield IC L293D, accessed 2021-02-11.
https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=arnumber=9310882

27
Chapter 6

Appendix A

Figure 6.1: Mechanical parts side view. Image taken by Serhat Türk.

29
CHAPTER 6. APPENDIX A

Figure 6.2: Mechanical parts over view. Image taken by Serhat Türk.

Figure 6.3: Table side view. Image taken by Serhat Türk.

30
Figure 6.4: Table over view. Image taken by Serhat Türk.

Figure 6.5: Finished construction. Image taken by Serhat Türk.

31
Chapter 7

Appendix B

Matlab Code

1 % Made by S e r h a t Turk , K r i s t o f f e r M u l l e r .
2 % 30/04 − 2021
3 % This code t a k e s a d i f f e r e n t i a l e q u a t i o n and s o l v e s i t with
Euler forward
4 % method . A f t e r s o l v i n g i t a G−code f i l e i s c r e a t e d with a l l
the points
5 % stored .
6 % The f i l e can then e a s i l y be uploaded t o our GTCRL code
7 %
8
9
10 clc
11 clear all
12
13 h = 0 . 2 ; % step s i z e
14 x = ( 1 : h : 1 0 ) ; % the range o f x
15 y = z e r o s ( s i z e ( x ) ) ; % a l l o c a t e the r e s u l t y
16 y (1) = 0 ; % the i n i t i a l y value
17 n = numel ( y ) ; % t h e number o f y v a l u e s
18
19 %The l o o p t o s o l v e
20 f o r i =1:n−1
21
22 f = 0 . 1 ∗ x ( i ) . ˆ 3 +0.5∗ x ( i ) . ˆ 2 +2∗x ( i )−8 ; % y ' i n your
DE
23 y ( i +1) = y ( i ) + h ∗ f ;
24 end
25

33
CHAPTER 7. APPENDIX B

26
27 % % Van d e r Pol o s c i l l a t o r , i t s p o s s i b l e t o g e t a gcode f o r
this aswell ,
28 % d o e s n t work t o d i s p l a y on t h e k i n e t i c a r t t a b l e
29
30 % tspan = [ 0 2 0 ] ;
31 % y0 = [ 2 ; 0 ] ;
32 % Mu = 1 ;
33 % ode = @( t , y ) vanderpoldemo ( t , y ,Mu) ;
34 % [ x , y ] = ode45 ( ode , tspan , y0 ) ;
35 % A1 = 1 5 5 + 7 . 5 ∗ [ x ] ;
36 % A2 = 1 5 5 + 7 . 5 ∗ [ y ( : , 1 ) ] ;
37
38
39
40 A1 = 155+[ x ] ; % 155 i s our z e r o p o s i t i o n f o r our maschine
41 A2 = 155+[ y ] ; % 155 i s our z e r o p o s i t i o n f o r our maschine
42
43 %P l o t with Matlab
44 p l o t (A1 , A2)
45 t i t l e ( ' S o l u t i o n f o r f with E u l e r metod ' )
46 x l a b e l ( ' x−a x i s ' )
47 y l a b e l ( ' y−a x i s ' )
48 xlim ( [ 1 5 5 1 6 9 ] )
49 ylim ( [ 1 3 0 6 5 0 ] )
50
51 % Convert matlab v e c t o r i n t o Gcode format
52
53 f i l e I D = f o p e n ( ' exp . gcode ' , 'w ' ) ; %C r e a t e s a new f i l e c a l l e d
exp i n gcode format
54 f p r i n t f ( f i l e I D , ' ; Created with MATLAB\n ; K r i s t o f f e r och
S e r h a t \n ; V e r s i o n : 0 . 1 . 2 \ n ; \ n ; Machine type : P o l a r \n ; \ n
' ) ; % Some i n f o r m a t i o n
55 formatSpec = ' G01 X%4.3 f Y%4.3 f \n ' ; % d e f i n i n g t h e format
o f t h e output data
56 f p r i n t f ( f i l e I D , formatSpec , A1 , A2) ; %a p p l i e s t h e formatSpec t o
a l l e l e m e n t s o f a r r a y s A1 and A2 ( c o o r d i n a t e s o f t h e
E u l e r metod ) .
57 f c l o s e ( f i l e I D ) ; %C l o s e s t h e f i l e

34
GCTRL Code

1 /∗
2 ∗
3 ∗ This code i s by sandeep and i t was found on h t t p s : / /
e l e c t r i c d i y l a b . com/how−to−make−arduino −mini−cnc−p l o t t e r −
machine /
4 ∗ I t r e a d s a t e x t f i l e and s e n d s o v e r any G−code t o t h e
Arduino .
5 ∗
6 ∗/
7
8 import j a v a . awt . e v e n t . KeyEvent ;
9 import j a v a x . swing . JOptionPane ;
10 import p r o c e s s i n g . s e r i a l . ∗ ;
11
12 S e r i a l port = n u l l ;
13
14 // s e l e c t and modify t h e a p p r o p r i a t e l i n e f o r your o p e r a t i n g
system
15 // l e a v e a s n u l l t o u s e i n t e r a c t i v e p o r t ( p r e s s ' p ' i n t h e
program )
16 // S t r i n g portname = n u l l ;
17 // S t r i n g portname = S e r i a l . l i s t ( ) [ 0 ] ; // Mac OS X
18 // S t r i n g portname = ”/ dev /ttyUSB0 ” ; // Linux
19
20 S t r i n g portname = ”COM3” ; // Windows p o r t f o r t h e a r d u i n o
21
22 // i n i t l a v a l u e s
23 boolean streaming = f a l s e ;
24 f l o a t speed = 0 . 0 0 1 ;
25 S t r i n g [ ] gcode ;
26 int i = 0;
27
28 void openSerialPort () {
29 // opens r i g h t s e r i a l p o r t
30 if ( portname == n u l l ) r e t u r n ;
31 if ( p o r t != n u l l ) p o r t . s t o p ( ) ;
32
33 // p o r t t h a t communicates with t h e a r d u i n o
34 p o r t = new S e r i a l ( t h i s , portname , 9 6 0 0 ) ;
35
36 p o r t . b u f f e r U n t i l ( ' \n ' ) ;

35
CHAPTER 7. APPENDIX B

37 }
38
39 void s e l e c t S e r i a l P o r t ( )
40 {
41 S t r i n g r e s u l t = ( S t r i n g ) JOptionPane . show InputDialog ( frame
,
42 ” S e l e c t t h e s e r i a l p o r t t h a t c o r r e s p o n d s t o your Arduino
board . ” ,
43 ” S e l e c t s e r i a l port ” ,
44 JOptionPane . PLAIN MESSAGE,
45 null ,
46 Serial . l i s t () ,
47 0) ;
48 // i f t h e r e i s no p o r t
49 i f ( r e s u l t != n u l l ) {
50 portname = r e s u l t ;
51 openSerialPort () ;
52 }
53 }
54
55 void setup ( )
56 {
57 // s e t s up program d i s p l a y
58 s i z e (500 , 250) ;
59 openSerialPort () ;
60 }
61
62 v o i d draw ( )
63 {
64 // d i f f e r e n t o p p t i o n s o f a c t i o n s t o c h o o s e from when i t i s
running .
65 background ( 0 ) ;
66 f i l l (255) ;
67 i n t y = 2 4 , dy = 1 2 ;
68 t e x t ( ”INSTRUCTIONS” , 1 2 , y ) ; y += dy ;
69 t e x t ( ”p : s e l e c t s e r i a l p o r t ” , 1 2 , y ) ; y += dy ;
70 t e x t ( ” arrow k e y s : j o g i n x−y p l a n e ” , 1 2 , y ) ; y += dy ;
71 t e x t ( ” 5 & 2 : j o g i n z a x i s ” , 1 2 , y ) ; y += dy ;
72 t e x t ( ” $ : d i s p l a y g r b l s e t t i n g s ” , 1 2 , y ) ; y+= dy ;
73 t e x t ( ”h : go home” , 1 2 , y ) ; y += dy ;
74 t e x t ( ” 0 : z e r o machine ( s e t home t o t h e c u r r e n t l o c a t i o n ) ” ,
1 2 , y ) ; y += dy ;
75 t e x t ( ” g : stream a g−code f i l e ” , 1 2 , y ) ; y += dy ;
76 t e x t ( ” x : s t o p s t r e a m i n g g−code ( t h i s i s NOT immediate ) ” ,

36
1 2 , y ) ; y += dy ;
77 y = h e i g h t − dy ;
78 text ( ” current jog speed : ” + speed + ” i n c h e s per step ” ,
1 2 , y ) ; y −= dy ;
79 t e x t ( ” c u r r e n t s e r i a l p o r t : ” + portname , 1 2 , y ) ; y −= dy ;
80 }
81
82 void keyPressed ( )
83 {
84 // s p e e d change
85 if ( key == ' 1 ' ) s p e e d = 0 . 0 0 1 ;
86 if ( key == ' 2 ' ) s p e e d = 0 . 0 1 ;
87 if ( key == ' 3 ' ) s p e e d = 0 . 1 ;
88 // k e y p r e s s e s with t o move t h e system ( we do not u s e t h e s e
ones )
89 i f ( ! streaming ) {
90 i f ( keyCode == LEFT) p o r t . w r i t e ( ”G21/G90/G1 X−10 F3500 \
n” ) ;
91 i f ( keyCode == RIGHT) p o r t . w r i t e ( ”G21/G90/G1 X10 F3500 \n
”) ;
92 i f ( keyCode == UP) p o r t . w r i t e ( ”G21/G90/G1 Y10 F3500 \n” ) ;
93 i f ( keyCode == DOWN) p o r t . w r i t e ( ”G21/G90/G1 Y−10 F3500 \n
”) ;
94 i f ( key == ' 5 ' ) p o r t . w r i t e ( ”M300 S50 \n” ) ;
95 i f ( key == ' 2 ' ) p o r t . w r i t e ( ”M300 S30 \n” ) ;
96 i f ( key == ' h ' ) p o r t . w r i t e ( ”G90\nG20\nG00 X0 . 0 0 0 Y0 . 0 0 0
Z0 . 0 0 0 \ n” ) ;
97 i f ( key == ' v ' ) p o r t . w r i t e ( ” $0=75\n$1=74\n$2=75\n” ) ;
98 // i f ( key == ' v ' ) p o r t . w r i t e ( ” $0 =100\n$1=74\n$2=75\n ” ) ;
99 i f ( key == ' s ' ) p o r t . w r i t e ( ” $3=10\n” ) ;
100 i f ( key == ' e ' ) p o r t . w r i t e ( ” $16=1\n” ) ;
101 i f ( key == ' d ' ) p o r t . w r i t e ( ” $16=0\n” ) ;
102 i f ( key == ' 0 ' ) o p e n S e r i a l P o r t ( ) ;
103 i f ( key == ' p ' ) s e l e c t S e r i a l P o r t ( ) ;
104 i f ( key == ' $ ' ) p o r t . w r i t e ( ” $$ \n” ) ;
105 }
106 // when p r e s s e d g , s e n d s t h e gcode t e x t f i l e i n t o t h e
a r d u i n o s e r i a l monitor
107 i f ( ! s t r e a m i n g && key == ' g ' ) {
108 gcode = n u l l ; i = 0 ;
109 File f i l e = null ;
110 p r i n t l n ( ” Loading f i l e . . . ” ) ;
111 s e l e c t I n p u t ( ” S e l e c t a f i l e to process : ” , ” f i l e S e l e c t e d ” ,
file );

37
CHAPTER 7. APPENDIX B

112 }
113 // when x i s p r e s s e d t h e s t r e a m i n g i s c a n c e l e d . d o e s not
work r i g h t away .
114 i f ( key == ' x ' ) s t r e a m i n g = f a l s e ;
115 }
116
117 void f i l e S e l e c t e d ( F i l e s e l e c t i o n ) {
118 i f ( s e l e c t i o n == n u l l ) {
119 p r i n t l n ( ”Window was c l o s e d o r t h e u s e r h i t c a n c e l . ” ) ;
120 } else {
121 p r i n t l n ( ” User s e l e c t e d ” + s e l e c t i o n . g e t A b s o l u t e P a t h ( ) ) ;
122 gcode = l o a d S t r i n g s ( s e l e c t i o n . g e t A b s o l u t e P a t h ( ) ) ;
123 i f ( gcode == n u l l ) r e t u r n ;
124 streaming = true ;
125 stream ( ) ;
126 }
127 }
128
129 // i f gcode i s s e n t , p r i n t i t i n t h e c o n s o l e .
130 v o i d stream ( )
131 {
132 i f ( ! streaming ) return ;
133
134 while ( true ) {
135 i f ( i == gcode . l e n g t h ) {
136 streaming = f a l s e ;
137 return ;
138 }
139
140 i f ( gcode [ i ] . t r i m ( ) . l e n g t h ( ) == 0 ) i ++;
141 e l s e break ;
142 }
143
144 p r i n t l n ( gcode [ i ] ) ;
145 p o r t . w r i t e ( gcode [ i ] + ' \n ' ) ;
146 i ++;
147 }
148
149 // c h e c k s i f i t i s p r o p e r t l y s e n t t o t h e a r d u i n o .
150 void s e r i a l E v e n t ( S e r i a l p)
151 {
152 S t r i n g s = p . r e a d S t r i n g U n t i l ( ' \n ' ) ;
153 p r i n t l n ( s . trim ( ) ) ;
154

38
155 i f ( s . t r i m ( ) . s t a r t s W i t h ( ” ok ” ) ) stream ( ) ;
156 i f ( s . t r i m ( ) . s t a r t s W i t h ( ” e r r o r ” ) ) stream ( ) ; // XXX: r e a l l y
?
157 }

39
CHAPTER 7. APPENDIX B

Arduino Code

1 /∗
2 ∗ S e r h a t Turk , K r i s t o f f e r M u l l e r
3 ∗ 28/4 − 2021
4 ∗
5 ∗ The b a s i c s o f t h e code i s by sandeep and i t was found on :
6 ∗ h t t p s : / / e l e c t r i c d i y l a b . com/how−to−make−arduino −mini−cnc−
p l o t t e r −machine /
7 ∗ I t was h e a v i l y m o d i f i e d t o work with our s p e c i f i c
construction .
8 ∗ This program r e a d s i n G−code and d i s c a r d s a l l t h e
u n c e s e s s a r y l e t t e r s and symbols
9 ∗ t h a t g e t s s e n t from a n t h e r program c a l l e d GCTRL v i a
p r o c e s s i n g program .
10 ∗ These G−code c o o r d i n a t e s i s r e a d a s x and y c o o r d i n a t e s
but l a t e r on c o n v e r t e d t o
11 ∗ rho and t h e t a c o o r d i n a t e s which makes t h e motors move
accordingly .
12 ∗/
13
14 #i n c l u d e <AFMotor . h>
15 #i n c l u d e <C o o r d i n a t e s . h>
16 // d e f i n e c o o r d i n a t e s c l a s s t o c a l c u l a t e p o l a r v a l u e s .
17 Coordinates point = Coordinates () ;
18
19 // a r r a y s i z e used l a t e r .
20 #d e f i n e LINE BUFFER LENGTH 512
21
22 // m i c r o s t e p p i n g f o r motors .
23 c h a r STEP = MICROSTEP;
24
25 const int stepsPerRevolution = 400;
26
27 // I n i t i a l i z e s t e p p e r s f o r rho and t h e t a u s i n g L293D s h i e l d
28 AF Stepper motorrho ( s t e p s P e r R e v o l u t i o n , 2 ) ;
29 AF Stepper m o t o r t h et a ( s t e p s P e r R e v o l u t i o n , 1 ) ;
30
31 // S t r u c t u r e s g l o b a l v a r i a b l e s , t h e s e a r e f o r c o o r d i n a t e s .
32 struct point {
33 float x;
34 float y;
35 };

40
36
37 // Current p o s i t i o n o f magnetic b a l l
38 s t r u c t point actuatorPos ;
39
40 // Drawing s e t t i n g s
41 in t StepInc = 1;
42 i n t StepDelay = 1 ;
43 i n t LineDelay = 0 ;
44 float scale = 155.0;
45 f l o a t addtheta = 0 . 0 ;
46 f l o a t addrho = 0 . 0 ;
47 int extrastep = 0;
48
49 // c a l c u l a t e d with MICROSTEPS. DIVIDE BY 2 IF YOU FORLOOP
INSTEAD OF MAKING ALL THE MOVES INSTANTLY
50 f l o a t S t e p s P e r M i l l i m e t e r R h o = 2 7 5 . 0 / s c a l e ; // (max s t e p o f
t h e arm/max mm t h a t t h e arm can move f r e e l y )
51 f l o a t StepsPerRadianTheta = 1 2 0 6 . 0 / ( 2 . 0 ∗ PI ) ; // ( s t e p s f o r 1
f u l l r o t a t i o n /(2∗ pi ) )
52
53 // Drawing r o b o t l i m i t s , i n mm
54 f l o a t rhomin = 0 . 0 ;
55 f l o a t rhomax = s c a l e ;
56 f l o a t thetamin = 0 . 0 ;
57
58 // s t a r t p o s i t i o n s ( 0 , 0 )
59 f l o a t rh op os = rhomin ;
60 f l o a t t h e t a p o s = thetamin ;
61
62 // Needs t o i n t e r p r e t
63 // G1 f o r moving
64 // D i s c a r d any o t h e r command !
65 void setup ( ) {
66 // Setup
67 S e r i a l . begin (9600) ;
68 delay (100) ;
69
70 i n t motorspeed = 1 0 ;
71 motorrho . s e t S p e e d ( motorspeed ) ;
72 m o t o r t he t a . s e t S p e e d ( motorspeed ) ;
73
74 // N o t i f i c a t i o n
75 S e r i a l . p r i n t l n ( ” everything i s running p r o p e r t l y ” ) ;
76 }

41
CHAPTER 7. APPENDIX B

77
78 void loop ( ) {
79 delay (100) ;
80 c h a r l i n e [ LINE BUFFER LENGTH ] ; // c r e a t e s an a r r a y t h a t
can s t o r e 512 c h a r s
81 c h a r c ; // c r e a t e s check v a r i a b l e .
82 i n t l i n e I n d e x ; // c r e a t e s l i n e i n d e x
83 b o o l lineIsComment , l i n e S e m i C o l o n ; // c r e a t e s b o o l s f o r
comments and s e m i c o l o n s f o r l i n e .
84
85 lineIndex = 0;
86 lineSemiColon = f a l s e ;
87 lineIsComment = f a l s e ;
88
89 while (1) {
90 // S e r i a l r e c e p t i o n − Mostly from Grbl , added s e m i c o l o n
support
91 // This r e a d s and s t o r e s S e r i a l i n p u t from GCTRL. These
i n p u t s comes i n rows .
92 w h i l e ( S e r i a l . a v a i l a b l e ( ) >0 ) {
93 c = S e r i a l . read ( ) ;
94 i f ( ( c == ' \n ' ) | | ( c == ' \ r ' ) ) { // End
of l i n e reached
95 i f ( lineIndex > 0 ){ // Line
i s c o m p l e t e . Then e x e c u t e !
96 l i n e [ l i n e I n d e x ] = ' \0 ' ; //
Terminate s t r i n g
97 processIncomingLine ( line , lineIndex ) ;
98 lineIndex = 0;
99 }
100 else {
101 // Empty o r comment l i n e . Skip b l o c k .
102 }
103 lineIsComment = f a l s e ;
104 lineSemiColon = f a l s e ;
105 S e r i a l . p r i n t l n ( ” ok ” ) ;
106 }
107 else {
108 i f ( ( lineIsComment ) | | ( l i n e S e m i C o l o n ) ) { //
i g n o r e a l l comment c h a r a c t e r s
109 i f ( c == ' ) ' ) lineIsComment = f a l s e ; // i f
end o f comment i s r e a c h resume l i n e .
110 }
111 else {

42
112 i f ( c <= ' ' ) { // d e l e t e empty s p a c e .
113 }
114 e l s e i f ( c == ' / ' ) { // Block d e l e t e not
supported . Ignore character .
115 }
116 e l s e i f ( c == ' ( ' ) { // Enable comments f l a g and
i g n o r e a l l c h a r a c t e r s u n t i l ' ) ' o r EOL.
117 lineIsComment = t r u e ;
118 }
119 e l s e i f ( c == ' ; ' ) {
120 lineSemiColon = true ;
121 }
122 e l s e i f ( l i n e I n d e x >= LINE BUFFER LENGTH−1 ) {
123 S e r i a l . p r i n t l n ( ”ERROR − l i n e B u f f e r o v e r f l o w ” ) ;
124 lineIsComment = f a l s e ;
125 lineSemiColon = f a l s e ;
126 }
127 // s t o r i n g v a l u e s i f t h e l e t t e r s i n l i n e
128 e l s e i f ( c >= ' a ' && c <= ' z ' ) { // Upcase
lowercase
129 l i n e [ l i n e I n d e x++ ] = c− ' a '+ 'A ' ;
130 }
131 else {
132 l i n e [ l i n e I n d e x++ ] = c ;
133 }
134 }
135 }
136 }
137 }
138 }
139
140 v o i d p r o c e s s I n c o m i n g L i n e ( c h a r ∗ l i n e , i n t charNB ) {
141 int currentIndex = 0;
142 c h a r b u f f e r [ 64 ] ; // 64 f o r 1 parameter . t h e b u f f e r t o
s t o r e the bytes in
143 s t r u c t p o i n t newPos ;
144
145 newPos . x = 0 . 0 ;
146 newPos . y = 0 . 0 ;
147
148 // Needs t o i n t e r p r e t
149 // G1 f o r moving
150 // G1 X60 Y30
151 // G1 X30 Y50

43
CHAPTER 7. APPENDIX B

152 // D i s c a r d any o t h e r command !


153 w h i l e ( c u r r e n t I n d e x < charNB ) {
154 s w i t c h ( l i n e [ c u r r e n t I n d e x++ ] ) { //
S e l e c t command , i f any
155 c a s e 'U ' :
156 break ;
157 c a s e 'D ' :
158 break ;
159 c a s e 'G ' :
160 b u f f e r [ 0 ] = l i n e [ c u r r e n t I n d e x++ ] ; // / ! \
D i r t y − Only works with 2 d i g i t commands
161 // b u f f e r [ 1 ] = l i n e [ c u r r e n t I n d e x++ ] ;
162 // buffer [2] = '\0 ';
163 b u f f e r [ 1 ] = ' \0 ' ;
164
165 switch ( atoi ( buffer ) ) { // S e l e c t G
command // a t o i t a k e s a s t r and c o n v e r t s i t t o i n t
166 case 0: // G00 & G01
− Movement o r f a s t movement . Same h e r e
167 case 1:
168 // / ! \ D i r t y − Suppose t h a t X i s b e f o r e Y
169 // Get X/Y p o s i t i o n i n t h e s t r i n g ( i f any )
170 c h a r ∗ indexX = s t r c h r ( l i n e+c u r r e n t I n d e x , 'X ' ) ;
171 c h a r ∗ indexY = s t r c h r ( l i n e+c u r r e n t I n d e x , 'Y ' ) ;
172 // compares p o s i t o n s i n d e x e s f o r t h e b a l l and s e t s
new x1 , y1 c o o r d i n a t e s
173 i f ( indexY <= 0 ) {
174 newPos . x = a t o f ( indexX + 1 ) ;
175 newPos . y = a c t u a t o r P o s . y ;
176 }
177 e l s e i f ( indexX <= 0 ) {
178 newPos . y = a t o f ( indexY + 1 ) ;
179 newPos . x = a c t u a t o r P o s . x ;
180 }
181 else {
182 newPos . y = a t o f ( indexY + 1 ) ;
183 ∗ indexY = ' \0 ' ;
184 newPos . x = a t o f ( indexX + 1 ) ;
185 }
186 // s t a r t s drawing from new c o o r d i n a t e s .
187 drawLine ( newPos . x , newPos . y ) ;
188 // S e r i a l . p r i n t l n ( ” ok ” ) ;
189 a c t u a t o r P o s . x = newPos . x ;
190 a c t u a t o r P o s . y = newPos . y ;

44
191 break ;
192 }
193 break ;
194 // s t o r e s new b u f f e r v a l u e s from l i n e a r r a y .
195 c a s e 'M' :
196 b u f f e r [ 0 ] = l i n e [ c u r r e n t I n d e x++ ] ; // / ! \
D i r t y − Only works with 3 d i g i t commands
197 b u f f e r [ 1 ] = l i n e [ c u r r e n t I n d e x++ ] ;
198 b u f f e r [ 2 ] = l i n e [ c u r r e n t I n d e x++ ] ;
199 b u f f e r [ 3 ] = ' \0 ' ;
200 switch ( atoi ( buffer ) ) {
201 case 300:
202 {
203 c h a r ∗ indexS = s t r c h r ( l i n e+c u r r e n t I n d e x , ' S ' ) ;
204 f l o a t Spos = a t o f ( indexS + 1 ) ;
205 // S e r i a l . p r i n t l n ( ” ok ” ) ;
206 break ;
207 }
208 c a s e 1 1 4 : // M114 − Repports p o s i t i o n
209 S e r i a l . p r i n t ( ” Absolute p o s i t i o n : X = ” ) ;
210 S e r i a l . print ( actuatorPos . x ) ;
211 Serial . print ( ” − Y = ” ) ;
212 S e r i a l . p r i n t l n ( actuatorPos . y ) ;
213 break ;
214 default :
215 S e r i a l . p r i n t ( ”Command not r e c o g n i z e d : M” ) ;
216 Serial . println ( buffer ) ;
217 }
218 }
219 }
220 }
221
222 // i n i t i a l l v a l u e s
223 f l o a t dtheta norm sum = 0 ;
224 f l o a t drho norm sum = 0 ;
225
226 /∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
227 ∗ Draw a l i n e from ( x0 ; y0 ) t o ( x1 ; y1 ) .
228 ∗ i n t ( x1 ; y1 ) : S t a r t i n g c o o r d i n a t e s
229 ∗ i n t ( x2 ; y2 ) : Ending c o o r d i n a t e s
230 ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/
231 v o i d drawLine ( f l o a t x1 , f l o a t y1 ) {
232
233 // s t a r t v a l u e s

45
CHAPTER 7. APPENDIX B

234 f l o a t rho0 = rh op os ;
235 f l o a t theta0 = thetapos ;
236
237 // c a l c u l a t i n t h e p o l a r c o o r d i n a t e s t o y1 and x1 .
238 // ! ! ! The c o o r d i n a t e s a r e s c a l e d with S a n d i f y s o i t
s t a r t s at (155 ,155) as the o r i g i n .
239 // ! ! ! For a n y t h i n g e l s e change t h e s c a l e t o a number
i n s t e a d o r remove i t f o r ( 0 , 0 ) .
240 p o i n t . f r o m C a r t e s i a n ( x1−s c a l e , y1−s c a l e ) ;
241 f l o a t rho1 = p o i n t . getR ( ) ;
242 f l o a t theta1 = point . getAngle ( ) ;
243
244 // s e t s max drawing d i s t a n c e rho
245 i f ( rho1 <= rhomin ) {
246 rho1 = rhomin ;
247 }
248 i f ( rho1 >= rhomax ) {
249 rho1 = rhomax ;
250 }
251
252 // rho and t h e t a d i f f e r e n c e .
253 f l o a t drho = abs ( rho1−rho0 ) ;
254 f l o a t d t h e t a = abs ( t h e t a 1 −t h e t a 0 ) ;
255
256 // d e c i d i n g which d i r e c t i o n s t h e motors a r e supposed t o
spin
257 i n t s r h o = rho1>rho0 ? S t e p I n c : −S t e p I n c ;
258 i n t s t h e t a = t h e t a 1 >t h e t a 0 ? S t e p I n c : −S t e p I n c ;
259
260 // t a k e s c a r e o f a n g l e movement from quadrant 1 t o 4 and
vice versa .
261 // makes i t move i n t h e r i g h t d i r e c t i o n i n s t e a d o f s p i n n i g
opposite directions .
262
263 i f ( t h e t a 1 >= 3 . 0 ∗ PI / 2 . 0 && t h e t a 0 <= PI / 2 . 0 ) { // remove
2∗ Pi i f i t g o e s from quadrant 1 −> 4
264 d t h e t a = −2.0∗ PI + t h e t a 1 − t h e t a 0 ;
265 s t h e t a = −1;
266 S e r i a l . p r i n t l n ( ”+ 2∗ p i ” ) ;
267 }
268 i f ( t h e t a 0 >= 3 . 0 ∗ PI / 2 . 0 && t h e t a 1 <= PI / 2 . 0 ) { // adds 2∗
Pi i f i t g o e s from quadrant 4 −> 1
269 S e r i a l . p r i n t l n ( ”− 2∗ p i ” ) ;
270 d t h e t a = −2.0∗ PI − t h e t a 1 + t h e t a 0 ;

46
271 stheta = 1;
272 }
273 d t h e t a = abs ( d t h e t a ) ;
274
275 // c a l u l a t e s amount o f m o t o r s t e p s t o move each motor .
276 f l o a t drho norm = round ( drho ∗ S t e p s P e r M i l l i m e t e r R h o ) ;
277 f l o a t dtheta norm = round ( d t h e t a ∗ StepsPerRadianTheta ) ;
278
279 // Take c a r e o f r ou n d i n g e r r o r s f o r t h e motor s t e p s .
280 a d d t h e t a += ( d t h e t a ∗ StepsPerRadianTheta − dtheta norm ) ;
281 addrho += ( drho ∗ S t e p s P e r M i l l i m e t e r R h o − drho norm ) ;
282 i f ( a d d t h e t a >=1){
283 ++dtheta norm ;
284 −−a d d t h e t a ;
285 }
286 i f ( a d d t h e t a <= −1){
287 −−dtheta norm ;
288 ++a d d t h e t a ;
289 }
290 i f ( addrho >=1){
291 ++drho norm ;
292 −−addrho ;
293 }
294 i f ( addrho <= −1){
295 −−drho norm ;
296 ++addrho ;
297 }
298 // bunch o f p r i n t s f o r t h e v a l u e s , t h i s used i n e r r o r
testing .
299 /∗
300 S e r i a l . p r i n t ( ” rho0 : ” ) ;
301 S e r i a l . p r i n t l n ( rho0 ) ;
302 S e r i a l . p r i n t ( ” rho1 : ” ) ;
303 S e r i a l . p r i n t l n ( rho1 ) ;
304 S e r i a l . p r i n t ( ” drho : ” ) ;
305 S e r i a l . p r i n t l n ( drho ) ;
306 S e r i a l . p r i n t ( ” drho norm : ” ) ;
307 S e r i a l . p r i n t l n ( drho norm ) ;
308
309 Serial . print (” theta0 : ”) ;
310 Serial . println ( theta0 ) ;
311 Serial . print (” theta1 : ”) ;
312 Serial . println ( theta1 ) ;
313 Serial . print (” dtheta : ”) ;

47
CHAPTER 7. APPENDIX B

314 S e r i a l . p r i n t l n ( dtheta ) ;
315 S e r i a l . p r i n t ( ” dtheta norm : ” ) ;
316 S e r i a l . p r i n t l n ( dtheta norm ) ;
317 S e r i a l . print (” stheta = ”) ;
318 Serial . println ( stheta ) ;
319 /∗
320 dtheta norm sum += dtheta norm ;
321 S e r i a l . p r i n t ( ” dtheta norm sum : ” ) ;
322 S e r i a l . p r i n t l n ( dtheta norm sum ) ;
323 /∗
324 drho norm sum += drho norm ;
325 S e r i a l . p r i n t ( ” drho norm sum : ” ) ;
326 S e r i a l . p r i n t l n ( drho norm sum ) ;
327 ∗/
328
329 f l o a t over = 0 . 0 ;
330
331 // Moving motors s o t h a t they move t o g e t h e r and ends a t
t h e same time .
332 i f ( drho norm > dtheta norm ) {
333 f l o a t d i v i d e r = dtheta norm / drho norm ;
334 f o r ( i n t i =0; i <drho norm ; ++i ) { // l o o p t o make r i g h t
amount o f s t e p s .
335 moverho ( s r h o ) ; // moves rho motors
336 // S e r i a l . p r i n t l n ( ” rho ” ) ;
337 o v e r += d i v i d e r ;
338 // makes t h e t a motor move s o t h e drawing becomes
correct .
339 i f ( o v e r >= 1 ) {
340 movetheta ( s t h e t a ) ;
341 −−o v e r ;
342 // S e r i a l . p r i n t l n ( ” t h e t a ” ) ;
343 }
344 // d e l a y ( StepDelay ) ;
345 }
346 }
347 e l s e i f ( dtheta norm > drho norm ) { // i f motor t h e t a moves
more s t e p s than motorrho
348 f o r ( i n t i =0; i <dtheta norm ; ++i ) {
349 f l o a t d i v i d e r = drho norm / dtheta norm ;
350 movetheta ( s t h e t a ) ;
351 o v e r += d i v i d e r ;
352 i f ( o v e r >= 1 ) {
353 moverho ( s r h o ) ;

48
354 −−o v e r ;
355 // S e r i a l . p r i n t l n ( ” rho ” ) ;
356 }
357 // d e l a y ( StepDelay ) ;
358 }
359 }
360 // s a v e s new v a l u e s t o t h e o l d o n e s .
361 r h o p o s = rho1 ;
362 thetapos = theta1 ;
363 // t u r n s o f t h e motors .
364 motorrho . r e l e a s e ( ) ;
365 motortheta . r e l e a s e ( ) ;
366 }
367
368 // t o move motor rho
369 v o i d moverho ( i n t s ) {
370 i f ( s == −1){
371 //BACKWARD
372 motorrho . s t e p ( 1 , BACKWARD, STEP) ;
373 }
374 else {
375 //FORWARD
376 motorrho . s t e p ( 1 , FORWARD, STEP) ;
377 }
378 return ;
379 }
380
381 // move motor t h e t a and rho s o t h a t t h e arm d o e s n t move when
it rotates .
382 v o i d movetheta ( i n t s ) {
383 i n t stepamount = 1 ;
384 int extra = 6;
385 i f ( s == −1){
386 //BACKWARD
387 m o t o r t he t a . s t e p ( stepamount , BACKWARD, STEP) ;
388 −−e x t r a s t e p ;
389 i f ( e x t r a s t e p == −e x t r a ) {
390 moverho ( s ) ;
391 extrastep = 0;
392 }
393 }
394 else {
395 //FORWARD
396 m o t o r t he t a . s t e p ( stepamount , FORWARD, STEP) ;

49
CHAPTER 7. APPENDIX B

397 ++e x t r a s t e p ;
398 i f ( e x t r a s t e p == e x t r a ) {
399 moverho ( s ) ;
400 extrastep = 0;
401 }
402 }
403 return ;
404 }

50
Acumen Code for simulation

1 // Made by S e r h a t Turk , K r i s t o f f e r M u l l e r .
2 // 23/3 − 2021
3 //
4 // This i s a s i m u l a t i o n on how our c o n s t r u c t i o n w i l l move a s
i t i s operating .
5 // I t i s e s s e n t i a l l y an arm moving i n and out and a r o t a t i n g
disk .
6 //
7 //
8
9
10 model Main ( s i m u l a t o r ) =
11 initially
12 // c r e a t e s a c1 i s r e d c i r k u l a r base , c2 i s t h e g r e e n arm
13 c1 = c r e a t e Arm( ( 0 , 0 , 0 ) , ( 0 , 0 , 0 ) ) , // i n p u t f o r p o s t i o n och
rotation
14 c2 = c r e a t e P l a t t a ( ( 0 , 0 , 0 ) , ( 0 , 0 , 0 ) ) , // i n p u t f o r p o s t i o n
och r o t a t i o n
15
16 // s t a r t data , e v e r y t h i n g i s s e t t o 0 i n t h e b e g i n n i n g
17 x1 =0, x1 ' =0, x1 ' ' =0, // d i s t a n c e , v e l o c i t y , a c c e l e r a t i o n f o r
x1 used f o r a n g l e s l a t e r
18 x2 =0, x2 ' =0, x2 ' ' =0, // d i s t a n c e , v e l o c i t y , a c c e l e r a t i o n f o r
x2 used f o r a n g l e s l a t e r
19 // v = 0 , v ' = 0 , v ' ' = 0 ,
20 rho = 0 . 3 5 , // f r i c t i o n c o e f f i c i e n c y f o r normal sand
21 m = 1 0 , // mass och t h e system
22 // g = 9 . 8 2 // a c c e l e r a t i o n k o n s t a n t ( not used i n t h i s c a s e )
23
24 // always l o o p t h a t s t a r t s and ends t h e s i m u l a t i o n .
25 always
26 i f x1<15
27 then x1 ' ' = −(x1 ' −0.3) // s e t s an a n g u l a r a c c e l e r a t i o n f o r
x1
28 e l s e i f x1 '>0
29 then x1 ' ' = −0.3 // s l o w s down t h e system i f t h i s g o e s
through
30 e l s e x1 ' ' = 0 , // c o n t i n u e s t h e a n i m a t i o n .
31 x2 ' ' = −100∗(x2−x1 ) −10∗( x2 '−x1 ' ) , // making t h e g r e e n arm
move p r o p e r t l y with t h e r e d c i r c l e
32 c2 . r o t = ( 0 , x2 , 0 ) , // maknig t h e r e d c i r c l e r o t a t e with and

51
CHAPTER 7. APPENDIX B

a c c e l e r a t i o n and r e t a r d a t i o n
33 // c h a n g e s t h e p o s i t i o n and r o t a t i o n o f t h e g r e e n arm t o
match t h e r o t a t i o n o f t h e r e d c i r c l e
34 c1 . pos = (−x2 /2∗ c o s ( x1 ) , −0.5 , x2 /2∗ s i n ( x1 ) ) ,
35 c1 . r o t = ( 0 , x1 , 0 )
36
37 // s t a r t model which i s used t o d e v e l o p e t h e g r e e n arm
38 model Arm( pos , r o t ) =
39 initially
40 3D = ( ) , P l o t =()
41 always
42 3D = ( Box
43 c e n t e r = pos + ( 0 , 0 , 0 )
44 c o l o r = green
45 size = (4 ,0.5 ,1)
46 rotation = rot
47 )
48
49 // s t a r t model which i s used t o d e v e l o p e t h e r e d c i r c l e b a s e
50 model P l a t t a ( pos , r o t ) =
51 initially
52 3D = ( ) , P l o t =()
53 always
54 3D =( C y l i n d e r
55 c e n t e r = ( 0 , 0 , 0 ) + pos
56 size = (0.5 ,2)
57 c o l o r = red
58 rotation = rot + (0 ,0 ,0)
59 )

52
53
CHAPTER 8. APPENDIX C

Chapter 8

Appendix C

8.1 Stepper motor datasheet

54
8.2. L293D MOTOR SHIELD DATASHEET

8.2 l293d motor shield datasheet

55
CHAPTER 8. APPENDIX C

Rajguru Electronics www.rajguruelectronics.com

L293D Based Arduino Motor Shield

Features:
 2 connections for 5V 'hobby' servos connected to the Arduino's high-resolution
dedicated timer - no jitter!
 Up to 4 bi-directional DC motors with individual 8-bit speed selection (so, about 0.5%
resolution)
 Up to 2 stepper motors (unipolar or bipolar) with single coil, double coil, interleaved or
micro-stepping.
 4 H-Bridges: L293D chipset provides 0.6A per bridge (1.2A peak) with thermal
shutdown protection, 4.5V to12V • Pull down resistors keep motors disabled during
power-up
 Big terminal block connectors to easily hook up wires (10-22AWG) and power
 Arduino reset button brought up top
 2-pin terminal block to connect external power, for separate logic/motor supplies
 Tested compatible with Mega, UNO & Duemilanove
 Dimensions: 69mm x 53mm x 14.3mm (2.7in x 2.1in x 0.6in)

The L293D is a dedicated module to fit in Arduino UNO R3 Board, and Arduino
MEGA. It is actually a motor driver shield that has full featured Arduino Shield can be used
to drive 2 to 6 DC motor and 4 wire Stepper motor and it has 2 set of pins to drive a SERVO.

56
8.2. L293D MOTOR SHIELD DATASHEET

Rajguru Electronics www.rajguruelectronics.com

L203D is a monolithic integrated that has a feature to adopt high voltage, high current
at four channel motor driver designed to accept load such as relays solenoids, DC Motors and
Stepper Motors and switching power transistor. To simplify to used as two bridges on each
pair of channels and equipped with an enable input. A separate supply input is provided for
the logic, allowing operation at a lower voltage and internal clamp diodes are included.

The device is suitable for use in switching applications at frequencies up to 5kHz. The
L293D is assembled in a 16 lead plastic package which has 4 centre pins connected together
and used for heat sinking. The L293D is assembled in a 20 lead surface mount which has 8
centre pins connected together and used for heat shrinking.

Items Min Typical Max Unit


Control Voltage 4.5 5 5.5 V
Driver Voltage 6 9 15 V
Output Current 1.2 A
Dimensions cm
Weight gm

Control up to 4 DC motors.
 Control 2 Servos.
 Logic Control Voltage VSS: 4.5 ~ 5.5 V
 Motor Supply Voltage VSS: 15v
 Drive operating current IO: 1.2A
 8 Stage Serial Shift Registers

Wiring a DC Motor

57
CHAPTER 8. APPENDIX C

Rajguru Electronics www.rajguruelectronics.com

Motor requires more energy specially cheap motors since chip motors less efficient.
The important thing you need is find out what voltage require your going to use. some small
motors are only intended to run at 1.5 volts but it is just a common to have 6 ~ 12v motors.
The motor controller on L294D shield is design to run at 4.5v to 25v. most 1.5 ~ 3 volts
motor will not works on this shield. another thing you need is to figure it out how much
current the motor will support? The L293D chip support up to 600 mA per motor, with 1.2A
peak current. Note ones you head towards 1A you’ll probably want to put a heat sink on the
chip, otherwise it will get thermal failure or burning out the chip.

Note:
Do not connect the motor to 5v line on the board. There are two places you can get
your motor high voltage supply.

58
8.2. L293D MOTOR SHIELD DATASHEET

Rajguru Electronics www.rajguruelectronics.com

Wiring and Installation the DC Motor to the l293D Shield

The DC motor are used for all sort of robotics projects. The motor shield can drive up
to 4 or 6 DC motors bi directional, it means that they can be driven forward and backward.
The speed can also be varied at 0.5% increments using PWM(Pulse with Modulation) this
means that speed can be controlled.

Note:
The H-Bridge Chip is not supported for driving load over 0.6A over 1.2A so this it
means that this chip is for small motors. Check the datasheet below to learn more. To connect
simply place the 2 wires to the terminal with screw and then connect them to either M1, M2,
M3, or M4 follow the example diagram above.

59
CHAPTER 8. APPENDIX C

Rajguru Electronics www.rajguruelectronics.com

Schematic :

60
TRITA-ITM-EX 2021:19

www.kth.se

You might also like