This project centers around a system with two PIC32MX170F256B microcontrollers. The logic PIC (U2) is designated as the leader in SPI communication and has the motor PIC (U1) as its follower, listening to its commands and controlling the PWM outputs to the motors. A power distribution board has been utilized to power this setup. Various sensors have been employed for robotic perception including opto-reflective sensors, phototransistors, magnetic encoders, and buttons.
As for the power, two 7.2V NiMH batteries are connected in series to provide greater than 14.4V voltage necessary for driving DC Motors while a DC-DC Stepdown converter is connected to its output to downregulate and generate a 6V rail, required to power our HX5010 launching servo to the targeted angular velocity. A 5V 2.4A output power bank is connected to the power distribution board. The 5V connections power up two other servos, two LEDs, the reference generator, and the magnetic encoders. Through regulators, the 3.3V output provides smooth drives for the PICs, most of the sensors, and the signal conditioning circuit.
The followings are the System Block Diagram and schematic of all the circuits built.
Logic Pic
The logic pic acts as the leader in SPI communication, and controls our acorn game strategies. It takes in the following sensor inputs: phototransistor searching for acorn and beacon, left and right IR proximity sensor for obstacle avoidance and the start button presses. Its outputs control the actuation of all three servos: the yard indicator, the acorn gripper, and the acorn launcher, the on/off the the game-in-progress red LED, and the IR emitter LED for acorn search. Through SS_BAR, SDO, SDI, and SCK connection, it communicates motor commands coded in 8bit numbers to the motor PIC and receives feedback in the same format.
For clarity, the usages of OC (output compare), IC (input compare), and AN (analog reads) and how each pin is connected are shown in the table below.
Motor Pic
The motor pic acts as the follower in SPI communication, and controls the locomotion of our robot. It takes in the following sensor inputs: magnetic encoders attached to DC motors, and opto-reflective sensors for differentiating tape and non-tape grounds and for detecting when acorn is in hold. For the outputs, with two pairs of PWM outputs and brake pin outputs connected to the TLE5206 H-bridge, it can drive motors on either wheels in the smoother brake mode. The tape following is enabled by posting events when opto sensors on the left or right side of the robot sees black and speeding up the motor on the correct side. The encoder sum on both wheels are checked routinely to make 90 degrees, 180 degrees and 360 degrees turns and is also checked at the beginning when the robot sees beacon K, A, D, E to determine the yard. Through SS_BAR, SDO, SDI, and SCK connection, it receives motor commands coded in 8bit numbers to the motor PIC and sends feedback in the same format when it finishes a certain task.
For clarity, the usages of OC (output compare), IC (input compare), and AN (analog reads) and how each pin is connected are shown in the table below.
Signal Conditioning Board
Our A.T.O.M.'s successful completion of the task heavily depends on its ability to detect and align with beacons, and to detect the free-range Acorns on field. A separate board has been soldered purely to handle input signals from beacons and acorns to search and align with them to reduce noises.
The top circuit is a voltage generator using an op-amp MCP6294 as buffer with a voltage divider to generate a stable 2.4V reference voltage used in various stages in the signal conditioning.
The middle circuit is designed for acorn detection. Starting with an inverting trans resistive circuit with op-amp MCP6294, the 10k ohm resistance in the feedback has been chosen to not saturate the output and have enough contrast at various lighting conditions. Then comes a high-pass filter biased at Vref with cutoff frequency at 3.4Hz to remove the possible DC drifts and make the signal centered at Vref. The output is fed to the second-stage, an op-amp MCP6294 based non-inverting amplifying circuit to further amplify the signal. A low-pass filter at 723Hz is added at the end of second stage to remove noises far away from our IR emitter's signal frequency at 50Hz. The two couplers together form a bandpass filter with our frequency of interest in the unattenuated range. The output is later connected to an inverting comparator MCP6546 circuit with high cutoff threshold at 2.4743V, low cutoff threshold at 2.2018V, and pull up at 3.3V. The final output is a digitized 0~3.3V square wave signal.
The bottom circuit is designed for beacon detection. With the same circuit layout but different resistor and capacitor values at stages for different gains and cutoff frequencies. The second stage now has a gain of 6.2 instead of 6.6. The bandpass filter incorporated now has a 284Hz low cutoff and a 7234.3Hz high cutoff to ensure the beacon frequency of interest from 900 to 3333Hz left unattenuated.
LED Circuits
A.T.O.M. has two LEDs incorporated. The IR LED (shown on bottom left) is controlled by a 50Hz PWM driving signal from the logic PIC's OC4 channel and is used as emitter to shine light onto things in the front of robot. Depending on the received light intensity and signal frequency on the coupled phototransistor, the robot can tell the availability of a front placed Acorn. LTR 5208E IR Led has a maximum continuous current of 100mA. To reach a balance between heat dissipation and light intensity required for long-range Acorn detection, the current limiting resistor has a value of 47 ohms to enable a maximum current of 80mA. An N-channel MOSFET 2N7000 has its gate connected to the leader PIC to control the on/off of LED. The red LED (shown on bottom right) has a similar circuit built with its on/off controlled by the gate input from leader PIC. With a forward voltage of 2V, using 150 ohms as the current-limiting resistor keeps the current at 20mA, less than the 21mA maximum continuous current. Rather than using output compares, framework timer with period of 0.4second is used to toggle the red LED's state after the game has begun.
Button Press Circuits
There is only one button used in our A.T.O.M., a blue momentary button to indicate the start of the game round. The button circuit uses RC time constants for hardware debouncing (credit to: prelab0) and are connected to the logic PIC U2 as digital input.
Magnetic Encoders
There are two encoders in our system, for the right and left DC motor respectively. The encoders are powered from the 5V pins coming off the power bank. For every revolution of the DC motor's shaft, 12 ticks are posted. Using input capture subsystems on the motor PIC U1, we are able to calculate the time interval between each tick and derive the speed in rpm our wheel is spinning at. This information is later used in our PI controller to let the algorithm aware of which motor needs to reduce or increase its duty cycle to go straight. The sum of encoder ticks on both wheels are also used to indicate when to stop during turning to achieve a 90/180/360 degrees as instructed by the commands. Since the encoder outputs are connected to 5V-intolerant pins on the motor PIC, a voltage divider is built at the output of ChA to reduce the 0-5V square wave to a 0~2.973V one.
Tape Sensors
Below the chassis and on the rotation axis of our robot lies three juxtaposed opto-reflective sensors TCRT5000 with detection range of 1mm and 25mm. All three sensors are powered from 3.3V pins coming off the power bank. In this project, they are used as analog tape sensors outputting values above 750 when the emitter is above black tapes and values below 120 when the emitter is above non-black/absorbing grounds. The values of tape sensors are routinely checked and depending on the readings, events to speed up the right or left side of the motor or to restore original speed will be posted to the motor control service.
Other Sensors
In addition to the previous listed sensors, our A.T.O.M. is equipped with three additional HW201 digital sensors, the left IR proximity sensor (top), the right IR proximity sensor (middle), and the front acorn contact sensor (bottom). All three sensors are powered from 3.3V pins coming off the power bank. The first two are connected to logic PIC U2 and are routinely checked. If a low to high transition has been detected on either sensors, a short distance event will be posted to trigger the robot's backwards movement. The last sensor is connected to the motor PIC U1 and is also frequently checked. If a low to high transition has been detected, an Acorn has entered A.T.O.M.'s gripper cavity. The motor will be stopped and the Acorn in contact message will be sent to the leader PIC to command the gripper servo to grasp.