Skip to content

pichim/Mini_Segway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniSegway

The Segway is a robot that has the ability to balance itself using two motors and an IMU sensor. It is controlled with a radio transmitter in two modes, a car where it moves on the ground maintaining three points of support but also as a segway, that is, balancing on two wheels.

Segway
Segway with radio

Table of Contents

  1. Repository structure
  2. Hardware
  3. Prerequisites
  4. User manual
  5. Software
  6. Notes

Repository structure

  • /docs/cad - cad files with division into different extensions, including print-ready STL files and STEP files.
  • /docs/hardware - folder contains all hardware's datasheets and list
  • /docs/matlab - folder contains all development files in matlab
  • /docs/papers - folder contains all scientific papers regarding segway development

Hardware

Mechanical components (ordered) employed in design:

All frame parts 3D models are localized in docs/cad/ folder

The list of eletric components varies from version to version, as a special PCB has been designed to eliminate some of the components and allow the battery to be charged directly on the robot. In the absence of a PCB, a list of stock components is provided.

VERSION WITHOUT PCB

Electrical components and sensors:

The electronics connection is included in the file, which can be found HERE

VERSION WITH PCB

The electronics connection is included in the file, which can be found HERE
All the files related to PCB can be found in docs/segway_charging_board/

Below there is components placement shown:

Front
Front

Back
Back

Prerequisites

  • Mbed Studio
  • Libraries:
    • mbed-os 6.17.0
    • eigen

All the libraries you need are included in the repository. Software is mostly based on files located in /src folder and main logic is included in MiniSegway class that is running in own thread.

User manual

Running the project for the first time

In order to run the project you need to import program to Mbed Studio and follow next steps:

  • as the board is using external power source, board has jumper JP5 switched to E5V postion which requires to first supply board with external power and then plug it in to the computer
  • now program can be compiled and flashed to the board

Using robot

In order to use the robot you must follow the steps below:

  • Start the radio controller that is paired with the receiver on the robot
  • Turn on the power supply on the robot (in this situation both LED, green and blue will start blinking)
  • Arm the radio controler (SD button) (in such case the green LED will start to shine continuously)
  • Then the USER button on the robot can be pressed, which will lead the robot to CAR mode (blue LED will start to shine continuously) [picture below]
  • To use the robot as segway, raise it to a standing position and wait until the robot visibly starts to balance.
  • By default, the robot is in normal mode, however, when you press the button on the radio transmitter (SA button), the robot will go into fast mode, and its speed will be increased (NOTES: In normal mode, the robot is practically unturnable when controlling the radio transmitter (as long as there is no collision, of course), however, in fast mode there is the possibility of such control, which will lead to loss of balance.)

Buttons layout
Button layout

Software

main.cpp

The main.cpp file contains only the declaration of the rc class, which handles communication with the radio transmitter, and the minisegway, which contains all the program logic. Inside the file you can also find the declaration of an additional button that serves as the RESET of the system.

config.h

The config.h file is very important due to the fact that it contains all the declarations of the robot's parameters and the names of the pins used to connect the hardware. Importantly, it also contains options for changing the robot's configuration, i.e. enabling or disabling certain options such as data transfer (over the link or to an SD card), measurements with additional current sensors, or a function for testing the frequency response with a chirp signal. This file should be used for all configurations related to changing the parameters of the robot, changing the parameters of the filters and any changes to the pin maps.

minisegway.cpp

Minisegway is a class that operates in its own thread with a frequency of 1kHz. In it there are declarations of all objects communicating with the hardware that is mounted on the robot. Inside the class you can find the state machine, because as mentioned the robot moves in two modes, as a car or as a segway. The file also includes additional functions, used during debugging and testing of the hardware operation.

IMU

The IMU class is initialized when the MiniSegway class is initialized, the first step that is performed inside the IMU is to configure and check the connection which is signaled by returning the device ID to the output window.The device is then calibrated, with the first thousand measurement points omitted due to the fact that they deviate significantly from the norm and there are fluctuations associated with the initialization process.

In addition, position mapping is performed due to the target position of the robot and the positioning of the IMU on the robot:

  1. Roll Control Advantage: The alignment allows the use of roll for controlling the Segway. Roll control is preferred because yaw control can encounter singularities (undefined or unstable behavior) at angles of ±90 degrees when the Segway is upright.

  2. IMU Orientation:

    • X-Axis: The IMU's x-axis is oriented to point to the left side of the Segway.
    • Y-Axis: The IMU's y-axis is oriented to point towards the back of the Segway.
    • Z-Axis: The IMU's z-axis is oriented to point upwards.

In case of completion of the calibration process, a flag is sent confirming the completion of the process so that further execution of the program in the minisegway class can be executed.

State space controller

This state-space controller is designed to keep a Segway in a vertical position by controlling the robot's velocity input based on various sensor readings and setpoints. The control strategy involves multiple proportional (P) and derivative (D) components applied to different states of the system:

  1. Position Control ( u_p_{pos} ):

    • Proportional Control on Position:
      • robotVelSetpointIntegrator.apply(robot_vel_setpoint(0)) is the integrated velocity setpoint, which essentially gives the desired position setpoint.
      • robot_pos(0) is the current position of the Segway.
      • MINI_SEGWAY_CP_POS_KP is the proportional gain for position control.
      • The difference between the desired position setpoint and the current position is multiplied by the proportional gain to produce the position control effort u_p_pos.
  2. Velocity Control (u_p_{vel} and u_d_{vel}):

    • Proportional Control on Velocity:
      • robot_vel(0) is the current velocity of the Segway.
      • MINI_SEGWAY_CPD_VEL_KP is the proportional gain for velocity control.
      • The current velocity is multiplied by the proportional gain to produce the velocity control effort u_p_vel.
    • Derivative Control on Velocity:
      • acc_x_filtered is the filtered acceleration along the x-axis.
      • MINI_SEGWAY_CPD_VEL_KD is the derivative gain for velocity control.
      • The filtered acceleration is multiplied by the derivative gain to produce the velocity derivative control effort u_d_vel.
  3. Angle Control (u_p_{ang} and u_d_{ang}):

    • Proportional Control on Angle:
      • imu_data.rpy(0) is the roll (angle) of the Segway as measured by the IMU (Inertial Measurement Unit).
      • MINI_SEGWAY_CPD_ANG_KP is the proportional gain for angle control.
      • The roll angle is multiplied by the proportional gain to produce the angle control effort u_p_ang.
    • Derivative Control on Angle:
      • gyro_theta_filtered is the filtered angular velocity (rate of change of angle).
      • MINI_SEGWAY_CPD_ANG_KD is the derivative gain for angle control.
      • The filtered angular velocity is multiplied by the derivative gain to produce the angle derivative control effort u_d_ang.
  4. Combining Control Efforts:

    • The control efforts from the position, velocity, and angle controllers are combined to produce the total control input.
    • The equation robot_vel_input(0) = -1.0f * (u_p_pos - (u_p_vel + u_d_vel + u_p_ang + u_d_ang)) combines these efforts. The negative sign indicates that the control input is used to counteract deviations from the desired state, aiming to keep the Segway upright.

Notes:

In the event that a version of Segway will be assembled that does not have a custom PCB, the arrangement of additional hardware will cause the IMU to be on the other side of the robot. In this case, changes must be made to the software in order for the robot to function properly. In the 45th line of IMU.cpp file located in src folder, is following code, that is working only with the version with custom PCB:

    // segway imu alignment:
    // the alignment was chosen so that roll can be used for controlling
    // the segway since yaw has a singularity at +/-90 deg
    //   when standing upright, the IMU is mounted on the robot with:
    //   - the x-axis pointing to the right
    //   - the y-axis pointing forwards
    //   - the z-axis pointing upwards
    Eigen::Vector3f gyro(m_ImuMPU6500.gyroX, -m_ImuMPU6500.gyroZ, m_ImuMPU6500.gyroY);
    Eigen::Vector3f acc(m_ImuMPU6500.accX, -m_ImuMPU6500.accZ, m_ImuMPU6500.accY);

To match the code to a different orientation of the IMU, i.e., located on the other side of the robot, you need to change the characters of the data coming from each axis as shown in the illustration below.

    // segway imu alignment:
    // the alignment was chosen so that roll can be used for controlling
    // the segway since yaw has a singularity at +/-90 deg
    //   when standing upright, the IMU is mounted on the robot with:
    //   - the x-axis pointing to the left
    //   - the y-axis pointing backwards
    //   - the z-axis pointing upwards
    Eigen::Vector3f gyro(-m_ImuMPU6500.gyroX, m_ImuMPU6500.gyroZ, m_ImuMPU6500.gyroY);
    Eigen::Vector3f acc(-m_ImuMPU6500.accX, m_ImuMPU6500.accZ, m_ImuMPU6500.accY);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published