RC car lesson (#519)

* initial drop

* fixing summary

* adding images

* Adding basic connect code

* connect section

* moving video

* adding ignores
This commit is contained in:
Peli de Halleux
2017-08-25 17:02:13 -07:00
committed by GitHub
parent 588f127ddd
commit 743979b9ea
17 changed files with 261 additions and 0 deletions

View 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
```

View 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
```

View 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
### ~