Top Banner

of 12

Modding a Tank for Wireless Control

Jun 02, 2018

Download

Documents

Marius Danila
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/10/2019 Modding a Tank for Wireless Control

    1/12

  • 8/10/2019 Modding a Tank for Wireless Control

    2/12

    http://www.instructables.com/id/Modding-a-tank-for-wireless-control/

    Intro: Modding a tank for wireless controlIn this instructable I will show you how to transform your RF tank into something controlled through wifi. The joystick, or control panel will be a PC program written in CApps can be written for android phones as well, to make the control really easy.Unfortunately electric IMP has servers pretty far from where I live, so latency IS a problem in my case at least.

    What you're going to need:- some electronics knowledge- a working RF, IR, or wired remote controlled tank, or any kind of vehicle- a motor controller board + electric imp, or any simple motor controller board, for that matter- jumper wires- an ULN board for powering the fifth motor (or stepper)- a screwdriver

    What I had to start with:

    - some electronics knowledge- thisRC tank- a mini-box motor controller board + electric imp-jumper wires- thisULN board- a screwdriver

    Step 1:Tearing the tank apart, taking a lookFor us to hack a tank like this, we have to understand how it's working, role of boards, components, mechanics.

    Be very careful not to break anything thinking, there's no more screws keeping the thing together. I didn't had to find any hidden screws while taking this tank apart, stbe patient.The first thing you need to take off, is the small board in the front with the chaintrack-reserves. This is secured in place with three screws. Even if you get it loose, you'have to take off the front wheel, and its shaft on the right side, that's blocking it.I advise anyone doing this to leave the screws in the holes, so they wouldn't lose them.

    When you have that done, you can put the wheel back, so you can test the thing later. Carefully put the chaintrack back too. After this, unscrew the six screws on thebottom, and put them away for a while. Now you can lift the top part off to have a look inside.At first sight, you will see a ~2 x 2 inch board with some transistors, resistors, capacitors on it. That is the RF receiver and the driver section of the motors. In the front will see the gearbox covered with plastic, holding the gears in place.

    In the upper part, you might see a DC motor, some wires, and a white circle shaped thing, that has gears on the outer side. That is the gear that turns the upper hull. Ddeeper, take out the screws holding that white wheel, and pull out the hull.You won't see much, just the hull, and the shooting mechanism sticking out. There are five screws covering the rest, take them out and take a look on the inside. You see the LED that lights up when shooting, the rest of the shooting mechanism, the barrel lifting mechanism, and some switches with wires.

    The shooting mechanism is pretty complex, and because it's quite fragile too, I had to glue it quite a few times. Regardless of the care you take when you play with it,these kind of thing s break easy. The mechanism has two springs in it, and some gears too, it took em about 15 minutes to reassemble it for the first time. When it broagain, and it needed to be taken apart, I put it back together again in 2-3 minutes.

    okay, you got somewhat familiar with the guts of my tank, now I will turn it into something cooler.

    http://www.ebay.com/itm/ULN2003-Driver-Module-Stepper-Motor-Driver-Board-NEW-/231045786731?pt=LH_DefaultDomain_0&hash=item35cb66ec6bhttp://www.ebay.com/itm/80-PCS-20cm-Dupont-Wire-Connector-Cable-Female-to-Female-1P-1P-2-54mm-Jumper-C01-/281079732832?pt=LH_DefaultDomain_0&hash=item4171a85a60http://www.ebay.com/itm/1-20-RC-Tiger-tank-Shoots-Airsoft-BBs-W-sound-Over-14-inches-long-NEW-RTR-/111154409959?pt=Radio_Control_Vehicles&hash=item19e151b1e7
  • 8/10/2019 Modding a Tank for Wireless Control

    3/12

    http://www.instructables.com/id/Modding-a-tank-for-wireless-control/

    Image Notes1. take out the battery

    Image Notes1. take off the chain tracks2. again3. front panel screws

    Image Notes1. take off front wheel on the right to be able to get the front off

    Image Notes1. ok, front panel is off

    Image Notes1. main board2. chain-track drivers and gearbox

    Image Notes1. parallel filter capacitor2. take these off, if having in-built current limit

  • 8/10/2019 Modding a Tank for Wireless Control

    4/12

    http://www.instructables.com/id/Modding-a-tank-for-wireless-control/

    Image Notes1. shooting mechanism

    Image Notes1. upper hull and shooting mechanism

    Image Notes1. this DC motor lifts the barrel2. take this cap off too

    Image Notes1. capacitor accross the motor

    Step 2:Start hackingI am a lucky tester of this little controller board, so I will focus on how THIS particular board works. Hopefully this little piece will be available on the market soon.

    Now you got to check out something: look for any capacitors connected straight to the pins of each motor you can see. If there is a cap on one motor, it is very likely foall of them to have one. Those are there to minimize the noise coming from the motors.However, if you are using a motor controller board, that has current limitation, you need to take the caps off. They act as short-circuits at start-up, when they're indischarged state. You can clip them off, or you can take them off nicely with a soldering iron, it's up to you.

    To remove the ones from the track driver motors, you must take the gearbox cover off, take out the motor, snap the caps off, and put everything back. I have to say,

    putting the motor back in its place wasn't too easy, though it matches the plastic perfectly.Clipping the remaining caps is easy, you don't have to deal with twisty angles, or weird motor holders.

    Okay, caps are off, next thing is to hack in our motor controller with the imp on it.The board pin headers are marked on the silkscreen layer, the DC motor pins can be easily identified. You will have to connect your DC motors to those, or the equivapins on your motor controller board. There are only DC motors in my tank, the wiring wasn't really hard to figure out. I put some resistor legs in the 0.2" header holes, aconnected them with a female-to-female cable to the DC outputs.Since I had five motors in my tank, I had to add an ULN buffer to power the fifth. These are actually made for steppers, but they're just as good for DC motors as well.The motor that makes the shooting happen is the only one that needs to rotate only in one direction, I chose that to be the one driven by the ULN board. I modified thecode of a servo output to give out a constant '1' or '0' whenever the control of the C# app sais so, and connected it to an ULN input. The shooter motor was tied betwethe coresponding ULN output and the ground.The buffering is needed, because the servo output can provide currents only up to 20mA, but our DC motor obviously draws more.The ULN2003 has a rated output current of 500mA each output, that is more than enough for us.

    The motor controller board must be powered for this to work. I had a battery of 9.6V in the tank by default, I used that to power my controller board, which had a voltagconsraint: Vin must be under 11V.

  • 8/10/2019 Modding a Tank for Wireless Control

    5/12

    http://www.instructables.com/id/Modding-a-tank-for-wireless-control/

    If you have unclarities about the connections that need to be made, please refer to the image from this step.

    Image Notes1. left track2. right track3. upper hull horizontal4. barrel vertical5. 11V max!6. ULN buffer board7. firing motor

    8. electric imp & motor control board

    Step 3:A few words about the boardThis board is capable of driving three different motor types: DC, steppers, and servos. Commands are coming through wifi, and parsed by the imp. Then, they're sent the waveform controller IC-s via serial interface.

    ServosWhat do we need to know about servomotors? Well, they usually have a potentiometer in them for feedback, and a gearbox for higher torque. Small DIY project servoare quite often limited to a certain turn angle, most of the times because of the potentiometer.Servo motors require a periodic squarewave of 50Hz , with variable pulse width, to change their position. However, if the signal drops out, the servo stays in the positioto which it was sent last time.The pulse width is a variable that differs from servo to servo. I have a servo, that needs a 1 millisecond impulse to turn to the left extremity, and an approximately 2.5millisecond impulse to turn to the maximum right position. The impulse lengths can be calculated using the law of three.The 1 millisecond base signal is required, but it doesn't change the position in any way. So we're going to look at this as a 1 ms offset.

    Let's say we want to turn the shaft to 75 degrees. We know these:max turn angle = 180 degrees

    impulse width change = 2.5 - 1 = 1.5

    180 degrees ................. 1.5 ms (1 ms offset not taken into consideration!)75 degrees ................... x ms-----------------------------------------x = (75 * 1.5) / 180 = 0.625 ms

    This is the formula we have to know, when we want to position the shaft to a given angle.

    Stepper motorsThe stepper motors need four amplified servo signals. This is what the ULN board was actually built for. Connect the servo outputs to the ULN inputs, and the Stepperthe ULN outputs. Look at the table to see how the four lines get toggled.The board supports wave, full-step, and half-step drive modes, basically anything you'll ever need. The IC providing the waveform isn't actually a specialized stepperdriver IC, so microstepping isn't supported.There is no in-built current limit on the stepper controller side.

    DC motorsThe simplest of all three, I think. There are four H-bridges on-board, each bridge has an input for direction, and an input for speed. The speed is varied by changing th

    duty cycle of the signal that goes on the speed pin.Simple enough, the DC motors have two parameters in our case: speed and direction. Change those to control the motors.Speed can be changed by giving a modulated signal on their power rail, direction can be toggled by changing the power rail the motor pins go to. Refer to the images get a more visual example on PWM modulation and direction control.

    Each of my bridges can deliver currents up to 1.5 amps before the in-built overcurrent protection kicks in.Current measurements can be made by developing the firmware for the imp: AD measurements on a shunt connected in series with the low side of the H-bridge can gyou an idea on how much current is flowing. Current is directly propotional with torque, so you could get an approximate torque value as well.

    Throughout the development, I accidentally reinvented something: Connect the PWM pin to 'high', and PWM modulate the signal that goes to the direction pin. You wiget PWM and direction control by controlling a single pin.Giving a 50% duty cycle signal on direction pin will make the motor stop (it turns to left just as much it does turn to right, so it goes nowhere from a point of view),changing the duty cycle low/high will result in the motor spinning left/right.The bad thing about this is, that there is consumption even when the motor doesn't move. We also lose one bit from the resolution.

    Long story short: this is the board I decided to use for control, the IMP is optional, this can be incorporated into any kind of system, and be controlled via I2C.I've also had the ebay-type L298 H-bridge board at hand, but that can deal with 2 motors only, and I needed 5. Not to mention the space the ebay bridge eats up :)

  • 8/10/2019 Modding a Tank for Wireless Control

    6/12

    http://www.instructables.com/id/Modding-a-tank-for-wireless-control/

    If there are any questions about the motor controller board I decided to use, you can ask in a comment!

    Let's see how can we control the board via the IMP, and a small C# application!

    Image Notes1. H-bridges2. divider stage3. divider stage4. buck converter5. DC waveform generator IC

    Image Notes1. imp2. id chip3. servo headers4. analog/pwm/io5. analog/pwm/uart/io6. DC motor headers7. Vin

    Image Notes1. T is constant, the duty cycle varies

  • 8/10/2019 Modding a Tank for Wireless Control

    7/12

    http://www.instructables.com/id/Modding-a-tank-for-wireless-control/

    Image Notes

    1. i bought few of these on ebay, but, as you can see, they're quite large with thatheatsink on them.

  • 8/10/2019 Modding a Tank for Wireless Control

    8/12

    http://www.instructables.com/id/Modding-a-tank-for-wireless-control/

    Step 4:Writing the for the PC programThere isn't really that much to be said here, especially because I am not too familiar with C#. I was able to write everything I ever needed, by looking on the internet fothe error messages I got, and msdn examples.

    First, we need a textbox for the imp http link we're going to get from the imp IDE. This is different for each HTTP IN module, that's why we need to make it a variable.Next, we need all sort of controls, to have full control on our motors. Different tanks might have different motors in them, so I explain how this board could be used to dthree types.

    ServosWe need to add input controls to change shaft angle from our C# app. I added a slidebar, a start, end and stop button. The start button takes the servo to 0 degrees, tend to 180 degrees (or servo maximum), the stop button makes the servo output drop to '0', effectively stopping it, whichever position the shaft is in. The slidebar givethe angle we want the servo to turn to. This forms a control string, which is sent to the HTTP link we already have. The imp parses it, and takes action by sending datathrough serial interface to the servo controller circuit.

    SteppersTo enable a stepper motor, one must select "Stepper A" against "Servo 0->3" down in the Stepper motor groupbox. Then he can select the drive mode from the threepossibilities.Depending on what we chose here, the servo outputs will toggle exactly as the drawing in the board description step depicts. I won't go into details about how the motshaft gets turned, that would be beyond the scope of this instructable. I tested all three, they all work.The moment we switch to "Stepper A", the motor will start turning. Changing the two-positioned direction slidebar will change the turn direction.The angle and steps textboxes aren't dealt with yet, that's something I just realized it could prove useful. To make that work, step angle, and some other parameterswould need to be included, too.

    DCControlling DC motors with the C# app is straightforward. You have a speed slidebar, this changes the duty-cycles from 0 to 100% with a 0.1% resolution. Then, you ha direction slidebar with two positions, left and right. The brake button is there to stop the motor immediately.

    After I finished tests with these, I realized, I needed some sort of joystick for better control. I added a "panel" control, and a mouse movement event, to know where I awith the mouse over the panel region. In the middle I put 0, 0 for the two chaintrack-driving outputs, as I move my mouse left-right and front-back, the tank reacts withchanges in the speed of each motors.I also added some textboxes for debugging.

    Note, that the point, where the application pops up at start, has effect on the on-screen position of this panel. So, if you decide to use this panel thing to control your tayou'll have to adjust it to work with your X & Y offsets. Or simply snap it to a corner of your screen, so the panel always has the same on-screen position.

    Making such a window is simple, just drag together everything you want from the "Toolbox" bar, align them, and "wire" them together in code. If you want something obutton-press, double click the button. If you want something to happen on a slidebar, or textbox change: add an event handler. It is very-very simple, you can findexamples for anything on the web.

    The way you communicate your parameters is at your choice. I built up a control string, which has some variables in it. I do something in the C# app, and send the strthat reflects that something on the URL I got from the IMP site. On IMP side the string is received on an input port. I parse out the variables, and send data to my I2Cdevices to execute the commands. very simple. I provided a snip of the code I wrote to send data.Parameter "data" has the string with the variables in it, the parameter "http" has to be the link from IMP site.

    Image Notes1. servo section with inputs, and feedback textboxes2. "homemade" joystick3. DC controller area, sliders adjust speed, switches adjust direction4. stepper motor controls

  • 8/10/2019 Modding a Tank for Wireless Control

    9/12

    http://www.instructables.com/id/Modding-a-tank-for-wireless-control/

    Step 5:Writing the firmware for the impI can't really tell stories about the firmware, it speaks for itself. It parses inputs from the HTTP IN node, and converts it into I2C commands, that can be interpreted by ttwo waveform driving IC-s. The H bridges VCC inputs are tied to these IC-s too, the bridge can be set to normal operation mode, or to sleep mode, minimizing currentconsumption.In the planner press "Add node" and select HTTP IN from the list that appears. After that, copy the link to your version of the C# app.I got my http post method from the web. I made some slight modifications on it, just to fit my needs better.When you're done with this part, simply pull an arrow by dragging the plus sign on the right top corner onto your imp node.

    Writing the code itself is the part that is the most time-consuming. I took examples from their forum, they proved to be useful. I've also had help from a colleague of miwith great experience in programming.Low level software isn't required here, the functions provided by the IMP team are more than enough to get this working.

    The code I wrote is probably far from optimal, however that wasn't my goal.I dedicate the following instructables steps to describe the IMP side stuff for each type of motors.

    Step 6:Functions that control my DC motorsDC motors are the most common type that can be found in appliances. I will start with a brief description of the functions I wrote to enable DC motor control on my boa

    INIT_DC()initializes the PCA9635 DC motor signal generator, resets the duty cycle pins to 0%, and puts the direction pin to 0. The two zeros on the H bridge control input pins lethe motor undriven and free spinning.

    DC_drivers()modifies the output drivers state. There are four modes, the output drivers can work in:00 - LED driver x is off (default power-up state).01 - LED driver x is fully on (individual brightness and group dimming/blinking not controlled).10 - LED driver x individual brightness can be controlled through its PWMx register.11 - LED driver x individual brightness and group dimming/blinking can be controlled through its PWMx register and the GRPPWM registers.The mode of each output driver is stored on two bits. Four driver states are grouped into a single register, the register name is the driver_id parameter of the DC_drivefunction. The second parameter is driver_mode, the user has to provide an 8 bit value with the wanted output driver mode shifted to its place.For example, if there is need for a switch from "fully on" to "PWM controlled" mode for output LED1, bits 3:2 of LEDOUT0 has to be changed from 01 to 10. In the defaIMP Motor Control board code this is done in the DC_command() function.Here's an example on this:

    ...temp = I2C_ReadByte(PCA9635, LEDOUT0); // read the registers contenttemp = temp &0xF3; // delete the bits found on bit fields 3:2temp = temp | 0x08; // set the 3:2 bits to 10DC_drivers(0, temp); // call DC_drivers() with the two parameters, LEDOUTx -in our case x is 0, and the updated register value

    ...

    Reading the register previously to the data change it's necessary, because the other bits in the register might have effect on the other outputs we use. To avoid this, I'read it first, changed the used two bits, and wrote it back again.

    DC_command()is the function used to change the speed and direction of the selected DC motor. The first parameter idtells the function, which DC output to modify with the next twoparameters: directionand duty_cycle. The last two parameters meaning is straightforward. The duty cycle is limited to 99.6%, any value bigger will result in changinthe duty cycle to 100% by changing the output driver state to "fully on" mode.Different applications will have different load on the motors, to get behind this, a ramp-up algorithm can be used to gradually increase the duty cycle.

    SleepMode()Takes advantage of the sleep mode feature of the DRV8835. Since this H-bridge draws very little current from the logic supply(typically 450 A, maximum 2 mA), it cabe powered straight from a PCA9685 pin, which can source a maximum of 10 mA. This is useful when one of the bridges is not used, putting it to sleep mode willminimize the current drawn from the load supply to ~10 nA. The first parameter "bridge" selects one of the two bridges on board, and can take "AB" or "CD" as value.These disable the bridge marked the same way, visible on the board silkscreen. The second parameter is active low, enables or disables sleep mode on the bridgeselected by the first function parameter.

  • 8/10/2019 Modding a Tank for Wireless Control

    10/12

    http://www.instructables.com/id/Modding-a-tank-for-wireless-control/

    Step 7:Functions controlling the 8 servo linesINIT_Servo()initializes the PCA9685 servo motor controller on power up. The period register is initialized to a value, that results in an output PWM period of 20 milliseconds. This 2millisecond period is required, this is the time in which the variable width signal has to repeat itself.

    SetServoConstants(turn, start, end)This function is used to save some values, that can change from servo to servo. Maximum turn angle, shortest impulse, longest impulse. These parameters are requirif we want to turn a servo shaft to a desired angle.

    function SERVO_command(id, angle);The function that tells the I2C device to start giving out impulses with given timings. The first parameter is the servo output number, the second is the angle we wish toturn the shaft of the servo on that channel.

    These three are the functions I used when it came to control servomotors.

  • 8/10/2019 Modding a Tank for Wireless Control

    11/12

    http://www.instructables.com/id/Modding-a-tank-for-wireless-control/

    Step 8:Stepper controlling functionSTEPPER_Command(id, steps, direction, mode)This function hasn't been finished yet, number of steps can't be given, since we don't know about the number of impulses that were sen't by the PCA9685. However, tmodeparameter allows us to control the stepper with three methods mentioned before.It works in both directions.

    Wave driveWhen using this step mode to drive the stepper, only a single phase gets activated at a given time. The number of steps is equal as it would be with full step drive modbut the torque is significantly lower than the rated torque.Full step driveThis is the most commonly used method, when it comes to drive stepper motors. Two phases are always on, and the motor will have full rated torque.Half step driveHalf stepping is widely used to increase angular resolution. Since the drive switches between one phase on two phases on, it will have less torque at the point,where only a single phase is turned on. Some compensation can be made with increasing the active winding current.

    That being said, we know plenty about this controller, now let's see how it works!

    Step 9:Final wordsI'm glad I was able to contribute with another instructable. If you like it, don't l ike it, have questions about it, have doubts about it..let me know! I am looking forwardanswering your questions.I'm off to clean the workshop :)

    Good luck to everyone in the MCU contest!

    Related Instructables

    wirelessmonitor tankrobot based on

    raspberry piby

    yichone

    A novel designfor raspberry piwireless shieldextension board

    by yichone

    RC tank with amoving FPV

    cameraby Nikus

    3D PrintedWireless Tank

    by 2bigbros

    Atari Combat:

    Tank vb 2010by

    kooljo

    My Robot Tank

    (Photos)by

    rptech

    http://www.instructables.com/member/rptech/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/My-Robot-Tank/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/My-Robot-Tank/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/My-Robot-Tank/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/kooljo/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Atari-Combat-Tank-vb-2010/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Atari-Combat-Tank-vb-2010/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Atari-Combat-Tank-vb-2010/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/2bigbros/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/3D-Printed-Wireless-LazerTag-Tank/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/3D-Printed-Wireless-LazerTag-Tank/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/3D-Printed-Wireless-LazerTag-Tank/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/Nikus/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/RC-FPV-tank/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/RC-FPV-tank/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/RC-FPV-tank/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/RC-FPV-tank/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/yichone/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/A-novel-design-for-raspberry-pi-wireless-shield-ex/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/A-novel-design-for-raspberry-pi-wireless-shield-ex/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/A-novel-design-for-raspberry-pi-wireless-shield-ex/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/A-novel-design-for-raspberry-pi-wireless-shield-ex/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/A-novel-design-for-raspberry-pi-wireless-shield-ex/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/yichone/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/wireless-monitor-tank-robot-based-on-raspberry-pi/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/wireless-monitor-tank-robot-based-on-raspberry-pi/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/wireless-monitor-tank-robot-based-on-raspberry-pi/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/wireless-monitor-tank-robot-based-on-raspberry-pi/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/wireless-monitor-tank-robot-based-on-raspberry-pi/?utm_source=pdf&utm_campaign=related
  • 8/10/2019 Modding a Tank for Wireless Control

    12/12

    htt // i t t bl /id/M ddi t k f i l t l/

    vertisemets

    Comments