Top Banner
12/30/2015 4WD Mobile Platform SKU:ROB0022 Robot Wiki https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 1/24 4WD Mobile Platform SKU:ROB0022 Contents [hide] 1 Function Introduction 1.1 STEP1: Assemble Robot 1.2 STEP2: Debug Motor 1.3 STEP3Install Upper Plate 1.4 STEP4: Debug Ultrasonic Sensor and Servo 1.5 STEP5: Debugging Robot Function Introduction This Kit will teach you how to build a automatic obstacle avoidance robot which is achieved on the platform of the Turtle Robot,based on ultrasonic sensor as distance measuring device,and combined with servo. STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and secure the motors in place. Place the motors in the correct alignment, then screw them into place as shown in the picture below. Please note that washers and gaskets are also included in the parts bag. Washers can be used to increase friction, which helps fasten the motors into place. The gaskets help prevent the screw nuts from loosening and falling off due to the Pirate’s movements and collisions.
24

4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

May 31, 2020

Download

Documents

dariahiddleston
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
Page 1: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 1/24

4WD Mobile Platform SKU:ROB0022

Contents [hide]

1 Function Introduction1.1 STEP1: Assemble Robot1.2 STEP2: Debug Motor1.3 STEP3:Install Upper Plate1.4 STEP4: Debug Ultrasonic Sensor and Servo1.5 STEP5: Debugging Robot

Function Introduction

This Kit will teach you how to build a automaticobstacle ­ avoidance robot which is achieved on theplatform of the Turtle Robot,based on ultrasonicsensor as distance measuring device,and combinedwith servo.

STEP1: Assemble Robot1.Assemble Your Own Motor

Look in your parts bag for eight long screws. These areused to fix and secure the motors in place. Place themotors in the correct alignment, then screw them intoplace as shown in the picture below.

Please note that washers and gaskets are alsoincluded in the parts bag. Washers can be used toincrease friction, which helps fasten the motors intoplace. The gaskets help prevent the screw nuts fromloosening and falling off due to the Pirate’smovements and collisions.

Page 2: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 2/24

2.Soldering the Cables

Take the black and red wires out of the parts bag.Attach one black and one red cable (15 cm long) toeach motor (4 motors in total). Then use your wirestripper to strip the insulation at both ends of the wires(make sure not to strip too much—refer to the picturesbelow). Next, solder the wires onto the pins affixed tothe motors. Repeat the soldering process for all fourmotors.

Page 3: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 3/24

Note:Pay attention to the correct locations of the redand black wires when soldering. Please consult thefollowing photos for details.

1

2

Page 4: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 4/24

3.Assemble the Romeo BLE controller

Look in your parts bag for three copper supports.Those 1cm­long supports are used to fasten theRomeo controller board. As shown in the picturebelow, there are three holes in the controller board.Place the three copper supports into the holes, thenfasten them into place with the appropriate screws.

Page 5: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 5/24

4.Assemble the Battery Box

Take out two countersunk screws (their heads are flat).Then follow the steps shown in the picture below andaffix the battery to the car base.

Page 6: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 6/24

5.Crafting the Power Switch

Batteries are the essential lifeblood of robots. Tocontrol power usage, we need to use a power switch:the switch turns off power when not in use, thuspreserving electricity and battery life. Refer to thepicture below before assembling and installing thepower switch.

Please pay attention to the sequence of the gasketsand screw nuts when assembling the switch.

Page 7: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 7/24

After assembling the switch, we want to start solderingits wires. Take some of the remaining wire leftoverfrom before. Strip the wiring off both ends of thecables so that the inside of the wire is exposed (sameprocess as with the motors before). We want to solderthe exposed end of the wires to the pins on the switch.When soldering, it’s very important that we note theposition of the switch’s pins.

Let’s do this step by step. a)Connect the switch to thebattery charger. Pay attention to the exact location ofboth items.

Page 8: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 8/24

b)Solder the red cables connecting the switch with thebattery charger as shown in the picture below.

Here’s another picture to make things clearer.

Page 9: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 9/24

c)Finally, take one red cable and one black cable.Attach one end of one cable to the negative pole ofthe battery charger and one end of the other cable tothe positive pole of the battery charger. Then attachthe other ends of both cables to the Romeo BLEcontroller.

Page 11: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 11/24

Looking at this enlarged picture should give you abetter idea of how the wires should be connected.After soldering, make sure to check and see if yourwiring between the battery and Romeo controller isconsistent from start to finish and matches with theabove pictures.

6.Assemble the Car Base

Using eight M3x6mm screws, attach the side plates tothe front and back bumper plates as shown by thediagram below.

Note: When tightening the screws during this step,make sure not to fully tighten the screws at first —this way, we can easily detach the top board in latersteps should we need to make adjustments.

Then, re­attach the base plate to the body of the caras shown in the picture below.

Page 12: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 12/24

This is what the car base should like after it’sbeen assembled — remember to install the batterypack!

7.Connect the Motors with the MicrocontrollerBoard

Now we need to the motors with the microcontrollerboard. Carefully follow the following diagram: the leftmotor’s red and black wires should be soldered intoM2; the right motor’s red and black wires should besoldered to M1. Pay special attention to the batterypack: the black wire should be soldered into the wireport reading GND, while the red wire should besoldered in the wire port labeled VND. Use yourscrewdriver to loosen and tighten the wire ports —make sure these ports are fastened well once the wireshave been inserted.

Note: Make sure the wires from one motor (i.e. theleft motor) are soldered into the motor port. (i.e. theM2 port on the diagram below — do not solder onemotor’s wires into two separate ports.)

Page 13: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 13/24

After soldering the motor wires to the microcontrollerboard, we’re ready to attach the top plate to the baseof the car. Before we attach the top plate, you havethe option of attaching a sensor plate (see diagrambelow) — if you don’t plan to use sensors just yet, youcan skip this extra step.

Page 14: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 14/24

After attaching the top plate, your Pirate shouldresemble the picture below.

8.Attach an extra level to the Pirate

Find the four holes on the base’s top plate. Screw inthe four M3x60mm Copper Standoffs, then attach theadditional top plate as shown in the diagram below —use M3x6mm screws to affix the plate to the copperstandoffs.

Page 16: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 16/24

STEP2: Debug MotorUpload the Code

int speedPin_M1 = 5; //M1 Speed Control int speedPin_M2 = 6; //M2 Speed Control int directionPin_M1 = 4; //M1 Direction Control int directionPin_M2 = 7; //M1 Direction Control

void setup()

void loop() carAdvance(100,100); delay(1000); carBack(100,100); delay(1000); carTurnLeft(250,250); delay(1000); carTurnRight(250,250); delay(1000);

void carStop() // Motor Stop digitalWrite(speedPin_M2,0); digitalWrite(directionPin_M1,LOW); digitalWrite(speedPin_M1,0); digitalWrite(directionPin_M2,LOW);

void carTurnLeft(int leftSpeed,int rightSpeed) //Turn Left analogWrite (speedPin_M2,leftSpeed); //PWM Speed Control digitalWrite(directionPin_M1,HIGH); analogWrite (speedPin_M1,rightSpeed);

Page 17: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 17/24

digitalWrite(directionPin_M2,HIGH);

void carTurnRight(int leftSpeed,int rightSpeed) //Turn Right analogWrite (speedPin_M2,leftSpeed); digitalWrite(directionPin_M1,LOW); analogWrite (speedPin_M1,rightSpeed); digitalWrite(directionPin_M2,LOW);

void carBack(int leftSpeed,int rightSpeed) //Move backward analogWrite (speedPin_M2,leftSpeed); digitalWrite(directionPin_M1,LOW); analogWrite (speedPin_M1,rightSpeed); digitalWrite(directionPin_M2,HIGH); void carAdvance(int leftSpeed,int rightSpeed) //Move forward analogWrite (speedPin_M2,leftSpeed); digitalWrite(directionPin_M1,HIGH); analogWrite (speedPin_M1,rightSpeed); digitalWrite(directionPin_M2,LOW);

STEP3:Install Upper Plate1. Fixed Ultrasonic Sensor Position

Please see the Installation Manual

2. Fixed Servo Position

Page 18: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 18/24

STEP4: Debug Ultrasonic Sensor andServo1. Hardware Connection

Page 19: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 19/24

2. Upload Code

Download the library firstly.Metro libray

#include <Servo.h> #include <Metro.h> Metro measureDistance = Metro(50); Metro sweepServo = Metro(20);

unsigned long actualDistance = 0;

Servo myservo; // create servo object to control a servo int pos = 60; int sweepFlag = 1;

Page 20: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 20/24

int URPWM = 3; // PWM Output 0-25000US,Every 50US represent 1cm int URTRIG= 10; // PWM trigger pin uint8_t EnPwmCmd[4]=0x44,0x02,0xbb,0x01; // distance measure command void setup() // Serial initialization myservo.attach(9); Serial.begin(9600); // Sets the baud rate to 9600 SensorSetup(); void loop() if(measureDistance.check() == 1) actualDistance = MeasureDistance(); // Serial.println(actualDistance); // delay(100); if(sweepServo.check() == 1) servoSweep();

void SensorSetup() pinMode(URTRIG,OUTPUT); // A low pull on pin COMP/TRIG digitalWrite(URTRIG,HIGH); // Set to HIGH pinMode(URPWM, INPUT); // Sending Enable PWM mode command for(int i=0;i<4;i++) Serial.write(EnPwmCmd[i]);

int MeasureDistance() // a low pull on pin COMP/TRIG triggering a sensor reading digitalWrite(URTRIG, LOW); digitalWrite(URTRIG, HIGH); // reading Pin PWM will output pulses unsigned long distance=pulseIn(URPWM,LOW); if(distance==50000) // the reading is invalid. Serial.print("Invalid"); else distance=distance/50; // every 50us low level stands for 1cm return distance;

void servoSweep() if(sweepFlag ) if(pos>=60 && pos<=120) pos=pos+1; // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' if(pos>119) sweepFlag = false; // assign the variable again else if(pos>=60 && pos<=120) pos=pos‐1; myservo.write(pos); if(pos<61) sweepFlag = true;

Page 21: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 21/24

3. Adjust the servo position

Method 1: Reinstall wheelMethod 2: Adapt your code accordingly

STEP5: Debugging Robot1. Fix the expansion board

Uplpad the code

#include <Servo.h> #include <Metro.h> Metro measureDistance = Metro(50); Metro sweepServo = Metro(20);

int speedPin_M1 = 5; //M1 Speed Control int speedPin_M2 = 6; //M2 Speed Control int directionPin_M1 = 4; //M1 Direction Control int directionPin_M2 = 7; //M1 Direction Control unsigned long actualDistance = 0;

Servo myservo; // create servo object to control a servo int pos = 60; int sweepFlag = 1;

int URPWM = 3; // PWM Output 0-25000US,Every 50US represent 1cm

Page 22: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 22/24

int URTRIG= 10; // PWM trigger pin uint8_t EnPwmCmd[4]=0x44,0x02,0xbb,0x01; // distance measure command void setup() // Serial initialization myservo.attach(9); Serial.begin(9600); // Sets the baud rate to 9600 SensorSetup(); void loop()

if(measureDistance.check() == 1) actualDistance = MeasureDistance(); // Serial.println(actualDistance); // delay(100); if(sweepServo.check() == 1) servoSweep(); if(actualDistance <= 30) myservo.write(90); if(pos>=90) // carBack(100,100); //// Serial.println("carBack"); // delay(100); carTurnRight(150,150); // Serial.println("carTurnRight"); delay(100); else // carBack(100,100); //// Serial.println("carBack"); // delay(100); carTurnLeft(150,150); // Serial.println("carTurnLeft"); delay(100); else carAdvance(70,70); // Serial.println("carAdvance"); delay(100); // carBack(150,150); void SensorSetup() pinMode(URTRIG,OUTPUT); // A low pull on pin COMP/TRIG digitalWrite(URTRIG,HIGH); // Set to HIGH pinMode(URPWM, INPUT); // Sending Enable PWM mode command for(int i=0;i<4;i++) Serial.write(EnPwmCmd[i]);

int MeasureDistance() // a low pull on pin COMP/TRIG triggering a sensor reading digitalWrite(URTRIG, LOW); digitalWrite(URTRIG, HIGH); // reading Pin PWM will output pulses unsigned long distance=pulseIn(URPWM,LOW);

Page 23: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 23/24

if(distance==50000) // the reading is invalid. Serial.print("Invalid"); else distance=distance/50; // every 50us low level stands for 1cm return distance;

void carStop() // Motor Stop digitalWrite(speedPin_M2,0); digitalWrite(directionPin_M1,LOW); digitalWrite(speedPin_M1,0); digitalWrite(directionPin_M2,LOW);

void carTurnLeft(int leftSpeed,int rightSpeed) //Turn Left analogWrite (speedPin_M2,leftSpeed); //PWM Speed Control digitalWrite(directionPin_M1,HIGH); analogWrite (speedPin_M1,rightSpeed); digitalWrite(directionPin_M2,HIGH);

void carTurnRight(int leftSpeed,int rightSpeed) //Turn Right analogWrite (speedPin_M2,leftSpeed); digitalWrite(directionPin_M1,LOW); analogWrite (speedPin_M1,rightSpeed); digitalWrite(directionPin_M2,LOW);

void carBack(int leftSpeed,int rightSpeed) //Move backward analogWrite (speedPin_M2,leftSpeed); digitalWrite(directionPin_M1,LOW); analogWrite (speedPin_M1,rightSpeed); digitalWrite(directionPin_M2,HIGH); void carAdvance(int leftSpeed,int rightSpeed) //Move forward analogWrite (speedPin_M2,leftSpeed); digitalWrite(directionPin_M1,HIGH); analogWrite (speedPin_M1,rightSpeed); digitalWrite(directionPin_M2,LOW);

void servoSweep() if(sweepFlag) if(pos>=60 && pos<=120) pos=pos+1; // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' if(pos>119) sweepFlag = false; // assign the variable again else if(pos>=60 && pos<=120) pos=pos‐1; myservo.write(pos); if(pos<61) sweepFlag = true;

Page 24: 4WD Mobile Platform SKU:ROB0022 - RobotShop · 2015-12-30 · STEP1: Assemble Robot 1.Assemble Your Own Motor Look in your parts bag for eight long screws. These are used to fix and

12/30/2015 4WD Mobile Platform SKU:ROB0022 ­ Robot Wiki

https://www.dfrobot.com/wiki/index.php?title=4WD_Mobile_Platform_SKU:ROB0022 24/24

Your own car was born!