Capacitive Sensing Robot Arm Using Pic

copper foil

Introduction

For our final project, we built a 2 axis robot arm with a capacitive sensor on the final member, which will allow the robot to detect a person near the robot. When there is an object detected, the arm will stop depending on the measured capacitance. The purpose of this type of sensor is to allow robots and humans to work in the environment safely. Functionally, this product will allow a user to move around the robot arm with potentiometers to complete a task as desired. In addition to that, the user can work alongside the robot with the risk of injury mitigated by the capacitance sensor on the robot.

High level Design

The overall design of this project is broken up into three interconnected parts: the mechanical robot
arm, electrical hardware including the capacitive sensor, and the software which runs on the PIC32.
The robot design is based on using servo motors connected directly together via 3d printed parts.
Each of the servois controlled by a PWM signal from the PIC32 processor. Each joint has a corresponding
potentiometer with a current-limiting resistor that the user can use to control the position of the arm.
To do this, we used the on-board ADC to determine the current potential of the potentiometer. From there
we converted it to a % duty cycle to control the servo motor position.

For the capacitive sensor portion, we used copper foil surrounding the arm (a rod) that acts as a very simple
capacitor. We have a function to measure the capacitance of the foil by charging it and measuring the voltage
through ADC. The CTMU charges the foil for certain amount of time with pre-set current so we have the charge.
Then we can calculate the Capacitance using the formula C = q/v. After reading the capacitance, we use a software low pass filter to give us a steady and accurate reading with minimal gitter. If the change in capacitance is over a certain threshold, that indicates a person has gotten very close to the robot. Once this occurs, the robot arm stops all movement until the user has moved away and the capacitance reading is back to its original reading. One of the difficulties in this process is that different environments and robot positions lead to a different nominal capacitance which makes tuning of our system difficult but vital to our project’s success.

On the hardware side, one of the biggest trade offs we made was due to our limited time and budget constraints.
The robot arm is less aesthetically pleasing than we would have liked, but we wanted to focus our efforts on the novelty of using capacitance on a robot arm to sense a person. Additionally we used cheap servo motors, which worked well for our application, but do not have as smooth operation as it would be for a final product.

In designing the capacitive sensor, we brainstormed a few ideas and made various prototypes. The first full-scale prototype we created involved a network of intertwining lines that were separated by a small gap to keep the two circuits separate. In this design, we would use a more traditional-looking capacitor where one end is the anode and the other the cathode as seen below.copper foil

Fig.1 – copper foil with pattern

We had great success with this prototype where we were able to get clear and consistent readings. Below is a table of our test on this design.

Distance

ADC Reading(low pass version)

from 0 to 1023

Far Away

124-128

touching(cupping)

26-30

1cm flat

108-111

2cm flat

111-115

3cm flat

114-119

0.5cm flat

102-104

0.1 flat

94-99

1cm cupping

101-102

2cm cupping

104-107

3cm cupping

111-115

0.5cm cupping

93-97

0.1cm cupping

79-83

Although we were able to clearly read the capacitance change, we thought we could do better. Our final design was ironically our first idea and also the simplest of all the designs. This design consists of a single strip of copper foil wrapped around the arm as seen below. We believe this is the best design due to its large surface area since capacitance is linearly proportional to surface area.Plain copper foil

Fig.2 – Plain copper foil

We again tested this with the same type of tests with the following results:

Distance

ADC Reading (low passed version)

from 0 to 1023

Far Away

101- 105

Touching (cupping)

43 – 46

1cm

91-95

2cm

96-100

3

99-102

.5

90-92

.1

80-83

1cm cupping

88-90

2cm cuping

93-96

3cm cup

94-99

.5 cup

82-85

.1 cup

78-82

When comparing the two final designs, it is clear that the single copper foil design has a greater change in
capacitance with a hand near it. With this knowledge in hand, we were able to focus on the software component of this project.

Hardware Design

3d printed parts

Our physical design consists of two servo motors with 180 degrees of rotation connected together to make a simple arm with two degrees of freedom. The base motor is mounted with a 3D printed part onto a piece of 2×6 wood which serves as a base to keep the arm in place. Connected to the base servo is another 3D printed mount which connects to the second servo motor. Finally, a final mount connects the second servo to the arm which is simply a piece of carbon fiber tubing. Below is a diagram of the robot arm made.2 Axis Robot Arm

Fig.3 – Rendered Image of 2 Axis Robot Arm in Autodesk Inventor

Each of the pieces that were 3D printed were made using Autodesk Inventor. The design for this was to be as simple and effective as possible while using minimal material. The bottom piece has four slots for wood screws to mount the piece to the wood base in addition to 2 5mm holes to place threaded heat set inserts for M3 screws. Each part made has these slots which allows us to easily attach the pieces to the motors and the carbon tube.The image above shows the design as rendered which we did before building the prototype.

Hardware Components Overview

Prototyping Board

In addition to the robot arm hardware, we also designed a simple soldered prototyping board which allows us to easily connect and disconnect the PIC32, motors, and power supply. Additionally, it made the control of the robot very clean and consistent without any possible loose wires.prototyping board

Fig.4 – prototyping board

As shown in the diagram, the user uses the two potentiometers on the bottom to control the position of each joint of the robot. The power to the system is provided by a power supply connected by the screw terminals on the right side. Additionally, a 3.3V power line is attached near the potentiometers to allow the ADC to read the potentiometers as seen in the center of the board. The user connects the two PWM outputs from the PIC32 to the board directly. Finally each motor connects easily to this board completing all of the circuitry.protoboard

Fig.5 – Image of wiring of the protoboard

The figure above depicts the wiring of the protoboard described earlier. Each of the potentiometer are connected to the 3.3V line and ground via a 330 Ohm pull down resistor to ensure there are no current spikes which could damage the PIC32 board. Aside from this, the rest of the wires are just basic connectors making sure all of the headers have power as needed.

Software Design

Software Low Pass Filter

We defined alpha = 0.98 at the start of our program to filter out high frequency noise of two ADCs. Another reason of such high ratio would be explained in the CTMU section. Using the formula signal = alpha * oldsignal + (1- alpha ) * newsignal, any signal can be effectively low-passed using software. We use the same low pass formula to low pass CTMU but with alpha set to 0.9 since we want a faster response to the proximity.

image1

CTMU

The CTMU(charge time measuring unit) module is the heart of our project. The CTMU act as a current source: it would first discharge the foil, then charge the copper foil for 2 microseconds with 5.5uA. And finally measure the voltage on the foil. The CTMU offers four options of current: 0.55uA, 5.5uA, 55uA and 550uA. By experimenting with our copper foil and referring from the final ADC value, we found that 0.55uA would be too small: the final ADC reading is around minimum. 55uA and 550uA would be too large: they always gave us a reading of maximum. To approximate the 2 uS charging time, we used the code from captain Bruce.CTMU

CTMU would work with only one analog pin connected to the foil. We don’t have many analog pin available to use because of the TFT screen.  The analog pin we chose was AN5, corresponding to the RPB3 on the big board.

Now with ADC value, we can calculate the final capacitance.ADC value

However, when we were writing the code to detect human proximity, we found that using capacitance for proximity detection was redundant since capacitance was derived from ADC reading. Working on ADC directly would be more efficient.

We tried different approaches for detecting human proximity. The most naive way of doing it would be setting a threshold: under which would be a catch. Then we just stopped reading ADCs values from potentiometers and it would stop the arm. This method face one problem: the capacitance of the foil was unstable even after low passing. We also observed that we achieve the highest ADC reading when the arm was vertical to the table (around 100) and lowest when the arm was parallel to the table(around 90). The problem may come from the distance between arm and table would alter the capacitance. If we set the threshold too high, moving toward table would stop the arm. If we set the threshold too low, it might be too late for the arm to stop.

To avoid the above problem, we tried detecting the proximity with a derivative term. By recording differences of a series of low passed ADC readings. If several consecutive negative results were detected, it mean human proximity. However we never got this method to work by tweaking around the parameters. The problem may come from the fact that the thread was running so quickly that the number of readings we recorded was too small.

But then we realized that the biggest problem we need to solve was that the arm was moving too quick and it might be the reason that we couldn’t stop it before. After a discussion of how to make arm move slower, we came up with different ideas like moving the arm to destination in steps but eventually we found that we can slow the motion of the arm just by simply low pass ADC readings with high alpha value.

After slowing down the motion by setting alpha from 0.8 to 0.98, the problem we had that the capacitance of the robot arm was changing with its position also disappeared. It might be due to the reason that the speed of the arm slowed from an instant moving to a several seconds process. Then we tested the arm with naive threshold approach and it worked with both of our hands.  When the CTMU get an ADC reading below the threshold, we set a variable ‘prox’ to 1 which mean human proximity detected. Two ADC readings for PWM controls would always check ‘prox’ value first and proceed if its 0.CTMU block diagram

PWM

We used pulse width modululus to control the position and speed of the servo motors in our system. The motor we used in the project has a pulse period of 20ms. And duty ratio from 0.5ms to 2.5ms. We had the timer2 running at 40Mhz. In order to get a pulse period of 20ms, we need 800000 counts for each period. By setting prescaler to 256, we got a range of 800000/256 = 3125 range of duty cycle. Since the duty ratio should be 0.5ms to 2.5ms. The corresponding duty we should set should be from lowest: 3125/40 ~= 78 to highest 3125/8 ~= 390. The formula we used in the code was:PWM

The image above shows the two PWM signals running simultaneously with the top signal being at 2.5ms and the lower at .5ms. Both of the pulse widths are significantly smaller than the major period of 20ms.

TFT

We displayed all the ADC readings and calculated capacitance to the TFT screen.TFT

ADC

Initially we were trying to make 3 motors work at the same time but we found out that we only have 3 analog pins left that we can use on the big board since we were using TFT screen. One is needed for CTMU so we can only have 2 analog pins left for PWM control. Two analog pins we chose for ADC readings were AN9 and AN11, corresponding to RPB13 and RPB 15. Since we have 3 ADCs, we could not do it with sampleA and sample B. We also tried scan mode and it didn’t work either. We chose manual mode eventually, for every ADC reading, we set the channel to that pin, acquire, convert, and read. The final parameters for enabling ADC was like this:ADC

Note that we might make a mistake that we were doing 3 samples instead of 1 by setting ADC_SAMPLES_PER_INT_3. Which may lead to the biggest problem in our project.

Compiling it Together

We wrote everything in one thread in the final version of the project. However, we wrote two ADC readings and CTMU in 3 different threads. For this version, we have many yield through out each thread. It worked fine initially and displayed 3 ADC values correctly  but when we tried to make any change to the code, for example: changing how many ms to yield in any yield command, or changing the size of text to print on TFT, would make the ADC reading for CTMU not valid at all. The ADC reading went from 0 to 1023 randomly. However, the ADC readings for PWM controls worked well as usual. Due to that factor, we believe that the charging time of the CTMU might be different due to yielding to the other threads. But since the thread was not pre-emptive,we questioned how the scheduler was involved during the charging.   We tried many different approaches and spent days to solve this issue. But we couldn’t find a solution while using multithread. Then we consulted with Captain Bruce who gave us the advice that we might want to remove all the yield and write everything in one thread to solve this issue. We rewrote everything in one thread and it worked.

The final version consists of 2 functioning thread: One timer thread that only updates the time on TFT. Another main thread that do all the work: First, check the variable ‘prox’, if 0, then perform two ADC readings and convert to PWM signals. If 1, then skip this step. Then we discharge the foil, charge it and measure the ADC. From there we can set the ‘prox’ and calculate capacitance. Finally we printed all information on TFT screen.

Design Result

The motion of the robot is very smooth after our extensive low passing of the ADC value to control the speed. Additionally, since we have all of the calculations in one thread, the reading of the capacitance is extremely fast. We sadly were not able to get an exact number on the speed of the readings, but imagine it is in the range of 300-1000 readings per second.  We noticed that after our extensive tuning, when we move the robot near our body, the arm constantly is able to stop  before hitting our hand! We tested this out at two seperate locations and with the arm at different positions and our product continued to work. The only time where we noticed an issue is if we move just a finger in front of the arm. Occasionally the robot would bump into our finger, but once it makes contact, it halts. This is due to the low surface area of our finger compared to an arm or hand.

Interference Concerns

Our design only contains ADC, PWM and CTMU; Since none of those functions cause any high frequency noise, our system will be interference free for other people and devices in the area.

Conclusion

Overall we were able to meet all of our major objectives in creating this robot arm which has fairly fluid motion while detecting and stopping when there is a human in the way of its movement. We were very happy with how we were able to create the sensing part of this even though neither of us had used the CTMU or implemented capativie sensing before. Although we were not able to build the system using three joints, the main outcome was to get the sensing working well and in the future we or others can join this technology with a higher DOF robot arm or system.

If we had to complete this project again knowing what we know now, we would make a few changes with the system. The first would be to take more time with the design of the arm and it’s housing. Although the arm works as expected, it is not aesthetically pleasing to look at or watch move around. We focused a lot on the capacitive sensing and were worried that we might run out of time if we were to design a good-looking arm. Additionally, another thing we would have liked to add is a joystick-like controller instead of an open PCB board with a bunch of wires coming off of them.

There are many more possibilities that we haven’t explored yet. Such as by calculating the direction of the human proximity, the robot can either follow the object, or move away from the object. To do this, we might need multiple foils on different robot locations while keeping tracking which direction the robot is moving.

On the software side we wrote all of our own code besides some setup code taken from Bruce Land’s headers and from previous labs which we completed. Although the idea of capacitive sensing is not a new or novel idea, with a little more work on the tuning of the system, it would be possible for us to publish our work. Currently, we do not have plans to do so, but are both open to it if we have time early next semester.

Safety Considerations

Since safety was the primary objective in creating an active sensing arm, we were sure that the construction and operation of the arm is safe. Each component runs on 5V which is safe to handle by any user. Additionally since the robot arm is able to sense if a person is near, our product is able to avoid any major collisions that could cause any harm to anyone.

Ethical Considerations

To our knowledge, our project is consistent with the IEEE code of ethics and have satisfied all 10 articles as detailed on the IEEE website.

SchematicsSchematics 2

Leave a Comment

Your email address will not be published. Required fields are marked *