本帖最后由 RichardFu 于 2016-4-1 14:59 编辑
视频展示
材料 1. Romeo BLE多合一控制器 (DFR0305) 2. L298N双路H桥电机驱动 (DRI0002) 3. 金属夹持器 (ROB0099) 4. Devastator 履带机器人移动平台(ROB0112) 5. 全方位蜂巢云台 (ROB0114) 6. 云台舵机支架套件 (FIT0004) 7. 7.4V 2200MA 锂电池 (FIT0137) 8. 180度舵机(SER0020) x2 9. 螺纹电机 6V,100rpm 10. 3D打印伸缩臂
简介 创客喜欢用自己的双手进行创作,但有没有想过让自己做的机器人同样拥有动手能力呢?在这个项目里我打算把履带小车结合夹持器做一个有抓取功能的小车。由于装在小车上方难以抓到地面上的东西,因此还需要给小车增加伸缩的功能。我们使用3D打印机打印一个可以伸缩的支架,并找了一个可以配合的螺纹电机来实现伸缩功能。
这个机器人还是个比较粗略的原型,希望由此可以发展出更精密并且也容易制作的机械爪机器人。
制作流程
组装过程: 1.用3D打印机打印伸缩臂的零件,并用螺丝组装起来。另外还打印螺纹电机的支架,把螺纹电机和伸缩臂组装起来。(模型在最后附上) 2.将蜂巢云台装在履带机器人上。 3.在云台上使用舵机支架套件来安装一个舵机。 4.把螺纹电机装在舵机上。 5.把另一个舵机装在夹持器上,使它可以做抓取动作。 6.把夹持器的舵机固定到伸缩臂上。
使用下图进行连接: M1 – 右轮电机 M2 – 左轮电机 数字13 – 电机驱动E1 数字12 – 电机驱动M1 数字9 – 机械臂抬起/降落舵机 数字8 – 夹持器舵机
Vin – 电机驱动VD GND – 电机驱动GND 电机驱动M1 – 螺纹电机 电池 – 控制板电源 电池 – 电机驱动VS和GND
代码
-
- #include <Servo.h>
- #include <Metro.h>
- #include "GoBLE.h"
-
- int speedPin_M1 = 5; //电机1速度控制 M1 Speed Control
- int speedPin_M2 = 6; //电机2速度控制 M2 Speed Control
- int directionPin_M1 = 4; //电机1方向控制 M1 Direction Control
- int directionPin_M2 = 7; //电机2方向控制 M1 Direction Control
-
- int E1 = 13;
- int M1 = 12;
-
- int tGo = 13000;
- int tBack = 13000;
-
- int tCatch = 2000;
- int tRelease = 2000;
-
- bool catched = false;
-
- Servo claw; //claw platform servo
- Servo top; //上层舵机 top servo
-
- int clawPosition = 45; // 45 ~ 100
- int topPosition = 45; //45 ~ 155
-
- int recordPin = 11;
- int playPin = 10;
-
- int joystickX, joystickY;
- int buttonState[5];
-
- bool leftPressed = false;
- bool rightPressed = false;
-
- bool clawMoved = false;
-
- void setup() {
- Goble.begin(); //启动GoBLE
- Serial.begin(115200);
- top.attach(9); // Top Servo– Digital 9
- claw.attach(8); // claw Servo - Digital 8
- top.write(topPosition); //写入起始角度
- claw.write(clawPosition); //写入起始角度
-
- pinMode(11, OUTPUT);
- pinMode(12, OUTPUT);
- pinMode(10, OUTPUT);
- digitalWrite(10, LOW);
-
- digitalWrite(11, LOW);
-
- digitalWrite(12, LOW);
-
- pinMode(13, OUTPUT);
- digitalWrite(13, HIGH);
-
- analogWrite(E1, 0);
- }
-
- void loop() {
-
- if (Goble.available()) {
-
- joystickX = Goble.readJoystickX();
- joystickY = Goble.readJoystickY();
-
- buttonState[SWITCH_UP] = Goble.readSwitchUp();
- buttonState[SWITCH_DOWN] = Goble.readSwitchDown();
- buttonState[SWITCH_LEFT] = Goble.readSwitchLeft();
- buttonState[SWITCH_RIGHT] = Goble.readSwitchRight();
-
-
-
- // Serial.print("Joystick Value: ");
- // Serial.print(joystickX);
- // Serial.print(" ");
- // Serial.println(joystickY);
-
-
- if (joystickY > 196) {
- Serial.println("turn right");
- carTurnRight(250, 250);
- }
- else if (joystickY < 64) {
- Serial.println("turn left");
- carTurnLeft(250, 250);
- }
- else if (joystickX > 196) {
- Serial.println("move forward");
- carAdvance(400, 400);
- }
- else if (joystickX < 64) {
- Serial.println("move backward");
- carBack(400, 400);
- }
- else {
- carStop();
- }
-
-
- if (buttonState[SWITCH_LEFT] == PRESSED && buttonState[SWITCH_RIGHT] == PRESSED) {
- analogWrite(E1, 0);
- if (!clawMoved) {
- if (clawPosition <= 45) {
- clawPosition = 100;
- claw.write(clawPosition);
- }
- else {
- clawPosition = 45;
- claw.write(clawPosition);
- }
- clawMoved = true;
- }
-
-
- }
- else if (buttonState[SWITCH_LEFT] == PRESSED) {
- digitalWrite(M1, LOW);
- analogWrite(E1, 255);
- }
-
- else if (buttonState[SWITCH_RIGHT] == PRESSED) {
- digitalWrite(M1, HIGH);
- analogWrite(E1, 255);
- }
- else if (buttonState[SWITCH_UP] == PRESSED) {
- topPosition -= 5;
- if (topPosition <= 45) {
- topPosition = 45;
- }
- top.write(topPosition);
- }
- else if (buttonState[SWITCH_DOWN] == PRESSED) {
- topPosition += 5;
- if (topPosition >= 155) {
- topPosition = 155;
- }
- top.write(topPosition);
- }
-
- if( buttonState[SWITCH_LEFT] == RELEASED && buttonState[SWITCH_RIGHT] == RELEASED){
- analogWrite(E1, 0);
- }
-
- if( buttonState[SWITCH_LEFT] == RELEASED || buttonState[SWITCH_RIGHT] == RELEASED){
- clawMoved = false;
- }
- }
-
- }
-
- 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);
- digitalWrite(directionPin_M1, LOW);
- analogWrite (speedPin_M1, rightSpeed);
- digitalWrite(directionPin_M2, LOW);
-
- }
-
- void carTurnRight(int leftSpeed, int rightSpeed) { //Turn Right
- analogWrite (speedPin_M2, leftSpeed);
- digitalWrite(directionPin_M1, HIGH);
- analogWrite (speedPin_M1, rightSpeed);
- digitalWrite(directionPin_M2, HIGH);
- }
-
- void carBack(int leftSpeed, int rightSpeed) { //Move backward
- analogWrite (speedPin_M2, leftSpeed); //PWM Speed Control
- digitalWrite(directionPin_M1, HIGH);
- analogWrite (speedPin_M1, rightSpeed);
- digitalWrite(directionPin_M2, LOW);
-
-
- }
- void carAdvance(int leftSpeed, int rightSpeed) { //Move forward
- analogWrite (speedPin_M2, leftSpeed);
- digitalWrite(directionPin_M1, LOW);
- analogWrite (speedPin_M1, rightSpeed);
- digitalWrite(directionPin_M2, HIGH);
-
-
- }
复制代码
实际效果 小车可以用iOS系统的GoBLE软件控制。用左边的遥杆控制小车移动,右边的键控制机械臂升起降落以及伸缩,左右键同时按可以让夹持器夹持或松开。
注意事项 1.螺纹电机转速过慢,可以再尝试一下其它型号。 2.机械臂负重过多,会导致弯曲以及无法伸展。以后可以考虑修改构造把夹持器舵机放到后面。 3.组装时尽量把机械臂放在直立状态。 4.注意将电线和驱动固定,各个连接口打胶。
模型
伸缩臂模型.zip
|