RC car lesson (#519)
* initial drop * fixing summary * adding images * Adding basic connect code * connect section * moving video * adding ignores
@ -30,6 +30,7 @@
|
|||||||
* [Inchworm](/projects/inchworm)
|
* [Inchworm](/projects/inchworm)
|
||||||
* [Milk Carton Robot](/projects/milk-carton-robot)
|
* [Milk Carton Robot](/projects/milk-carton-robot)
|
||||||
* [Milk monster](/projects/milky-monster)
|
* [Milk monster](/projects/milky-monster)
|
||||||
|
* [RC Car](/projects/rc-car)
|
||||||
* [Timing gates](/projects/timing-gates)
|
* [Timing gates](/projects/timing-gates)
|
||||||
* [Compass](/projects/compass)
|
* [Compass](/projects/compass)
|
||||||
* [Telegraph](/projects/telegraph)
|
* [Telegraph](/projects/telegraph)
|
||||||
|
@ -110,6 +110,10 @@ Fun games to build with your @boardname@.
|
|||||||
"name": "Railway crossing",
|
"name": "Railway crossing",
|
||||||
"url":"/projects/railway-crossing",
|
"url":"/projects/railway-crossing",
|
||||||
"imageUrl":"/static/mb/projects/railway-crossing.png"
|
"imageUrl":"/static/mb/projects/railway-crossing.png"
|
||||||
|
},{
|
||||||
|
"name": "Hacked RC car with Kitronik",
|
||||||
|
"url": "/projects/rc-car",
|
||||||
|
"imageUrl":"/static/mb/projects/rc-car.jpg"
|
||||||
}]
|
}]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
54
docs/projects/rc-car.md
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# RC car
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
Hack a toy RC car with your @boardname@!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
https://youtu.be/xQJCZwVvjyw
|
||||||
|
|
||||||
|
### ~ hint
|
||||||
|
|
||||||
|
This activity involves opening an electronic toy, cutting into cables and potentially rendering it completly useless.
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
## Materials
|
||||||
|
|
||||||
|
* Toy RC car with 4 or 6 AA batteries
|
||||||
|
* 1 @boardname@
|
||||||
|
* a cable trimmer
|
||||||
|
* small Philips screw driver
|
||||||
|
* [1 Kitronik motor driver](https://www.kitronik.co.uk/5620-motor-driver-board-for-the-bbc-microbit-v2.html)
|
||||||
|
|
||||||
|
## What's the plan?
|
||||||
|
|
||||||
|
Most toy RC car use 3 small DC motors to operate:
|
||||||
|
* 1 DC motor for the back wheels torque,
|
||||||
|
* 1 DC motor for the front wheels torque,
|
||||||
|
* 1 DC motor to steer the front wheels
|
||||||
|
|
||||||
|
The plan is to open up the RC car, remove the existing electronic controller and replace it with the motor driver
|
||||||
|
that can control 2 DC motors. We will connect both torque motors to one controller and the steering motor to the other controller.
|
||||||
|
|
||||||
|
Once the motor driver is connected, we will use a @boardname@ to control it. Another @boardname@ can also be used as a radio controller
|
||||||
|
for the @boardname@ in the car.
|
||||||
|
|
||||||
|
### ~ hint
|
||||||
|
|
||||||
|
Ask friends and family for old RC cars lying around, scout thrift shops and other second hand shops for discarded RC cars.
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
## Activities
|
||||||
|
|
||||||
|
* [Make](/projects/rc-car/make)
|
||||||
|
* [Code](/projects/rc-car/code)
|
||||||
|
* [Connect](/projects/rc-car/connect)
|
||||||
|
|
||||||
|
### ~button /projects/rc-car/make
|
||||||
|
|
||||||
|
Let's make it!
|
||||||
|
|
||||||
|
### ~
|
72
docs/projects/rc-car/code.md
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
# Code
|
||||||
|
|
||||||
|
## Step 1: Add the Kitronik package
|
||||||
|
|
||||||
|
Kitronik published a set of blocks to use their motor driver. We need to add it to our project.
|
||||||
|
|
||||||
|
* Click on **Advanced**
|
||||||
|
* Click **Add Package**
|
||||||
|
* Type ``kitronik``, press **Enter**
|
||||||
|
* Select the **kitronik-motor-driver** package
|
||||||
|
|
||||||
|
After the package gets loaded, you should see a new **Kitronik" category in the toolbox.
|
||||||
|
|
||||||
|
## Step 2: Round and round we go!
|
||||||
|
|
||||||
|
https://youtu.be/pD6tM1nXCPA
|
||||||
|
|
||||||
|
The first program will have the car drive in a circle for 5 seconds when the user presses button ``A``.
|
||||||
|
This is simply done by turning both motor controllers on for 5 seconds.
|
||||||
|
|
||||||
|
```blocks-ignore
|
||||||
|
input.onButtonPressed(Button.A, () => {
|
||||||
|
basic.showIcon(IconNames.Happy)
|
||||||
|
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Reverse, 100)
|
||||||
|
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Forward, 100)
|
||||||
|
basic.pause(5000)
|
||||||
|
kitronik.motorOff(kitronik.Motors.Motor1)
|
||||||
|
kitronik.motorOff(kitronik.Motors.Motor2)
|
||||||
|
basic.showIcon(IconNames.SmallDiamond)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### ~ hint
|
||||||
|
|
||||||
|
Make sure to unplug the @boardname@ from the Edge connector while your are connecting it to your computer to avoid any kind of electrical problem.
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
Depending on how you've connected your cables to the motor driver, your car may be going backward instead of forward.
|
||||||
|
You can either swap the cables or change your code to account for that.
|
||||||
|
|
||||||
|
## Step 3: Figure Eight
|
||||||
|
|
||||||
|
https://youtu.be/agor9wtiAkE
|
||||||
|
|
||||||
|
Instead of stopping after 5 seconds, we reverse the steering motor to turn the other direction. This will create a figure eight trajectory.
|
||||||
|
|
||||||
|
```blocks-ignore
|
||||||
|
input.onButtonPressed(Button.A, () => {
|
||||||
|
basic.showIcon(IconNames.Happy)
|
||||||
|
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Reverse, 100)
|
||||||
|
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Forward, 100)
|
||||||
|
basic.pause(3500)
|
||||||
|
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Reverse, 100)
|
||||||
|
basic.pause(3500)
|
||||||
|
kitronik.motorOff(kitronik.Motors.Motor1)
|
||||||
|
kitronik.motorOff(kitronik.Motors.Motor2)
|
||||||
|
basic.showIcon(IconNames.SmallDiamond)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Great! It's now time to use another @boardname@ to remove control the car.
|
||||||
|
|
||||||
|
### ~button /projects/rc-car/connect
|
||||||
|
|
||||||
|
Connect
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
```package
|
||||||
|
pxt-kitronik-motor-driver=github:kitronikltd/pxt-kitronik-motor-driver#v0.0.3
|
||||||
|
```
|
54
docs/projects/rc-car/connect.md
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# Connect
|
||||||
|
|
||||||
|
|
||||||
|
https://youtu.be/XXesoUC0XBU
|
||||||
|
|
||||||
|
We are going to use radio to remote control the toy car.
|
||||||
|
A second @microbit@ will send commands to control the throttle and the steering.
|
||||||
|
|
||||||
|
```blocks-ignore
|
||||||
|
let steering = 0
|
||||||
|
let throttle = 0
|
||||||
|
radio.onDataPacketReceived( ({ receivedString: name, receivedNumber: value }) => {
|
||||||
|
led.toggle(0, 0)
|
||||||
|
if (name == "throttle") {
|
||||||
|
if (value > 0) {
|
||||||
|
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Reverse, 100);
|
||||||
|
} else if (value < 0) {
|
||||||
|
kitronik.motorOn(kitronik.Motors.Motor1, kitronik.MotorDirection.Forward, 100);
|
||||||
|
} else {
|
||||||
|
kitronik.motorOff(kitronik.Motors.Motor1);
|
||||||
|
}
|
||||||
|
} else if (name == "steering") {
|
||||||
|
if (value > 0) {
|
||||||
|
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Forward, 100);
|
||||||
|
} else if (value < 0) {
|
||||||
|
kitronik.motorOn(kitronik.Motors.Motor2, kitronik.MotorDirection.Reverse, 100);
|
||||||
|
} else {
|
||||||
|
kitronik.motorOff(kitronik.Motors.Motor2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
basic.forever(() => {
|
||||||
|
throttle = 0
|
||||||
|
if (input.buttonIsPressed(Button.A)) {
|
||||||
|
throttle = 100
|
||||||
|
} else if (input.buttonIsPressed(Button.B)) {
|
||||||
|
throttle = -100
|
||||||
|
}
|
||||||
|
radio.sendValue("throttle", throttle)
|
||||||
|
steering = 0
|
||||||
|
if (input.acceleration(Dimension.X) < -512) {
|
||||||
|
steering = -100
|
||||||
|
} else if (input.acceleration(Dimension.X) > 512) {
|
||||||
|
steering = 100
|
||||||
|
}
|
||||||
|
radio.sendValue("steering", steering)
|
||||||
|
})
|
||||||
|
radio.setGroup(12)
|
||||||
|
```
|
||||||
|
|
||||||
|
```package
|
||||||
|
radio
|
||||||
|
pxt-kitronik-motor-driver=github:kitronikltd/pxt-kitronik-motor-driver#v0.0.3
|
||||||
|
```
|
76
docs/projects/rc-car/make.md
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
# Make
|
||||||
|
|
||||||
|
### @description Hacking the car electronics
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
Hack the @boardname@ into the car!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
https://youtu.be/gH__3l_oDeM
|
||||||
|
|
||||||
|
## Materials
|
||||||
|
|
||||||
|
* a toy RC car with 4 or 6 AA batteries
|
||||||
|
* a cable trimmer
|
||||||
|
* small Philips screw driver
|
||||||
|
|
||||||
|
![A toy RC car](/static/mb/projects/rc-car/rccar.jpg)
|
||||||
|
|
||||||
|
## Step 1: Remove the batteries!
|
||||||
|
|
||||||
|
Make sure all the batteries are removed from the toy car!
|
||||||
|
|
||||||
|
## Step 2: Remove the cover
|
||||||
|
|
||||||
|
Remove the various protective covers until you have access to the electronic controller. Make sure to keep track of all the screws you remove,
|
||||||
|
you will need them again!
|
||||||
|
|
||||||
|
## Step 3: Cut out the electronic board
|
||||||
|
|
||||||
|
Follow the motor and power cables and cut the wires as close as possible from the electronic board. You should end up with a total of 8 cables:
|
||||||
|
2 for power, 2 for the steering motor and 2 pairs for the torque motors.
|
||||||
|
|
||||||
|
![Electronic board removed](/static/mb/projects/rc-car/elecremoved.jpg)
|
||||||
|
|
||||||
|
## Step 4: Prepare the cables
|
||||||
|
|
||||||
|
Using the wire trimmer, expose 1/4 inch (1/2 cm) of metal on each wire so you can attach it to the motor driver.
|
||||||
|
|
||||||
|
![Various cables](/static/mb/projects/rc-car/cables.jpg)
|
||||||
|
|
||||||
|
## Step 5: Connect the battery cables
|
||||||
|
|
||||||
|
* Connect the cables from the battery section to the power input on the motor shield.
|
||||||
|
Make sure the **+** cable goes into the **+** port!
|
||||||
|
* Connect both torque motors to the **motor 1** connector in the motor driver.
|
||||||
|
Make sure to connect the cables of same colors so that your wheel turn the same direction!
|
||||||
|
* Connect the remaining motor cables to the **motor 2** connector.
|
||||||
|
|
||||||
|
![Wiring](/static/mb/projects/rc-car/wiring.jpg)
|
||||||
|
|
||||||
|
## Step 6: Slot in the @boardname@
|
||||||
|
|
||||||
|
Probably the easiest step, insert the @boardname@ in the edge connector until clips in.
|
||||||
|
|
||||||
|
## (Optional) Step 7: Cut out a slot in the cover to fit the @boardname@
|
||||||
|
|
||||||
|
Depending on your car size, you may be able to fit back the decoration top back on the car.
|
||||||
|
Otherwise, get some cardboard, scissors and a glue gun to rebuild it yourself!
|
||||||
|
|
||||||
|
![Cutout](/static/mb/projects/rc-car/cutout.jpg)
|
||||||
|
|
||||||
|
## (Optional) Step 8: Paint job
|
||||||
|
|
||||||
|
Once you have replaced the cover (original or carboard), decorate it to your taste!
|
||||||
|
|
||||||
|
![Painted](/static/mb/projects/rc-car/painted.jpg)
|
||||||
|
|
||||||
|
That's it, it's time to code!
|
||||||
|
|
||||||
|
### ~button /projects/rc-car/code
|
||||||
|
|
||||||
|
Code
|
||||||
|
|
||||||
|
### ~
|
BIN
docs/static/mb/projects/rc-car.jpg
vendored
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
docs/static/mb/projects/rc-car/backdrivetrain.jpg
vendored
Normal file
After Width: | Height: | Size: 122 KiB |
BIN
docs/static/mb/projects/rc-car/cables.jpg
vendored
Normal file
After Width: | Height: | Size: 109 KiB |
BIN
docs/static/mb/projects/rc-car/cutout.jpg
vendored
Normal file
After Width: | Height: | Size: 87 KiB |
BIN
docs/static/mb/projects/rc-car/elecremoved.jpg
vendored
Normal file
After Width: | Height: | Size: 116 KiB |
BIN
docs/static/mb/projects/rc-car/frontdrivetrain.jpg
vendored
Normal file
After Width: | Height: | Size: 107 KiB |
BIN
docs/static/mb/projects/rc-car/painted.jpg
vendored
Normal file
After Width: | Height: | Size: 100 KiB |
BIN
docs/static/mb/projects/rc-car/project.jpg
vendored
Normal file
After Width: | Height: | Size: 118 KiB |
BIN
docs/static/mb/projects/rc-car/rccar.jpg
vendored
Normal file
After Width: | Height: | Size: 112 KiB |
BIN
docs/static/mb/projects/rc-car/stripped.jpg
vendored
Normal file
After Width: | Height: | Size: 96 KiB |
BIN
docs/static/mb/projects/rc-car/wiring.jpg
vendored
Normal file
After Width: | Height: | Size: 95 KiB |