Walking on Four Legs

by Student Rover Challenge Korea in Workshop > 3D Printing

82 Views, 3 Favorites, 0 Comments

Walking on Four Legs

KakaoTalk_20240609_154335578_01.jpg
Attaching a joystick to a four-legged robot to move it


Supplies

KakaoTalk_20240609_154335578_02.jpg
Servo motor, 3D printer output, jumper wire, joystick

Moving a Four-legged Robot With a Sensor

KakaoTalk_20240609_154335578.jpg

Purpose to use

  1. Connect with the puppy robot to move the legs
  • Use the XYZ axis to move

XYZ axis photo

a photograph of supplies

Making the main body

Attach the acceleration sensor to the best position

Write code {not exact code}

line connection

servo motor GND=Arduino GND VCC=Arduino 5V Signal = Arduino signal pin acceleration sensor GND=Arduino GND VCC=Arduino 5V SCL=A5 SDA=A4

#include <Servo.h>
#include<Wire.h>

const int MPU = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
Servo LF;
Servo RF;
Servo LB;
Servo RB;
Servo LF_d;
Servo RF_d;
Servo LB_d;
Servo RB_d;

// 프로그램 시작 - 초기화 작업
void setup()
{
LF.attach(3);
RF.attach(4);
LB.attach(5);
RB.attach(6);
LF_d.attach(7);
RF_d.attach(8);
LB_d.attach(9);
RB_d.attach(10);
LF.write(90);
RF.write(90);
LB.write(90);
RB.write(90);
LF_d.write(90);
RF_d.write(90);
LB_d.write(90);
RB_d.write(90);
Serial.begin(9600); // 시리얼 통신 초기화
Serial.println("Arduino Examples - GY-521 Gyro& Accelator (MPU-6050) Module");
Serial.println(" <http://docs.whiteat.com/?p=2662>");

Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);

// gyro scale
Wire.beginTransmission(MPU);
Wire.write(0x1B); //
Wire.write(0xF8); //
Wire.endTransmission(true);

// acc scale
Wire.beginTransmission(MPU);
Wire.write(0x1C); //
Wire.write(0xF8); //
Wire.endTransmission(true);

}

void loop()
{


Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU, 14, true); // request a total of 14 registers
AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

/*
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp / 340.00 + 36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(333);
*/

int xAxis = (AcX - 1090);
int yAxis = (AcY - 930);
int zAxis = (AcZ - 1000);

Serial.print(xAxis);
Serial.print(" ");
Serial.print(yAxis);
Serial.print(" ");
Serial.print(zAxis);
Serial.println(" ");

delay(50);

if (AcX>0)
{
LF.write(135);
LF_d.write(135);
LB.write(135);
LB_d.write(0);
delay(1000);
}
else
{
LF.write(90);
LF_d.write(90);
LB.write(90);
LB_d.write(90);
delay(1000);
}

if (AcY>15)
{
RB.write(45);
RF.write(45);
RF_d.write(45);
RB_d.write(180);
delay(1000);
}
else
{
RB.write(90);
RF.write(90);
RF_d.write(90);
RB_d.write(90);
delay(1000);
}

if (AcZ>15)
{
LF.write(135);
LF_d.write(135);
RB.write(45);
RF.write(45);
delay(1000);
}

else
{
LF.write(90);
LF_d.write(90);
RB.write(90);
RF.write(90);
delay(1000);
}

}


Write Another Way

KakaoTalk_20240609_154335578_03.jpg

## Change of plan

Change from acceleration sensor to joystick. picture

line connection

servo motor GND=Arduino GND VCC=Arduino 5V Signal = Arduino signal pin joy stick GND=Arduino GND VCC=Arduino 5V VRX=A0 VRY=A1 SW=Signal No. 2 code

//조이스틱으로 서보모터 제어하기
#include <Servo.h>

Servo LF;
Servo RF;
Servo LB;
Servo RB;
Servo LF_d;
Servo RF_d;
Servo LB_d;
Servo RB_d;
int kpin = 7, xpin = A0, ypin = A1;
int servoPin = 2, angle = 90;

void setup() {
LF.attach(3);
RF.attach(4);
LB.attach(5);
RB.attach(6);
LF_d.attach(8);
RF_d.attach(9);
LB_d.attach(10);
RB_d.attach(11);
LF.write(90);
RF.write(90);
LB.write(90);
RB.write(90);
LF_d.write(90);
RF_d.write(90);
LB_d.write(90);
RB_d.write(90);
pinMode(kpin, INPUT);
digitalWrite(kpin, HIGH);
}

void loop() {
//스위치 및 X, Y 축 값 읽어오기
int swValue = digitalRead(kpin);
int xValue = analogRead(xpin);
int yValue = analogRead(ypin);



if (xValue>200)
{
LF_d.write(135);
RF_d.write(45);
LB_d.write(135);
RB_d.write(45);

}
else
{
LF_d.write(0);
LF.write(0);
RF_d.write(180);
RF.write(180);
delay(250);
LB_d.write(0);
RB_d.write(180);
delay(250);


}

}


Broken Part

My right leg is broken while walking on all fours and I am in the process of repairing it.

Reason: The soul of the servoter

My leg was separated when I fell.

Last

I fixed my broken leg last time and it is moving well now.

And a problem arose.

The point is that the angles of the servo motors are all different and there is a slight delay when moving.