Difference between revisions of "Robot Drummer"

From Mech
Jump to navigationJump to search
Line 104: Line 104:
====Master Overview====
====Master Overview====
If the master PIC senses data being pushed to serial buffer, it reads the incoming data. The appropriate function in Robot_Drummer_MotorController.c is called, which sends a command to a slave. If data was requested, the master writes it back to Matlab.
If the master PIC senses data being pushed to serial buffer, it reads the incoming data. The appropriate function in Robot_Drummer_MotorController.c is called, which sends a command to a slave. If data was requested, the master writes it back to Matlab.

<table border=1>
<tr><th>Master PIC C Command Format</th><th>Purpose</th><th>Example</th><th>Example's Outcome</th>
<tr><td>set_mc_position(device,number)</td><td>Sets the desired position of the motor</td><td>set_mc_position(0x80,5000)</td><td>Will set slave #0 motor's position to 5000</td>
<tr><td>mc_get_position(device)</td><td>Gets the position of the motor</td><td>position = mc_get_position(0x80)</td><td>Will get slave #0 motor's current position</td>
<tr><td>mc_resetpos(device)</td><td>Sets the current position of the motor to zero</td><td>mc_resetpos(0x80)</td><td>Will sett slave #0 motor's current position to zero</td>
<tr><td>mc_pos(device)</td><td>Sets slave to position tracking</td><td>mc_pos(0x80)</td><td>Will put slave #0 in position tracking mode</td>
<tr><td>mc_go()</td><td>Begins actions on all slave. Note that mc_go() must be sent before the action is carried out</td><td>mc_go()</td><td>Will tell slave to run previous commands</td>
</table>


====Communication====
====Communication====

Revision as of 20:08, 19 March 2009

ME_333_final_projects

Team Members

Niecestro-Lee-By
  • Bobby By: Senior in Electrical Engineering
  • Agatha Lee: Master Student in Biomedical Engineering
  • Dan Niecestro: Senior in Mechanical Engineering


Overview

The goal of this project was to create a high speed motor controller which can be tuned through MATLAB so that anyone could take a couple motors and a few dollars worth of hardward and implement accurate high-speed encoder-based feedback control. MATLAB sends commands via RS232 serial connection to a "master" PIC which in turn communicates with a number of "slave" PICs to initiate motor control. To demonstrate this, the Robot Drummer was created.

Mechanical Design

Mechanical Overview

In this project, we were asked to present motor control of two separate motors running simultaneously. It was thought that a simple way to visually demonstrate motor control and be aesthetically pleasing was to make a small drum set.

Robot Drummer

This drum set consisted of a base, a drum pad and two drum sticks. All the parts were manufactured in the Northwestern machine shop, with materials supplied. The motors are removable and can be switched by loosening the brackets that hold them down. One of the main considerations was reusability of the motors and this setup allows easy removal or switching of motors from our device.

Base

The base was made in a U shape; this was done to allow the motors to hang over the insides and share the same drum pad, as seen above. Also, small legs were planted under the base so that when the motor rotated, the drumsticks would not hit the surface underneath. Both the legs and the main base was made of wood. Cardboard was placed over the base for aesthetic reasons

Securing Motor to Base

The motors were secured to the base using two brackets. The first bracket went around the circular part of our motor to hold the motor down and prevent side-to-side movement. Next, around the square part, a small, thin bracket was used to prevent the motor from moving up and down and slipping. Both brackets were set in place using screws to allow the bracket to open and close with ease. After securing it in place, the motors did not move at all and proved to be very secure.

Drum Pad

The drum pad is elevated off the base to allow the ends of the drumstick to hit it without hitting the base. Like the base, the drum pad is made of wood; it was then was covered in a thick poster/foam board material to dampen the sound since the metal hitting the wood was rather loud. This also gave the look of a drum pad. The number 13 was put on the pad represents our team number.

Drum Sticks

This was the most intensive part to make--there was a large number of trials and different ways of creating them. It was decided that the drum sticks should be made as light as possible to ensure that the motor could support it, therefore aluminum sheet metal was used. Basically, two L beams were made mirrored of each other and one hole was drilled for a screw on each side at the base of each beam. This was to connect to another small beam to go on the other side which will make a simple collet and a nice force fit on the shaft of the motor. To connect the two L beams together, rivets had to be used as spot welding aluminum is not very effective. Only three rivets were placed on the beam because a small circular rod of aluminum was added at the end of the beam. The beam had to open up and the rod was place in the middle, where two holes were drilled to prevent the rod from moving. Lastly, we wrapped it in a yellow glossy paper to make them look more like drumsticks; however, these coverings are not exactly round because it had to attach to the beam itself, which isn’t round. The result showed that it created a very nice force fit which had very little to no slipping on the motor shaft.

Electrical Design

Component List

PartPart No.Qty
PIC18F4520 Prototyping Board---3
Microchip 8-bit PIC MicrocontrollerPIC18F45201
Microchip 8-bit PIC MicrocontrollerPIC18F44312
RS232 CableTTL-232R1
Pittman Motor with EncoderGM82242
Hex Inverter ChipSN74HC041
H-Bridge ChipL293D2
10K Resistor---2

Setup

All of the components, except the Pittman motors, were powered with 5V DC. The Pittman motors were powered with 12V DC.

PICs

Two kinds of PICs were used: one "master" 18F4520 and two "slaves" 18F4431. The 18F4431 has a built in quadrature encoder, which makes it very useful for encoder-based motor control. This eliminates the need of a counter chip, such as a LS7083 used in the original I2C motor control circuit. The three PICs communicated via I2C. I2C communication requires 2 connections: clock(SCL) and data(SDA). The SCL line and SDA line were connected from pin 18 and pin 23 of the master PIC to pin 24 and pin 23 of all slave PICs, respectively. Note that the SCL and SDA lines needed a 10 Kohm pull-up resistor. There is also a "Go" signal from pin 7 of the master to pin 18 of the slave PICs.

RS232

The TTL-232R has six color-coded wires, but only 3 were required with this project. The black GROUND wire was connected to PIC ground, the orange Tx wire was connected to pin 26 of the master PIC and the yellow Rx wire was connected to pin 25 of the master PIC.

H-Bridge

The slave PICs send an individual PWM to a L293D H-bridge. This PWM determines the speed of each motor. The motor is at rest at a 50% duty cycle and is at its maximum speed at 0 and 100% duty cycles. Pin 16 of the slave PICs was connected to pin 2 of a L293D. The H-bridge needed to be powered with +12V on pin 8, +5V on pin 1 and grounded on pins 4 and 5. Pin 16 was also powered with +5V and pins 12 and 13 were grounded to minimize noise.

Hex Inverter

Pin 16 of the slave PICs was also run through the hex inverter chip (pin 1 or pin 13). The output of the hex inverter (pin 2 or pin 12) was sent to pin 7 of a L293D. Pin 14 was powered with +5V and pin 7 was grounded.

Pittman Motors

The positive end and negative end of the Pittman motor were connected to pin 6 and pin 3 of the H-bridge, respectively. Encoder A of the Pittman motor was connected to pin 6 of the slave PICs, while encoder B was connected to pin 5.

Schematic

Robot Drummer Schematic


Programming

Programming Overview

Three sets of code were required for our project: the MATLAB code, C code for the master PIC, and C code for the slave PICs. The MATLAB code sends commands to the master PIC. The master PIC code read all the serial communication from MATLAB and converted it into appropriate I2C commands for the slave PICs, which were completely dedicated to motor control and encoding.

Matlab

Matlab Code

Robot_Drummer_Matlab.zip

This zip file contains all the Matlab functions needed, as well as two sample code files.

Matlab Overview

The following table outlines the commands that can be sent from Matlab. (This is a summary of MATLAB functions as written by Matt Turpin in his I2C Motor Control project.)

Matlab FunctionPurposeCommand FormatExampleExample's Outcome
MotorControllerConnect.mEnables communication between Matlab and the master PICserial object = MotorControllerConnect(serial port number)s = MotorControllerConnect(6)Will connect the master and Matlab through COM port 6
mc_resetpos.mResets the current position to zeromc_reset_pos(device,serial object)mc_reset_pos(0,s)Will reset slave #0 motor's current position to zero
set_mc_position.mSets the desired positionset_mc_position(position,device,serial object)set_mc_position(5000,0,s)Will set slave #0 motor's current position to 5000
mc_get_position.mGets the current positionposition = mc_get_position(device,serial object)position = mc_get_position(0,s)Will get slave #0 motor's current position

Master

Master Code

Robot_Drummer_Master.c
Robot_Drummer_MotorControllerFunctions.c

There are two files related to the master PIC. Robot_Drummer_Master.c is the file that needs to be put on the master PIC. Robot_Drummer_MotorConntrollerFunctions.c should be put in the same directory as Robot_Drummer_Master.c.

Master Overview

If the master PIC senses data being pushed to serial buffer, it reads the incoming data. The appropriate function in Robot_Drummer_MotorController.c is called, which sends a command to a slave. If data was requested, the master writes it back to Matlab.

Communication

The master PIC can be used in two ways. First, it can receive commands from Matlab through the RS232 cable and then send it to a slave PIC. The second method of communication is the master PIC can directly send commands to a slave PIC without having Matlab involved.

Slave

Slave Code

There is one file related to each slave PIC.

Slave Overview

Control

Each slave contains a PID control algorithm with hard-coded control gains to drive the motor to the desired position.

Slave Addressing

The following table shows the 16 preset addresses. The device numbers are used in the Matlab commands, while the Hex I2C addresses need to be defined twice inthe slave code (in the top and in setup()).

Device NumberHex I2C Address
080
182
284
386
488
58A
68C
78E
890
992
1094
1196
1298
139A
149C
159E

Relflections

Objectives Met

Overall, we are pleased with the progress we've made in the relatively short amount of time. We believe this project will be of great use to others. We were able to meet the following objectives:

  • Make it easy for anyone to do high-speed encoder-based feedback control of brushed DC motors cheaply.
  • The master PIC is consistently able to receive commands from Matlab using the RS232 cable.
  • The master PIC is consistently able to communicate the commands back to the slave PICs using I2C.
  • Learn about and take advantage of the 18F4431's built-in quad encoder.
  • The slave PICs implement PID control.
  • Upon request, data can be sent from the slave PICs back to Matlab.

Problems Encountered

At first, we encountered a lot of trouble with the RS232 communication, the I2C communication and motor control. We spent a lot of time inefficiently, but eventually developed a plan that helped us solve our problems. For those trying to recreate this project, it may be useful to build each part separately and then combine them. We found the debugging strategy below to be useful.

Debuggging Strategy

Test RS232

In order to test the RS232, connect the RS232 cable to the appropiate pins of the master PIC (see Electrical Design). To see that the master PIC can receive data from the RS232, send a desired position from Matlab and turn on some LEDs or output the position on the d register in the master PIC code. The following code in the master PIC's Robot_Drummer_MotorControllerFunctions.c will do this.

void set_mc_pos(int device,  int32 position)
{
   int* output[5] = {0,0,0,0,0};
   int ii;
   output_d(position);
   output[0] = 2;
   for(ii=0;ii<2;ii++)
   {
      output[ii+1] = (int8)(position>>(8*(ii)));
   }
   mc_transmit(device,output);
}
Test I2C

In the master PIC code, instead of waiting to receive commands from Matlab, commands can be sent directly to a slave PIC. For example, the following code can be used in the main loop to send a desired position.

set_mc_pos(0x80,5000);
mc_go();

It may also be useful to turn on LEDs to see that the master is transmitting data and/or the slave is receiving data.

Test Motor Control

In the slave code, instead of waiting to receive commands from the master, manually set the target position in the main loop. This way, you can see if the motor control is working.

Other Problems

  • The L293D H-bridge heated up and eventually burnt out a couple of times during testing.
  • Occasionally, the drum sticks tried to reach their position by making a complete 360, but this was not possible due to the drum. This would cause internal problems in the motor.
  • The drum sticks would sometime fall from its position due to gravity.

Future Work

There are many options that could be researched and developed to make this project better.

  • Due to time constraints, we were not able to implement the flash memory. Flash memory is a more reliable method of data logging than currently implemented.
  • In addition to the position control that is available, velocity control would be useful.

See Also