Project Goals

The goal of the project was to create a device that could climb, move vertically up, on the pipe.

Mechanical Part:

-Built from Lego, including motors and sensors.

-Keeps given position on the pipe.

-Move up on pipe with a specific diameter.

-Stops near bottom/upper part of the pipe.

-Follows hand up and down.

Software Part:

-C programming language with Husarion/Lego libraries.

-The microcontroller is a Husarion RoboCore.

-Raspberry Pi 1 to create access point n order to control robot on distance.

-Must take the input from the sensor and decide where it should stop.

-Measures heights of its position on the pipe.

-Operating module: Manual, Automatic.

Manual module:

-Controlling from the computer by key commands such as tightens connecting part by decreasing its length, releases connecting part, makes robot to move up and stops all motors.

-Follows hand on the pipe.

Automatic module:
-Stops at bottom and up position of the pipe.

-Stops if not receives commands from Raspberry Pi.

-Holds given position.

Design:

The robot is made up of 3 motors, 1 ultrasonic sensor and 1 RoboCORE connected by Lego briks. Two motors are used to rotate wheels which make robot move up on the pipe. The third motor is used to provide tension to increase friction between wheels and the pipe. Ultrasonic sensor used to measure the distance below robot.

Source code can be found below, as well as in attached files.

main.cpp

#include <hFramework.h>
#include <stdio.h>
#include <DistanceSensor.h>
#include <vector>
#include <ctype.h>
#include <cmath>
#include <Lego_Touch.h>


// screen /dev/ttyUSB0 460800

using namespace hFramework;
using namespace hModules;
using namespace hSensors;

int zmax = 170;
int zmin = 15;

void stop(){
    hMot1.setPower(0);
    hMot3.setPower(0);
    hMot6.setPower(0);
}

int get_number(){
	char c  = getchar();
	int total = 0;
	std::vector<int> numbers;
	while(c != 'c'){
		int digit;
		printf("%c", c);
		digit = (int) c - '0';
		numbers.push_back(digit);
		c = getchar();
	}

	for(int i = 0; i < numbers.size(); i++){
		printf("%d\r\n", numbers.at(i));
		total += numbers.at(i) * pow(10,(numbers.size()-i-1));
	}
    printf("%d\r\n", total);
    return total;
}

void go_to(DistanceSensor &sens, int height){
    int dist = sens.getDistance();
    if(dist < 0) return; // remove -1 value of readout

    if(abs(dist - height) > 10){ // asume 10 units error
        if(dist < height && dist < zmax){ // case where robot is lower than goal height
            hMot1.setPower(1000);
            hMot3.setPower(1000);
        }else if(dist > height && dist > zmin){ // case where robot is higher than goal height
            hMot1.setPower(-200);
            hMot3.setPower(-200);
        }else{
			stop();
		}
    }else{
        stop();
    }
}

void hMain(void)
{
	//initialize
    sys.setLogDev(&Serial);
    DistanceSensor sens(hSens2.getBaseSens());
	//infinite loop
    while (true)
    {
        printf("read: ");
        char c = getchar(); //program locks at this moment
                            //awaits of input
                            //requires cyclic commands from external program
        printf("%c", c);
        if(isalpha(c)){
            printf("\r\nok\r\n");
        }else{
            printf("\r\nwrong command\r\n");
            continue;
        }
        printf("number: ");
        int number = get_number();

       if(c == 'p'){
			// z up
			int dist = sens.getDistance();
			if(dist == -1){
				continue;
			}

			if(dist < zmax){
				hMot1.setPower(number);
            	hMot3.setPower(number);
			}else{
				hMot1.setPower(0);
            	hMot3.setPower(0);
			}
        }else if(c == 'o'){
            // z down
			int dist = sens.getDistance();
			if(dist == -1){
				continue;
			}

			if(dist > zmin){
				hMot1.setPower(-number);
				hMot3.setPower(-number);
			}else{
				hMot1.setPower(0);
            	hMot3.setPower(0);
			}

        }else if(c == 'w'){
            // tighten lock
            hMot6.setPower(500);  
        }else if(c == 's'){
            // release lock
            hMot6.setPower(-500);
        }else if(c == 'm'){
            // go to height
            go_to(sens, number);
        }else if(c == 'q'){
            //stop all motors
            stop();
        }else{
			stop();
		}
    }
}

CMakeList.txt

cmake_minimum_required(VERSION 2.8)

project(ARoboCoreProject NONE)

set(PORT "stm32")

set(BOARD_TYPE "robocore")

set(BOARD_VERSION "1.0.0")

include(${HFRAMEWORK_PATH}...
Read more »