• No results found

Ball ballancing robot

N/A
N/A
Protected

Academic year: 2021

Share "Ball ballancing robot"

Copied!
54
0
0

Loading.... (view fulltext now)

Full text

(1)

IN

DEGREE PROJECT TECHNOLOGY, FIRST CYCLE, 15 CREDITS

STOCKHOLM SWEDEN 2017,

Ball ballancing robot

FREDRIK SANDAHL

WILLIAM MILES

(2)
(3)

Ball balancing robot

Bachelor thesis

FREDRIK SANDAHL WILLIAM MILES

Bachelor thesis at KTH Supervisor: Fariba Rahimi

Examiner: Nihad Subasic

MMK 2017:31 MDAB 649

(4)
(5)

Abstract

This report will research how micro stepping effects the vibrations from the motors. The report will also cover the steps that are needed for design a ball balancing robot. This type of robot can be seen as an inverted pendulum. Without any controller the system is unstable and the robot will fall. With help of an IMU that provides the necessary data which is needed to implement a controller which makes it possible for the robot to balance on the ball. Because of weak motors the robot wasn’t able to balance. Other reasons and areas of improvement is discussed in the report.

(6)

Sammanfattning

Denna rapport utforskar hur mikrosteg påverkar vibrationerna från motorerna. Rap- porten beskriver även de nödvändiga stegen för hur man designar en balanseringsrobot.

Denna typ av robot kan ses som en inverterad pendel. Utan någon kontroller är systemet ostabilt och roboten kommer att falla. Med hjälp av en IMU tillhandahålls nödvändig data som behövs för att implementera en kontroller som gör det möjligt för roboten att balansera på bollen. På grund av svaga motorer kunde roboten inte balansera. Andra orsaker och förbättringsområden diskuteras i rapporten.

(7)

Acknowledgements

We would like to thank our supervisor, Fariba Rahimi for the feedback and support.

Tomas Österås, Staffan Qvarnström for the electrical and mechanical manufacturing and the lab assistants.

(8)

Contents

Contents

1 Introduction 4

1.1 Background . . . 4

1.2 Scope . . . 4

1.3 Method . . . 4

2 Theory 6 2.1 Omni-wheel Dynamic . . . 6

2.2 Motor control . . . 8

2.2.1 Stepper motor . . . 8

2.2.2 H-bridge . . . 8

2.3 Microcontroller . . . 8

2.4 Control theory . . . 9

2.5 Internal measurement Unit . . . 9

2.6 Filtering . . . 9

2.7 Theoretical analysis . . . 10

3 Demonstration 12 3.1 Hardware . . . 12

3.1.1 Microcontroller . . . 12

3.1.2 The Robot . . . 13

3.2 Data reading, v, ψ, ˙ψ and x . . . . 14

3.3 Movement - Ball and robot . . . 15

3.4 Conducting tests . . . 16

4 Result 18 5 Discussion and conclusions 22 5.1 Discussion . . . 22

5.2 Conclusions . . . 22

6 Recommendation and future work 23

(9)

Bibliography 24

A Verifying Kalman filter with MPU-6050 26

B Results and graphs from disturbance testing 29

C Arduino code 34

(10)
(11)

Nomenclature

Abbreviation Description CAD Computer-aided design CPU Central Processing Unit DC Direct current

IMU Internal measurement unit MATLAB Matrix Laboratory

MEMS Micro-electro-mechanical system PWM Pulse width modulation

RAM Random Access Memory Symbols Description

Angular velocity for robot (degrees/s) τ0 Torque (N m)

θx Angle between robot and upright position along x-axis (degrees) θy Angle between robot and upright position along y-axis (degrees) ax Acceleration along x-axis (m/s2)

ay Acceleration along y-axis (m/s2) I Moment of inertia(kgm2)

Ib Moment of inertial of ball (kgm2) Ip Moment of inertial of robot (kgm2) KA Gain constant

KV Gain constant

(12)

KAV Gain constant KT Gain constant

L Angular momentum (kgm2/s) l Height of center of mass (m) m Mass of the falling person (kg) mb Mass of the ball (kg)

mp Mass of the robot (kg) rb Radius of the ball (cm)

rw Radius of the omni-wheels (cm) vx Velocity along x-axis (m/s) vy Velocity along y-axis (m/s)

w Angular velocity for the ball (rad/s) x Distance traveled along x-axis (m) y Distance traveled along y-axis (m)

(13)

Chapter 1

Introduction

1.1 Background

To make robots be a part of humans everyday life they need too be flexible and move around objects in an efficient way, take little space to manage the crowded areas and be able to be knocked by individuals without falling or losing control. Two wheeled balancing robot was demonstrated in Japan 1994 [18]. The design eliminated the third wheel to make it stable and made the robot take less space but it could not maneuver side ways. The project led to new ideas, to use a ball as the wheel. There are benefits with this design, they leave very little footprint and are very agile. Many different robots have been made using different drivers like DC motors, servo motors and stepper motors.

Commonly they are modeled as inverted pendulums and balanced with control theory.

1.2 Scope

The process of making a self balancing robot on a ball is very complex. The aim for this project is to use stepper motors instead of DC motors. Because stepper motors vibrate much more than DC motors it is important to minimize the noise they generate. The report will investigate the following questions. One will be able to answer by investigating and the other by research.

• How does raise/lowering the center of mass of the ball balancing robot affect the dynamics of the robot?

• How to maximize the torque from the stepper motors in relationship to the disturbance that affects the IMU readings?

1.3 Method

The goal of this project is to make a ball balancing robot. To achieve this objective the following procedure is done.

(14)

• Design the test rig as a CAD model and create the test rig using a 3D-printer.

• Derive the equation for controlling the ball with the omni wheels.

• Extract values from the IMU and filter out the noise.

• Extract the data from the sensors and filter it too make it accurate.

• Find the optimal micro-stepping that will cause high torque without causing too much noise.

The robot will be powered by three stepper motors to ensure precision from the motors. Each motor is turning one omni wheel. The omni wheels are designed to be in an angel that will prevent the robot from sliding of the ball. A accelerometer and gyroscope will give the feedback signal to the controller to be analyzed. The calculations are done by an Arduino Uno. The robot are designed to fit a size five football.

(15)

Chapter 2

Theory

2.1 Omni-wheel Dynamic

[1]

Figure 2.1: Omni wheels degrees of freedom.

(16)

Figure 2.2: This will be the positioning of the Omni-wheels on the spherical wheel [2]

Omni-wheels has the ability to move in the direction perpendicular to its own rotation.

But there is only one direction that can be controlled. The Omni-wheels that have been used for this project have cylindrical bearings around the wheel, which can be seen in the figure 2.1. The bearings make the wheels have two degrees of freedom. By combining three omni wheels with an angel of 120 form each other as seen in 2.2.

(17)

2.2 Motor control

2.2.1 Stepper motor

For this project a stepper motor has been chosen because of there high precision without using an encoder. Stepper motor is a brushless DC-motor that have the benefit of being able to split every rotation too many small steps of equal sizes. This makes the stepper motor very precise. It can be commanded to hold a specific position without needing any feedback controller. Stepper motor is controlled by sending electric pulses to the motor and every pulse makes the motor turn one step. By having two electromagnets and teeth that are not aligned with the magnets, giving current to the different electromagnets will make the axis step. The stepper motor that has been used in this project is a two phase stepper motor[9].

2.2.2 H-bridge

Figure 2.3: Representation of an H-bridge [3]

H-bridge is used to control motors. This is done by turning different transistors on and off. So that the direction of the motor can be controlled by directing the current through transistors that works as switches. In the H-bridge the switches which are parallel to each other works together. When one par is open the other one is closed, see figure 3.4. In this way the direction of the current changes which will make the motor rotate in different direction. In this project dual h-bridges has been used, they work in the same way that a single H-bridge works but because a stepper motor has two coils a dual H-bridge is needed[12].

2.3 Microcontroller

A microcontroller is a small computer with integrated circuit, it has memory, one CPU or more, small amount of RAM and out/in pins. The most common uses for microcontroller is embedded systems. The microcontroller is able to read data from sensors, compute and give commands to the motors. [8].

(18)

2.4 Control theory

The control equations are represented by :

ax = KAθx+ KAVθ˙x+ KT(x − x0) + KVvx (2.1) ay = KAθy+ KAVθ˙y + KT(y − y0) + KVvy (2.2) θ is the angel and ˙θ is the angular velocity, x/y is the position is x/y directions and v is the velocity of the ball. KA, KAV, KT and KV is different gains. The gains can be detriment by experimenting. This is most commonly done by setting all the gains to zero and start testing too find a KA where the system starts too become stable. Then fine tuning the robot by changing the rest of the gains. [4]

2.5 Internal measurement Unit

To be able to measure the position of the robot an Internal measurement Unit (IMU) is used to measure acceleration and angular rate. It is built up with one or more linear accelerometers and one or more gyroscopes or angular accelerometers. Accelerometers are a type of transducers that gives away electrical signals that are proportional to the exposed accelerations. The accelerometer is fastened to the frame of the structure that it is going to measure. A small mass inside the accelerometer is free to move and because of gravity inertia the mass will move and it will be converted into electrical signals. A new method has been developed where the measurement unit is made of silicon structure.

It has small movable silicon rods that are very robust. They are often used in cellular devices. The accelerometers are very sensitive and detect a lot of noise from disturbance.

[5]

Complementary too the accelerometer the IMU uses gyroscopes too be able too get a more accurate measurement. They measure angular rate or orientation about a given directional vector. It’s principal is having a spinning disc which is supported in light rings. Because of the frictionless joints in the rings the spinning disc will always point at the same direction. But too fit a gyroscope in a small circuit board they use vibrating gyros called MEMS. It has a mass vibrating using piezoelectric current. When the gyro is spun the mass wants too keep vibrating in the same direction which causes them too put pressure on piezoelectric components which send an electrical signal to the computer [11].

2.6 Filtering

The IMU provides real time data but because of the sensitivity of the sensors they detect lots of noise. Vibrations from the motors affect the reading from the accelerometer.

Too get an accurate reading for the angle that the robot is tilting the signals from accelerometer and gyro are fused together. By applying a Kalman filter for the signal fusing, a steady and accurate reading can be obtained. Kalman filter weights the sources

(19)

of information depending on the knowledge about the signal and its characteristics.

Because every sensor has flaws, weak and strong features, the signal fusing complements the different weaknesses of the different sensors, gyro and accelerometer [7].

2.7 Theoretical analysis

An important aspect when designing a ball balancing robot is to raise the center of mass, because this will lead to a longer fall time for the robot. Which will mean that the system will have more time to become stable again. A ball balancing robot is often seen as an inverted pendulum which means that the system is unstable. The human body can be seen as an inverted pendulum because input from our muscles is needed too keep the human body from falling over[15].

So what are the proofs that raising the center of mass also will raise the fall time?

This has been proven [6].

Figure 2.4: Simple model of a human falling. g is the gravity, l is the length from the ground to the center of mass of the body and theta is the angel from the upright position to degree that the body have fallen [15]

If one of the foots is attached to the ground the fall can been seen as having the falling pattern of an arc. with these assumptions the fall can been seen as an inverted pendulum with l as the length from the floor to the center of mass for the b ody. It will also be assumed that the body only can move in θ direction. The angular momentum principle can then be used which are described as:

τ0 = dL0

dt (2.3)

(20)

| L0|= Idθ

dt (2.4)

Angular moment is a vector but in this case the vector dose not change direction if the body is rigid. The gravity can be summarized too only be pulling on the center of mass for the human body so the torque can be written as:

τ0 = mgl

2sin(θ) (2.5)

The moment of inertia can be written as:

I = ml2

3 (2.6)

If equation 2.6 is inserted in equation 2.4. If then equation 2.4 is derived it will be equal to the torque so we can replace the torque with equation 2.5. If then the second derivative of θ is moved to one side the angular acceleration will be:

d2θ

dt2 = 3gsin(θ)

2l (2.7)

Where equations 2.7 shows that the height to the center of mass is linear proportional to the angular acceleration. This is the equation when the mass is evenly distributed over the hole body, but in the case with a inverted pendulum the mass is assumed too be at the top. So the equation for an inverted pendulum is:

d2θ

dt2 = gsin(θ)

l (2.8)

So the angular acceleration will be slower with a factor of 3/2 for the inverted pendu- lum which is another reason too have as much of the weight at the top of the robot. But the principles are still the same, the angular acceleration will decrease with the length to the center of mass.

(21)

Chapter 3

Demonstration

3.1 Hardware

3.1.1 Microcontroller

In this project an Arduino uno(ATmega328P) is used, it has 16 in/out-pins of which six provides a PWM signal and operates at 5v.

Figure 3.1: Schematics of the hardware and their communication. Made in Lucidchart.

(22)

Figure 3.2: Flowchart for the algorithm. Made in Lucidchart.

3.1.2 The Robot

The stepper motor that is used for this project is KH39F52-851. It is a two phase hybrid stepper motor and the drive method is bipolar. It was chosen because they could rotate in both direction and the motors are very precise. The omni wheel that are used has a diameter of 50 mm.

(23)

Figure 3.3: CAD model of the robot, missing Arduino and H-bridge circuit. Made in Solid Edge.

Figure 3.3 shows the robot which is made in CAD. From the CAD program the robots moment of inertia, mass and center of mass is found. The parameters are shown in the table bellow.

rb Radius of the ball 111 cm

rw Radius of the omni wheels 2.5 cm

mp Mass of robot 2.113 kg

mb Mass of ball 0.6 kg

Ip Moment of inertia of robot 0.111 kgm2 Ib Moment of inertia of ball 0.00484 kgm2 l Height of center of mass 0.275 m

3.2 Data reading, v, ψ, ˙ ψ and x

The IMU inbuilt gyro can sense angular velocity and the inbuilt accelerometer senses angular acceleration in three axis from the raw values of the sensor . According to the data sheet the IMU is able to be set for different sensitivity’s in different ranges [14].

The accelerometer is set to ±2g and the gyro to ±250/s for highest resolution. An open source kalman filter is used to signal fuse the accelerometer readings and the gyro readings and ψ is calculated. From the acceleration the velocity is derived by numerical integration in real time by,

vi+1= vi+ ˙vi+1dt (3.1)

where dt is the time difference from the last loop and ˙v is the acceleration from the ac- celerometer. Data from the IMU’s gyro is the angular velocity. Which is then translated

(24)

in to proper values and used for ˙ψ. x is the movement of the ball and is calculated by

x = wrb (3.2)

where w is the angular velocity of the ball around the x axis and rb is the radius of the ball. The four states that are needed are now known for the x axis. The same equations are used too find the states in the y axis.

3.3 Movement - Ball and robot

[10]

Figure 3.4: The test rig, θ will be set to 30 degrees.

The translation from speed of the ball to the velocity for the motors has already been studied[13] and the following equation has been used in similar problem.[13]

First step is too split up the speed v into velocity vf that is parallel to the wheels axis and vs that are perpendicular to the wheel axis. They are related to v by introducing the unit vector s.

(25)

vs = vss + vfs = ± | vs || s | +0 = vs (3.3) The s matrix is:

s =

0 −1 0

3 2

1

2 0

3 2

1

2 0

(3.4)

The velocity vs can also be described with the angular velocity w and the position vector p.

vsi=

3

X

j=1

(wj × pi)(si)T (3.5)

The matrix p is:

p = rb

sin(θ) 0 cos(θ)

12sin(θ)

3

2 sin(θ) cos(θ)

12sin(θ)

3

2 sin(θ) cos(θ)

(3.6)

And the w matrix is:

w =

wx 0 0 0 wy 0

0 0 wz

(3.7)

This will give the expression for the velocity for motor one, two and three:

vs1 vs2

vs3

=

−vycos(θ) − rbsin(θ)wz (

3

2 vx+ vy12)cos(θ) − rbsin(θ)wz

(−

3

2 vx+ vy12)cos(θ) − rbsin(θ)wz

(3.8)

Equation (3.8) yields the translation from velocity of the ball to the velocity for the motors for the ball balancing robot.

3.4 Conducting tests

The precision that a stepper motor offers makes it suitable for many tasks. Full step on many stepper motor and on the KH39FM2-851 that is used for this project has a step angle of 1.8. Too increase the precision the H-bridge is able too micro step the motors.

When half stepping, the step angle is divided by two. Therefor the stepping angle becomes 0.9 per step. The H-bridge is able too make the motors move in sixteenth of a step, the stepping angle is then 1.8/16[17]. While micro stepping the torque drastically decreases and the top speed of the motors rotation. The current is proportional to the torque, but because of magnetic saturation there is no advantage of increasing the current more than 100% of the recommended current limit. There is also a greater chance of

(26)

damaging the motors[16]. In table 3.4 the different holding torques are shown depending on what micro stepping setting is used.

Micro steps/full step % Holding Torque/Micro step

1 100.00%

2 70.71%

4 38.27%

8 19.51%

16 9.80%

[17]

Figure 3.5: Graph over how the torque decays while microstepping

In figure 3.5 the holding torque is shown until 256 of a full step. If the precision becomes too high the motor may not have enough torque too turn because of its own friciton.

To be able to obtain accurate readings from the IMU it is necessary to cancel as much noise as possible from the motors. The stepper motors vibrate a lot when they are driven in low speeds. Too minimize noise the stepper motor driver is capable of micro stepping.

Several tests are made to evaluate the impact on the IMU when micro stepping. The motors are driven in two different speeds when micro stepping in full-, half-, eight- and sixteenth step. The data are plotted in MATLAB and an average amplitude of four test are summarized to evaluate the disturbance. The robot was placed on a flat floor and the bearings that are on the motors shaft make them turn without the robot moving.

(27)

Chapter 4

Result

The results for this project is obtained by several test using the finalized robot. The disturbance from the motors are then compared with the loss of torque that the stepper motors suffer when micro stepping.

Figure 4.1: Relation between the acceleration (x-axis) disturbance and torque loss

(28)

Figure 4.2: Relation between the acceleration (y-axis) disturbance and torque loss

(29)

Figure 4.3: Relation between the angle (x-axis) disturbance and torque loss

(30)

Figure 4.4: Relation between the angle (y-axis) disturbance and torque loss The graphs show high disturbance while full stepping and makes it very inefficient too use even though 100% of the torque can be utilized. Inputs with too much disturbance will make the robot not be able too function properly. But if the torque loss is too great there is a risk that the motors will start too slip. If the motors are chosen wisely the optimal stepping setting is around a quarter step. The angular disturbance is less than 1 degrees in every case except one and the acceleration does not peak over 1m/s2. There is a loss in torque with 38% .

Equation 2.7 shows that the acceleration will decrease depending on the length to the center of mass. It is impossible too determine the exact time that it takes the body to hit the ground without providing information about the deviation of angel θ from zero in the beginning. So the system would stay upright if the angel was exactly zero, but even the smallest offset will make the system fall. The fact that the angular acceleration will decrease with length l to the center of mass will lead to that the speed will do the same and lower speed will lead to longer fall time.

(31)

Chapter 5

Discussion and conclusions

5.1 Discussion

The results shows some deviation, but conclusions can be made. The deviation was caused by vibration in the ground from other project or from other students walking nearby. Conclusions that can be made from the graphs is that half step is pointless to use because it outputs less torque and causes more noise than full step. Quarter step causes significant less noise than full step and can still output 40% of the torque.

Quarter step is causing so little noise that is possible to use for a ball balancing robot project. When using eight step and sixteenth step the torque will decrease but they cause negligible noise. If a motor is able to output a lot more torque than is needed, eight step is still recommended because it causes a small amount of noise and the torque is 19.5%

compared to 9.8% for sixteenth step. The torque is almost half as big for sixteenth step but the noise is similar.

By raising the center of mass of an unstable system like an inverted pendulum, it will fall slower which is shown in chapter 2.7. It can be achieved by putting a weight (or the battery for the robot) on top of the robot. But with greater mass the motors must be able to output greater torque which means bigger motors. The best solution is to make a light rig with a small mass on top.

5.2 Conclusions

When creating a ball balancing robot with stepper motors, the motors have to be strong enough even when micro-stepping with at least quarter stepping. If the motors are too weak for quarter stepping so that half or full step is needed to be used the disturbance from the motors to the IMU will be too high. The main reason for the robot to fail balancing purpose was that the motors were too weak.

If the motor spins faster they will become weaker, so bigger omni-wheels should be used which lowers the speed that is needed to output.

If the motor spins faster they will become weaker, so bigger omni-wheels should be used which will lower the needed output speed from the motors.

(32)

Chapter 6

Recommendation and future work

There is still some future work that needs to be done before the robot will be balancing on a ball. Upgrading the stepper motors for higher torque is essential for the robot to function. Also installing bigger omni wheels is beneficial to achieve a faster speed while micro stepping.

(33)

Bibliography

[1] http : / / www . solostocks . com . mx / venta - productos / rodamientos / otros - rodamientos/ruedas- multidireccionales- rotacaster- 1429329. [Online; ac- cessed 15-05-2017].

[2] http://makezine.com/projects/make-40/kiwi/. [Online; accessed 15-05-2017].

[3] https : / / circuitdigest . com / electronic - circuits / h - bridge - motor - driver-circuit-diagram. [Online; accessed 15-05-2017].

[4] http://www.mech.tohoku- gakuin.ac.jp/rde/contents/tech/BallIPMini/

techinfo.html#eRgkKfLoemPcAncCQcCicCacCcBhjfUt. [Online; accessed 23-04- 2017].

[5] Accelerometers Information. [Online; accessed 10-April-2017]. url: http://www.

globalspec.com/learnmore/sensors_transducers_detectors/acceleration_

vibration_sensing/accelerometers.

[6] Rhett Allain. Center of Mass: Tools and Techniques for Animating Natural Human Movement. https://www.wired.com/2014/09/how-long-does-it-take-for- a-pencil-to-tip-over/. [Online; accessed 11-05-2017]. 2017.

[7] An introduction to the beginning of motion capture technology. [Online; accessed 19-April-2017]. url: https://www.xsens.com/fascination-motion-capture/.

[8] Arduino Uno SMD. [Online; accessed 19-April-2017]. url: https://www.arduino.

cc/en/Main/ArduinoBoardUnoSMD.

[9] Automatic Commutation of Stepper Motors using low cost standard stepper drivers.

[Online; accessed 19-April-2017]. url: http : / / www . portescap . com / sites / default/files/wp_automatic_commutation_of_stepper_motors_0.pdf.

[10] Development of a ball balancing robot with omni wheels. [Online; accessed 6-April- 2017]. url: http://www.control.lth.se/documents/2012/5897.pdf.

[11] Gyroscopes Information. [Online; accessed 10-April-2017]. url: http : / / www . globalspec.com/learnmore/sensors_transducers_detectors/tilt_sensing/

gyroscopes.

[12] Hans Johansson. Elektroteknik. 3-48: KTH, 2013.

[13] Masaaki Kumagai and Takaya Ochiai. Development of a Robot Balancing on a Ball. Tohoku Gakuin University: Journal of robotics and mechatronics Vol.22 No.3, 2010, 2008.

(34)

[14] MPU-6000/MPU-6050 Product Specification. [Online; accessed 19-April-2017]. url:

https : / / www . invensense . com / wp - content / uploads / 2015 / 02 / MPU - 6000 - Datasheet1.pdf.

[15] Eiko Oba. Center of Mass: Tools and Techniques for Animating Natural Human Movement. http://www.gamasutra.com/view/feature/132982/center_of_

mass_tools_and_.php?print=1. [Online; accessed 11-05-2017]. 2017.

[16] Stepper Motor Speed and Torque Relationship. http://www.nmbtc.com/step- motors / engineering / torque - and - speed - relationship/. [Online; accessed 15-05-2017].

[17] Stepper Motor Technical Note: Microstepping Myths and Realities. http://www.

micromo.com/media/wysiwyg/Technical-library/Stepper/6_Microstepping%

20WP.pdf. [Online; accessed 15-05-2017].

[18] George Kantor Tom Lauwers and Ralph Hollis. One is Enough! The Robotics Institute, Carnegie Mellon University, 2005.

(35)

Appendix A

Verifying Kalman filter with MPU-6050

For the robot too respond in the correct way it is crucial that the sensor fusion with the kalman filter has small errors. Too verify that the kalman filter performs good enough test where made. The IMU was fasten to a servo, which rotated the IMU for given angles and speed. Bellow the graphs from the test are shown.

Figure A.1: Angle from the IMU threw the kalman filter oscillating between +-45 degrees

(36)

Figure A.2: Angle from the IMU threw the kalman filter oscillating between +-10 degrees

Figure A.3: Angle from the IMU threw the kalman filter oscillating between +-45 degrees

(37)

Figure A.4: Angle from the IMU threw the kalman filter oscillating between +-5 degrees By studying at the graphs the angle deviates by a little. For the grater angles,

±45degrees there is also a delay for the readings with 150ms and a slight overshoot.

While turning the IMU ±10 degrees the delay is 90ms and the angle overshoot is about 2degrees. And ±5 degrees gives a delay of 70ms and a angular error as the most of 0.8 degrees. The results show that the IMU performs well and the small delays that accrues are minor. For small angles the IMU is more precise than moving over a wider range of angles. Because the robot will only experience fairly small changes in angle there will not be a problem.

(38)

Appendix B

Results and graphs from disturbance testing

Below are graphs for how acceleration or the angel for x or y for a motor speed of 0.5rad/s or 1rad/s from full step till stepping sixteenth step di˙ers when robot is standing still but the motors are on. The reference value is the disturbance when the motor is turned of. All diagrams in Appendix B are made in Microsoft Excell.

Figure B.1: Difference in acceleration for x for motor speed of 0.5rad/s.

(39)

Figure B.2: Difference in acceleration for y for motor speed of 0.5rad/s.

Figure B.3: Difference in acceleration for x for motor speed of 1rad/s.

(40)

Figure B.4: Difference in acceleration for y for motor speed of 1rad/s.

Figure B.5: Difference in angle for x for motor speed of 0.5rad/s.

(41)

Figure B.6: Difference in angle for y for motor speed of 0.5rad/s.

Figure B.7: Difference in acceleration for x for motor speed of 1rad/s.

(42)

Figure B.8: Difference in acceleration for y for motor speed of 1rad/s.

(43)

Appendix C

Arduino code

1

i n c l u d e <I2Cdev . h>

3

i n t k = 0;

5 /∗ Copyright (C) 2012 K r i s t i a n Lauszus , TKJ E l e c t r o n i c s . All r i g h t s r e s e r v e d .

This s o f t w a r e may be d i s t r i b u t e d and modified under the terms o f the GNU

7 General Public Licens e v e r s i o n 2 (GPL2) as published by the Free Software Foundation and appearing in the f i l e GPL2.TXT in clu ded in the packaging

o f

9 t h i s f i l e . Please note that GPL2 S e c t i o n 2 [ b ] r e q u i r e s that a l l works based

on t h i s s o f t w a r e must a l s o be made p u b l i c l y a v a i l a b l e under the terms o f

11 the GPL2 ( " Copyleft " ) . Contact information

13 −−−−−−−−−−−−−−−−−−−

K r i s t i a n Lauszus , TKJ E l e c t r o n i c s

15 Web : http : / /www. t k j e l e c t r o n i c s . com e−mail : k r i s t i a n l @ t k j e l e c t r o n i c s . com

17

∗/

19

#i n c l u d e <Wire . h>

21

#i n c l u d e " Kalman . h " // Source : https : / / github . com/ TKJElectronics / KalmanFilter

23

#d e f i n e RESTRICT_PITCH // Comment out to r e s t r i c t r o l l to 90deg i n s t e a d − p l e a s e read : http : / /www. f r e e s c a l e . com/ f i l e s / s e n s o r s /doc/app_note/

AN3461 . pdf

25

27

Kalman kalmanX ; // Create the Kalman i n s t a n c e s

29

Kalman kalmanY ;

31

(44)

33 // V a r i a b e l s f o r c o n t r o l l e r

35 f l o a t K_A = 1 0 0;

37 f l o a t K_AV = 0;

39 f l o a t K_T = 0;

41 f l o a t K_V = 0;

43 f l o a t ax ; f l o a t ay ;

45 f l o a t X = 0; f l o a t Y = 0;

47 f l o a t x_0; f l o a t y_0;

49 f l o a t x_old = 0; f l o a t y_old = 0;

51 // end f o r c o n t r o l l e r v a r i a b l e r

53 // stepping mode

55#i f 0

#d e f i n e M1 LOW

57#d e f i n e M2 LOW

#d e f i n e M3 LOW

59#d e f i n e comp 1

#e n d i f

61#i f 0

#d e f i n e M1 HIGH

63#d e f i n e M2 LOW

#d e f i n e M3 LOW

65#d e f i n e comp 2

#e n d i f

67#i f 0

#d e f i n e M1 LOW

69#d e f i n e M2 HIGH

#d e f i n e M3 LOW

71#d e f i n e comp 4

#e n d i f

73#i f 0

#d e f i n e M1 HIGH

75#d e f i n e M2 HIGH

#d e f i n e M3 LOW

77#d e f i n e comp 8

#e n d i f

79#i f 1

#d e f i n e M1 HIGH

81#d e f i n e M2 HIGH

#d e f i n e M3 HIGH

83#d e f i n e comp 16

#e n d i f

85

(45)

87 i n t micro_comp = comp ;

// V a r i a b l e s f o r the motor d r i v e r

89

i n t stepCount = 0; // number o f s t e p s the motor has taken

91 i n t stp1 = 1 2, stp2 = 1 1, stp3 = 1 0; // connect pin to step i n t d i r1 = 9, d i r2 = 8, d i r3 = 7; // connect pin to d i r

93 f l o a t rb = 0 .1 1, rw = 0 .0 2 5; // r a d i e b o l l

f l o a t v_x = 0 .1, v_y = 0, w_bx, w_by, w_bz = 0;

95 f l o a t theta = 0 .5 2 3 5 9;

const i n t m = 3, p = 3, n = 1;

97

f l o a t T_1, T_2, T_3; // Tids konstanter som motorn v n t a r

99 f l o a t m1 = 0, m2 = 0, m3 = 0; // True e l l e r f a l s e

f l o a t w_1, w_2, w_3; // v a r v t a l t i l l resp motor ( rad / s )

101 f l o a t TIME_1 = 1, TIME_2 = 1, TIME_3 = 1; // t i d s g r e j e r f l o a t rpm_1, rpm_2, rpm_3; // rpm t i l l resp motor

103 f l o a t rps_1, rps_2, rps_3; // rps t i l l resp motor // f l o a t Vy=0; Vx=0; dt =0; AngleX

105

f l o a t delta_t , DT;

107 f l o a t delta_tOld = 0;

109

111 f l o a t pi = 3 .1 4;

i n t stepsPerRevolution = 3 6 0 / 1 .8;

113 unsigned long time , IMU_loop = 0, IMU_TIME ; i n t x = 0;

115 //End f o r v a r i a b l e s f o r motor d r i v e r

117 // V a r i a b l e s f o r IMU f l o a t lastGyroX = 0;

119 f l o a t AngleX_old = 0; /∗ IMU Data ∗/

121 double accX , accY , accZ ; double gyroX , gyroY , gyroZ ;

123 i n t1 6_t tempRaw ;

double Vx_0 = 0, Vy_0 = 0;

125 double Ax, Ay ;

double lastReadingX , lastReadingY ;

127

129 double gyroXangle , gyroYangle ; // Angle c a l c u l a t e using the gyro only double compAngleX , compAngleY ; // Calculated angle using a complementary

f i l t e r

131 double kalAngleX , kalAngleY ; // Calculated angle using a Kalman f i l t e r

133 uint3 2_t timer ;

uint8_t i2cData [1 4] ; // B uf fe r f o r I2C data

135

//End o f v a r i a b e l s f o r IMU

137

(46)

139 void setup ( ) {

S e r i a l . begin (1 1 5 2 0 0) ;

141 i n t AFS_SEL = 0; Wire . begin ( ) ;

143#i f ARDUINO >= 157

Wire . setClock (4 0 0 0 0 0UL) ; // Set I2C frequency to 400kHz

145#e l s e

TWBR = ( (F_CPU / 4 0 0 0 0 0UL) − 1 6) / 2; // Set I2C frequency to 400kHz

147#e n d i f

149 i2cData [0] = 7; // Set the sample r a t e to 1000Hz − 8kHz/(7+1) = 1000Hz i2cData [1] = 0x0 0; // Disable FSYNC and s e t 260 Hz Acc f i l t e r i n g , 256 Hz

Gyro f i l t e r i n g , 8 KHz sampling

151 i2cData [2] = 0x0 0; // Set Gyro F u l l S c a l e Range to 250deg / s i2cData [3] = 0x0 0; // Set Accelerometer F u l l S c a l e Range to 2g

153 while ( i2cWrite (0x1 9, i2cData , 4, f a l s e ) ) ; // Write to a l l f o u r r e g i s t e r s at once

while ( i2cWrite (0x6B, 0x0 1, true ) ) ; // PLL with X a x i s gyroscope r e f e r e n c e and d i s a b l e s l e e p mode

155

while ( i2cRead (0x7 5, i2cData , 1) ) ;

157 i f ( i2cData [0] != 0x6 8) { // Read "WHO_AM_I" r e g i s t e r S e r i a l . p r i n t (F(" Error reading s e n s o r ") ) ;

159 while (1) ; }

161

delay (1 0 0) ; // Wait f o r s e n s o r to s t a b i l i z e

163

/∗ Set kalman and gyro s t a r t i n g angle ∗/

165 while ( i2cRead (0x3B, i2cData , 6) ) ;

accX = ( i n t1 6_t) ( ( i2cData [0] << 8) | i2cData [1] ) ;

167 accY = ( i n t1 6_t) ( ( i2cData [2] << 8) | i2cData [3] ) ; accZ = ( i n t1 6_t) ( ( i2cData [4] << 8) | i2cData [5] ) ;

169

// Source : http : / /www. f r e e s c a l e . com/ f i l e s / s e n s o r s /doc/app_note/AN3461 . pdf eq . 25 and eq . 26

171 // atan2 outputs the value o f − to ( r a d i a n s ) − s e e http : / / en . wik ipedia . org / wiki /Atan2

// I t i s then converted from r a d i a n s to d e g r e e s

173#i f d e f RESTRICT_PITCH // Eq . 25 and 26

double r o l l = atan2( accY , accZ ) ∗ RAD_TO_DEG;

175 double p i t c h = atan(−accX / s q r t ( accY ∗ accY + accZ ∗ accZ ) ) ∗ RAD_TO_DEG

;

#e l s e // Eq . 28 and 29

177 double r o l l = atan ( accY / s q r t ( accX ∗ accX + accZ ∗ accZ ) ) ∗ RAD_TO_DEG;

double p i t c h = atan2(−accX , accZ ) ∗ RAD_TO_DEG;

179#e n d i f

181 kalmanX . setAngle ( r o l l ) ; // Set s t a r t i n g angle kalmanY . setAngle ( p i t c h ) ;

183 gyroXangle = r o l l ; gyroYangle = p i t c h ;

185 compAngleX = r o l l ; compAngleY = p i t c h ;

(47)

187

// I n i t the outputs f o r the motors

189 pinMode ( stp1, OUTPUT) ; pinMode ( d i r1, OUTPUT) ;

191 pinMode ( stp2, OUTPUT) ; pinMode ( d i r2, OUTPUT) ;

193 pinMode ( stp3, OUTPUT) ; pinMode ( d i r3, OUTPUT) ;

195 pinMode (3, OUTPUT) ; pinMode (4, OUTPUT) ;

197 pinMode (5, OUTPUT) ; d i g i t a l W r i t e (3, M1) ;

199 d i g i t a l W r i t e (4, M2) ; d i g i t a l W r i t e (5, M3) ;

201

203 timer = micros ( ) ;

205 time = micros ( ) ;

207

}

209

void loop ( ) {

211

213 i f ( micros ( ) >= IMU_loop) {

IMU_loop = micros ( ) + 3 0 0 0; //Loop every 2 m i l i sek

215

#i f 1 // Set to 1 to a c t i v a t e

217 /∗ Update a l l the v a l u e s ∗/

while ( i2cRead (0x3B, i2cData , 1 4) ) ;

219 accX = ( i n t1 6_t) ( ( i2cData [0] << 8) | i2cData [1] ) ; accY = ( i n t1 6_t) ( ( i2cData [2] << 8) | i2cData [3] ) ;

221 accZ = ( i n t1 6_t) ( ( i2cData [4] << 8) | i2cData [5] ) ; tempRaw = ( i n t1 6_t) ( ( i2cData [6] << 8) | i2cData [7] ) ;

223 gyroX = ( i n t1 6_t) ( ( i2cData [8] << 8) | i2cData [9] ) ; gyroY = ( i n t1 6_t) ( ( i2cData [1 0] << 8) | i2cData [1 1] ) ;

225 gyroZ = ( i n t1 6_t) ( ( i2cData [1 2] << 8) | i2cData [1 3] ) ; ;

#e n d i f

227

double dt = ( double ) ( micros ( ) − timer ) / 1 0 0 0 0 0 0; // C a l c u l a t e d e l t a time

229 timer = micros ( ) ; // time = micros ( ) ;

231

// Source : http : / /www. f r e e s c a l e . com/ f i l e s / s e n s o r s /doc/app_note/AN3461 . pdf eq . 25 and eq . 26

233 // atan2 outputs the value o f − to ( r a d i a n s ) − s e e http : / / en . wik ipedia . org / wiki /Atan2

// I t i s then converted from r a d i a n s to d e g r e e s

235#i f d e f RESTRICT_PITCH // Eq . 25 and 26

double r o l l = atan2( accY , accZ ) ∗ RAD_TO_DEG;

(48)

237 double p i t c h = atan(−accX / s q r t ( accY ∗ accY + accZ ∗ accZ ) ) ∗ RAD_TO_DEG;

#e l s e // Eq . 28 and 29

239 double r o l l = atan ( accY / s q r t ( accX ∗ accX + accZ ∗ accZ ) ) ∗ RAD_TO_DEG;

double p i t c h = atan2(−accX , accZ ) ∗ RAD_TO_DEG;

241#e n d i f

243 double gyroXrate = gyroX / 1 3 1 .0; // Convert to deg/ s double gyroYrate = gyroY / 1 3 1 .0; // Convert to deg/ s

245

#i f d e f RESTRICT_PITCH

247 // This f i x e s the t r a n s i t i o n problem when the a c c e l e r o m e t e r angle jumps between −180 and 180 d e g r e e s

i f ( ( r o l l < −9 0 && kalAngleX > 9 0) | | ( r o l l > 9 0 && kalAngleX < −9 0) ) {

249 kalmanX . setAngle ( r o l l ) ; compAngleX = r o l l ;

251 kalAngleX = r o l l ; gyroXangle = r o l l ;

253 } e l s e

kalAngleX = kalmanX . getAngle ( r o l l , gyroXrate , dt ) ; // C a l c u l a t e the angle using a Kalman f i l t e r

255

i f ( abs ( kalAngleX ) > 9 0)

257 gyroYrate = −gyroYrate ; // I n v e r t rate , so i t f i t s the r e s t r i c e d a c c e l e r o m e t e r reading

kalAngleY = kalmanY . getAngle ( pitch , gyroYrate , dt ) ;

259#e l s e

// This f i x e s the t r a n s i t i o n problem when the a c c e l e r o m e t e r angle jumps between −180 and 180 d e g r e e s

261 i f ( ( p i t c h < −9 0 && kalAngleY > 9 0) | | ( p i t c h > 9 0 && kalAngleY < −9 0) ) {kalmanY . setAngle ( p i t c h ) ;

263 compAngleY = p i t c h ; kalAngleY = p i t c h ;

265 gyroYangle = p i t c h ; } e l s e

267 kalAngleY = kalmanY . getAngle ( pitch , gyroYrate , dt ) ; // C a l c u l a t e the angle using a Kalman f i l t e r

269 i f ( abs ( kalAngleY ) > 9 0)

gyroXrate = −gyroXrate ; // I n v e r t rate , so i t f i t s the r e s t r i c e d a c c e l e r o m e t e r reading

271 kalAngleX = kalmanX . getAngle ( r o l l , gyroXrate , dt ) ; // C a l c u l a t e the angle using a Kalman f i l t e r

#e n d i f

273

gyroXangle += gyroXrate ∗ dt ; // C a l c u l a t e gyro angle without any f i l t e r

275 gyroYangle += gyroYrate ∗ dt ;

// gyroXangle += kalmanX . getRate ( ) ∗ dt ; // C a l c u l a t e gyro angle using the unbiased r a t e

277 // gyroYangle += kalmanY . getRate ( ) ∗ dt ;

(49)

279 compAngleX = 0 .9 3 ∗ ( compAngleX + gyroXrate ∗ dt ) + 0 .0 7 ∗ r o l l ; //

C a l c u l a t e the angle using a Complimentary f i l t e r

compAngleY = 0 .9 3 ∗ ( compAngleY + gyroYrate ∗ dt ) + 0 .0 7 ∗ p i t c h ;

281

// Reset the gyro angle when i t has d r i f t e d to much

283 i f ( gyroXangle < −1 8 0 | | gyroXangle > 1 8 0) gyroXangle = kalAngleX ;

285 i f ( gyroYangle < −1 8 0 | | gyroYangle > 1 8 0) gyroYangle = kalAngleY ;

287

// C a l i b r a t e the angle

289 f l o a t AngleY = kalAngleY ; f l o a t AngleX = −kalAngleX ;

291

// C a l c u l a t i n g the a c c e l e r a t i o n whit a f i l t e r

293

double readAccelerationX = accX ;

295 double readAccelerationY = accY ;

297 double alpha = 0 .1;

299 double acc_X = alpha ∗ readAccelerationX + (1 alpha ) ∗ lastReadingX ; double acc_Y = alpha ∗ readAccelerationY + (1 alpha ) ∗ lastReadingY ;

301 // S e t t i n g v a r i b l e s to l a t e s t v a l u e s lastReadingX = accX ;

303 lastReadingY = accY ;

305 f l o a t AngleX_new = AngleX ;

f l o a t w_x = ( AngleX_new − AngleX_old ) / dt ;

307 AngleX_old = AngleX ;

309 f l o a t Ax_no_filter = accX / 1 6 3 8 4; Ax = acc_X / 1 6 3 8 4;

311 Ay = (acc_Y / 1 6 3 8 4) ;

f l o a t Ay_cal = Ay − s i n ( AngleX ∗ 0 .0 1 7 4 5 3 2 9 2 5) ;

313 f l o a t Ax_cal = Ax + s i n ( AngleY ∗ 0 .0 1 7 4 5 3 2 9 2 5) ; // V e l o c i t y

315 double Vx = Vx_0 + Ax_cal ∗ dt ; Vx_0 = Vx ;

317 double Vy = Vy_0 + Ay_cal ∗ dt ; Vy_0 = Vy ;

319

321

323 X = x_old + (1 0 0 ∗ Vy) / 1 1 ∗ dt ; Y = y_old − (1 0 0 ∗ Vx) / 1 1 ∗ dt ;

325

327

ax = K_A ∗ AngleX + K_AV ∗ gyroXrate + K_T ∗ (X − x_0) + K_V ∗ Vx ;

329 ay = K_A ∗ AngleY + K_AV ∗ gyroYrate + K_T ∗ (Y − y_0) + K_V ∗ Vy ;

331 x_old = X;

(50)

y_old = Y;

333

delta_t = micros ( ) ;

335 DT = ( delta_t − delta_tOld ) / 1 0 0 0 0 0 0; delta_tOld = delta_t ;

337

w_1 = −ay ∗ DT;

339 w_2 = ( ( s q r t (3) / 2) ∗ ( ax ∗ DT) + (0 .5 ∗ ay ∗ DT) ) ∗ cos (3 0 0 .0 1 7 4 5 3 2 9 2 5) ;

w_3 = ((− s q r t (3) / 2) ∗ ( ax ∗ DT) + (0 .5 ∗ ay ∗ DT) ) ∗ cos (3 0 0 .0 1 7 4 5 3 2 9 2 5) ;

341

343

w_1 = w_1 ∗ micro_comp ;

345 w_2 = w_2 ∗ micro_comp ; w_3 = w_3 ∗ micro_comp ;

347

349

351 }

motor_1( time , w_1) ;

353 motor_2( time , w_2) ; motor_3( time , w_3) ;

355

}

357

359

void motor_1( unsigned long time , f l o a t w_1) {

361

// d e c i d e s the d i r e c t i o n f o r the motor1

363 i f (w_1 < 0) {

d i g i t a l W r i t e ( d i r1, LOW) ;

365 }

i f (w_1 > 0) {

367 d i g i t a l W r i t e ( d i r1, HIGH) ; }

369 // d e c i d e s the speed f o r the motor1 rpm_1 = abs (w_1) ∗ 9 .5 4 9 2;

371 rps_1 = rpm_1 / 6 0;

T_1 = 1 0 0 0 0 0 0 / (4 0 0 ∗ rps_1) ;

373

375

377

i f ( ( micros ( ) >= TIME_1) && (m1 == 1) ) {

379 d i g i t a l W r i t e ( stp1, HIGH) ; TIME_1 = TIME_1 + T_1;

381 m1 = 0;

383 }

(51)

385 i f ( ( micros ( ) >= TIME_1) && (m1 == 0) ) { d i g i t a l W r i t e ( stp1, LOW) ;

387 TIME_1 = TIME_1 + T_1; m1 = 1;

389 }

391

}

393

void motor_2( unsigned long time , f l o a t w_2) {

395

// d e c i d e s the d i r e c t i o n f o r the motor2

397 i f (w_2 < 0) {

d i g i t a l W r i t e ( d i r2, LOW) ;

399 }

i f (w_2 > 0) {

401 d i g i t a l W r i t e ( d i r2, HIGH) ; }

403 // d e c i d e s the speed f o r the motor2 rpm_2 = abs (w_2) ∗ 9 .5 4 9 2;

405 rps_2 = rpm_2 / 6 0;

T_2 = 1 0 0 0 0 0 0 / (4 0 0 ∗ rps_2) ; // 1/(200∗ rps ) ∗1000;

407

409

411 i f ( ( micros ( ) >= TIME_2) && (m2 == 1) ) {

413 // S e r i a l . p r i n t l n (T_1) ; d i g i t a l W r i t e ( stp2, HIGH) ;

415 TIME_2 = TIME_2 + T_2; m2 = 0;

417 }

419 i f ( ( micros ( ) >= TIME_2) && (m2 == 0) ) { d i g i t a l W r i t e ( stp2, LOW) ;

421 TIME_2 = TIME_2 + T_2; m2 = 1;

423 }

425 }

427 void motor_3( unsigned long time , f l o a t w_3) {

429 // d e c i d e s the d i r e c t i o n f o r the motor3 i f (w_3 < 0) {

431 d i g i t a l W r i t e ( d i r3, LOW) ; }

433 i f (w_3 > 0) {

d i g i t a l W r i t e ( d i r3, HIGH) ;

435 }

// d e c i d e s the speed f o r the motor3

437 rpm_3 = abs (w_3) ∗ 9 .5 4 9 2;

References

Related documents

Case concerning Military and Paramilitary activities in and against Nicaragua (Nicaragua v.United States of America), I.C.J, Judgment 27 June 1986 and Barcelona Traction, Light

Previous research has shown that unemployment is followed by lowered levels of subjective well-being and life-satisfaction (Clark and Oswald, 1994, Korpi, 1997). Yet,

In sum, EC is increasing its power as a foreign policy actor; the annual amount of foreign aid is increasing in a stumbling pace; the foreign aid is seen

When first being presented the objects at Skokloster, three things immediately struck me. First, why is it called Wrangels fältservis? It doesn’t particularly look like

One of the biggest projects within the Dialogue process was the so-called parallel city analyses, during the autumn of 2005 six crews worked to create six different visions of

The MNC was selected strategically in order to achieve an interesting case study, due to the assumed opportunities the white- collar workers have in relation to building a

Even though scholars argue that the specificity of sport presented above requires traditional management accounting practices to adapt to these contingencies (Hoye, 2008),

The notion of employment support, or activation, is interesting as it simultaneously reflects conceptions that are deeply rooted in the historic legacy of different states of