Pasindu Liyanage
Created December 1, 2019 © GPL3+

Fall Prevention Robotic Attachment

What if you can use advanced AI and Robotics to Prevent someone from falling and get back up.

IntermediateFull instructions providedOver 1 day38

Things used in this project

Hardware components

STMicroelectronics STM32F103RB
×1
Arduino Nano R3
Arduino Nano R3
×1
LDX 227 Servo
×1
LDX 218 Servo
×1
6 DOF Sensor - MPU6050
DFRobot 6 DOF Sensor - MPU6050
×1
Humanoid Robot Kit
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Robot STM Circuit

Code

Basic Logic

Arduino
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>

void gyroInit() {
  //MPU6050 configure
  Wire.begin();
  accelgyro.initialize();
  accelgyro.setFullScaleGyroRange(3); //Set angular velocity range
  accelgyro.setFullScaleAccelRange(1); //Set acceleration range
  delay(200);
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);  //Get current axis data to calibrate
  ax_offset = ax;  //X-axis acceleration calibration data
  ay_offset = ay;  //Y-axis acceleration calibration data
  az_offset = az - 8192;  //Z-axis acceleration calibration data
  gx_offset = gx; //X-axis angular velocity calibration data
  gy_offset = gy; //Y-axis angular velocity calibration data
  gz_offset = gz; //Z-axis angular velocity calibration data
}

void update_mpu6050()
{
  static uint32_t timer = 0;
  static uint8_t index = 0;

  // put your main code here, to run repeatedly:
  if (timer > millis())
    return;
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  //timer = millis() + 10;
  ax0 = ((float)(ax)) * 0.3 + ax0 * 0.7;  //Filter the read data
  ay0 = ((float)(ay)) * 0.3 + ay0 * 0.7;
  az0 = ((float)(az)) * 0.3 + az0 * 0.7;

  ax1 = (ax0 - ax_offset) /  8192.0;  //  Correct and convert to multiples of gravity acceleration
  ay1 = (ay0 - ay_offset) /  8192.0;
  az1 = (az0 - az_offset) /  8192.0;

  gx0 = ((float)(gx)) * 0.3 + gx0 * 0.7;  //Filter the read angle
  gy0 = ((float)(gy)) * 0.3 + gy0 * 0.7;
  gz0 = ((float)(gz)) * 0.3 + gz0 * 0.7;

  gx1 = (gx0 - gx_offset);  //Corrected angular velocity
  gy1 = (gy0 - gy_offset);
  gz1 = (gz0 - gz_offset);

  /////Average processing
  aax2[index] = ax1;//replace value
  aay2[index] = ay1;
  aaz2[index] = az1;
  ggx2[index] = gx1;
  ggy2[index] = gy1;
  ggz2[index] = gz1;
  index++;//Multiple sets of indices move down to easily replace the oldest value,
  if (index > 4)
    index = 0;
  for (int i = 0; i < 5; i++) { //Sum
    ax1 += aax2[i];
    ay1 += aay2[i];
    az1 += aaz2[i];
    gx1 += ggx2[i];
    gy1 += ggy2[i];
    gz1 += ggz2[i];
  }
  ax1 = ax1 / 5.0; //Average
  ay1 = ay1 / 5.0;
  az1 = az1 / 5.0;
  gx1 = gx1 / 5.0;
  gx1 = gy1 / 5.0;
  gx1 = gz1 / 5.0;

  //   Serial.print("aax2[]:"); Serial.println(aax2[i]);
  //   delay(500);

  //Complementary calculation of x-axis inclination
  radianX = atan2(ay1, az1);
  radianX = radianX * 180.0 / 3.1415926;
  float radian_temp = (float)(gx1) / 16.4 * 0.02;
  radianX_last = 0.8 * (radianX_last + radian_temp) + (-radianX) * 0.2;

  //Complementary calculation of Y-axis inclination
  radianY = atan2(ax1, az1);
  radianY = radianY * 180.0 / 3.1415926;
  radian_temp = (float)(gy1) / 16.4 * 0.01;
  radianY_last = 0.8 * (radianY_last + radian_temp) + (-radianY) * 0.2;

}

Credits

Pasindu Liyanage

Pasindu Liyanage

3 projects • 23 followers
Electrical and Electronics Engineering Undergraduate

Comments