So for my final year project I had to convert the signals from an accelerometer to displacements for a movement of a few millimetres and I decided to write about my experiences(mainly problems) doing this. I can’t say exactly what the device was as it was built for a research group but I’m going to go through the theory involved with getting displacements from an accelerometer. I’ll be making a few posts to cover the different topics. If You came here from the YouTube video and want to see the code you can jump to the third post. The movement I was measuring involved the sensor moving forward/backwards and upward/downward as well as the sensor tilting forward and backwards. The sensor used was an MPU-9150 which has 9 degrees of freedom(DOF), only the accelerometer and gyroscope were used in this application(3DOF each), a diagram of the axes can be seen below. So because accelerometers measure acceleration due to gravity this would have to be canceled to isolate the acceleration caused by the movement, this wouldn’t be too difficult if all 3 axes from the accelerometer and gyro were being recorded, using some 3d vector and trig calculations this could be done easily enough but a problem I faced was having a fixed sample rate and other sensors which had to be recorded alongside the ACC and gyro, this meant that only the necessary axes from these two could be recorded. Continue reading
For my mini project I wanted to make something that would move a around webcam to keep an object in the center of the screen. To do this I used two servos to change the x and y axis orientation of the webcam but before I got to attaching the webcam I needed to learn how to find objects and isolate them from a webcam, to do I used OpenCV and Python. The first program I made was to read in the feed from a webcam and display the normal feed, the hue, saturation and value(hsv) for the feed isolating the colour was looking for and Continue reading
The next motor I worked on was the stepper motor which works by turning on multiple coils in a sequence to turn the motor. The code I started with used bit banging to rotate the stepper in one direction at one speed. This code can be found here. First thing I did with this code was to have it react to a sensor, in this case a light dependent resistor(LDR), the LDR used was the NORP12 RS. Using two LDRs and the analog digital converter(ADC) to have the stepper to point in the direction of a light source, the LDRs would be mounted on the stepper so if one LDR was reading more light the stepper would move in that direction until the two LDRs were were reading the same amount of light. The code is shown below:
This week I worked on controlling a DC motor using the pulse width modulation (PWM) in the dsPIC30F4011 to adjust the speed of the motor. The code I started with would drive the motor at 75% duty cycle for two seconds then 25% for two seconds and repeat, this code can be found here. The DC motor pulls a lot more current than the PIC can supply so I needed to use a driver chip (SN754410NE), This chip would amplify the current enough to drive the motor. On this chip we can apply the PWM to the enable pin on either side giving us the ability to switch the chip on and off very quickly and this turns on and off the motors, this switching will then change the speed. If the enable pins were left alone the motor would just run at full speed. Continue reading
In my first lab we were getting a feel for the dsPIC30F4011 micro controller which we haven’t used before, we have used the MSP430 chip before and they work fairly similarly, just need to learn the names of the functions like P1DIR is like TRISD in the PIC. The way we’re doing this is by writing a code to control a servo, we’ll be controlling the servo using the bit banging method which is switching an output on and off creating certain length pulses. Using the pulse width modulation in the chip would be better but doing bit banging will help use get used to the __delay32.
We start with a code given to us by our lecturer which would switch from 0 degrees to 180 degrees but when I tested it, it didn’t look like it was going the full 180 degrees so I decided to change the pulse on top and bottom of the range to find the real values for 0 and 180 degrees. The datasheet suggests the values around 1ms to 2ms for the full range but from trial and error I found to get the full range of angles, the pulse range is 0.7ms to 2.2ms. The circuit and the final code for switching between 0 and 180 degrees is below, the code was edited from here. Continue reading