How to make the robot move accurately? Studuino Platform Robotics Overview and Features

image

The organization in which I work was asked to hold a small robotics webinar for the Moscow International Education Salon 2020, which was held in an online format. The topic of the presentation was left to me open and given an educational set on robotics. So I got acquainted with products from the Japanese corporation ArTeC (this is not advertising and I am not an employee of ArTeC - it's just my personal experience from communicating with their products). After the webinar, I decided to write this article, since in Russia kits from Lego Education were quite popular, and this was the first time I came across this Japanese designer.

The article is divided into two parts. The first part will be useful to those who choose a kit for educational robotics. In the second part, I examined the use of a kit to solve an applied problem that may occur in life.

So, if anyone is interested in what kind of robotic kit it is and what can be done with it, I ask for a cat. So let's go!

As a building basis, the designer uses only a few basic parts from which you can assemble quite complex structures.

ArTeC Designer Base Blocks
ArTeC Designer Base Blocks

image
Example Models from Designer Parts

Due to the specifics of the parts - the staggered order of the holes and spikes for the connection, it is not always quick to find the right combination of parts to achieve the result. Of the advantages, unlike Lego: all parts are large enough, losing such a lot more difficult. The second plus is that you don’t have to rummage around in search of the necessary part for a long time, because there are only 5-6 pieces of basic parts (the difference in the color of the parts does not count). There is a minus - as long as the parts are completely new, their separation sometimes turns into torment - so they cling tightly to each other. To help disengage them comes a special tool that is in the kit.

In addition to the basic blocks in the set there are a couple of varieties of wheels and gears, as well as a gear rack.

Now about what is included in the electronic part of this robotic kit. The Japanese website has a fairly large number of different sensors and modules. Of course, I had a lot less of them, but those that were already gave a certain scope for creativity.

For the filling of the main control unit, the Japanese made their version of the Arduino board, finalizing it, and called it Studuino. They added a DC motor control driver to it and brought a line for 3-pin connectors (standard BLS-3, these are placed on servos). On each such connector there is power: plus and minus, as well as one of the pins of the Arduino board. All connectors are signed, so it’s hard to make a mistake when connecting to them.

Studuino Platform
Studuino Platform

For compatibility with standard Arduino shields on standard places, there are connectors similar to Arduino.

The main difference from the Arduino board is that the voltage of the controller is 3.3V. This is explained by the fact that the central control module is supplied with power through the supplied battery compartment for 3 AA batteries (4.5 V in total). The battery, unfortunately, is not provided, it can not even be bought on the manufacturer’s website as an additional option.

The board is located in a plastic case, to which you can attach the base parts of the designer and other elements.

ArTeC Central Unit
ArTeC Central Unit

As actuators, the manufacturer offers two DC motors with gearboxes and up to 8 servo-drives of their own design (their number can vary depending on the kit configuration). Motors are connected through special connectors that are on the board.

DC motors with gears and their connection
DC motors with gearboxes and their connection

It is possible to assemble quite easily and quickly the simplest construction that comes to mind: a robot machine with two motors, controlling which you can make it move in the right direction.

Simple robot machine with two DC motors
Simple robot machine with two DC motors

The engines are controlled by setting the logical states of the terminals D2, D4, D3 for the engine, which is connected to the M1 and D7, D8, D5 connectors for the motor connected to the M2 connector on the Studuino board. It is to these conclusions that the developers of the Studuino board connected in parallel a motor driver driver chip. Using these conclusions by connecting your circuit there, and at the same time using the engines at the same time, will fail.

Consider how to control an engine that is connected to the M1 connector. By setting a different logical state of the terminals D2 and D4, it is possible to achieve rotation of the engine in the desired direction. For example: with D2 - 1 and D4 - 0, the engine rotates clockwise, and if D2 - 0 and D4 - 1, then the engine rotates counterclockwise. It is also necessary to set the motor rotation speed by setting the PWM value at pin D3 - it can be in the range from 0 to 255. If the value is 0, the motor will not rotate, and if the value is 255, we will get the maximum rotation speed. The engine driver also allows an instant change in the direction of rotation of the engine and supports the engine braking mode. To decelerate the engine, the same logical state equal to 1 must be set at terminals D2 and D4.

By the way, there are no D3 and D5 pins in the connectors that have 3 pins (GND, VCC, SIG) on the Studuino board, but they are on the standard Arduino connector, which the developers left to maintain platform compatibility.

Similarly, the motor is controlled, which is connected to the M2 connector. For him, the direction of rotation is specified through the state of the terminals D7 and D8, and the rotation speed by terminal D5.

The simplest program I wrote made the robot machine move like this:


Servos can be connected to the connectors that are highlighted in red on the board: D2, D4, D7, D8, D9, D10, D11, D12.

Servo connection
Connecting Servo Drives

It is on these pins that the AtMega168 microcontroller has a PWM, which is needed to control the servo drives. If you connect the maximum number of servos, you can get some interesting design. For the sake of demonstration, I put together a simple analogue of a walking robot and tried to program it a little bit. The result can be seen in the video:


The only thing to remember is that if you plan to use both DC motors and servos at the same time, then you cannot use 2 DC motors and 8 servos at the same time, since they have common outputs controlled by the microcontroller. You can make the following configurations: 2 DC motors + 4 servos, 1 DC motor + 6 servos or use only 8 servos.

In any robotic kit, in addition to actuators, there must be sensors that are the "eyes" and "ears" of any robot. They are also here. In my set there were the following sensors: a light sensor, a sound sensor, an acceleration sensor, two IR sensors, a touch sensor, as well as LEDs (green, red, blue, white) and a piezodynamic.

Sensors in a set
Sensors in a set

Sensors are connected to the central unit using the cables that come with the kit. To fix the sensors in the robot model on the housings, they have spikes with which they can be attached to the structure. I assembled and programmed a couple of simple designs to look at the operation of the sensors.

This is how the touch sensor works:


And so the light sensor works:


If there are not enough standard sensors in the set and you want to expand its functionality, then you can easily use the solderless breadboard and connect circuits there, just like on a standard Arduino board.

Enhanced Recruitment Features
Enhanced dialing

The next important point for any robotic kit is the availability of a convenient programming environment. Here, the manufacturer offers three different programming options.

Entry level - designed for the smallest users, those who still do not really know how to read, but who are already taking their first steps into the adult world of robotics. For them, the simplest programming environment is offered - the pictogram one.

Icon programming
Icon programming

Here you can pull out pictograms with basic actions into the program (go forward, turn, turn on the LED, etc.) and configure their basic parameters.

When this level is mastered or its capabilities become insufficient to solve the tasks, you can go to the next step and start using the Scratch programming environment for the Studuino platform.

Scratch programming for Studuino
Scratch programming for Studuino

There are already more programming options: you can use variables and arrays, logical and arithmetic expressions, subroutines, as well as more flexibly configure various blocks for execution.

When these capabilities are not enough, you can go on to programming in the Arduino IDE and get full control over all the hardware capabilities of the Studuino platform. To use the Studuino board in the Arduino IDE, you must configure the environment according to the instructions from the manufacturer’s website (so that the environment sees the Studuino platform in the list of supported boards).

Complete with programming software, the manufacturer gives a set of instructions for assembling different models and programming them. The software itself is available for free on the manufacturer's website.

Now let's try to solve a small practical problem using this set.

Imagine that we have a robot that must move forward and backward in the warehouse and we need to make it stop at the given places. If the robot is not controlled, an accident will occur. An example of such an accident is shown here:


Moving the robot forward and backward can be done using DC motors or using servos. Servo drives solve the problem of how to stop the robot in the right place (you can accurately set the angle of rotation of the servo). This solution has a limitation (we will use a servo from a set with a wheel fixed on it) - servos cannot rotate by an angle of more than 180 degrees and thus the movement of our robot will be limited to half the length of the wheel revolution on the servo, but usually you want more.

We will use a DC motor with a reducer from the set to move forward and backward. These motors have no feedback. After starting the engine, we cannot say how far the robot traveled. You can detect the time during which the robot travels the required distance during engine operation and use these delays in the program to stop the robot in the right place. This method has one significant drawback - the engine speed depends on the voltage that is supplied to it and on the required effort. Since batteries are used in the robot, which after a while will be slightly discharged and their voltage will become less, in the same time the robot will begin to travel a shorter distance, and it will be necessary to select the time again.

The simplest option that you can use is a robot, passing the desired point, touches the touch sensor, which will be a stop signal in the right place.

I made changes to my design by adding touch sensors on the robot, and placed elements along the robot path so that the robot touched them with touch sensors when moving.


The video shows that the robot reaches the end of the “warehouse” and touches the “wall” with the sensor, then it goes back to the opposite “wall” of the warehouse and there it also touches. After that, the process is repeated. Thus, there are two points that the robot “knows” for sure - these are the points when the touch sensor is triggered.

Scratch touch program for Studuino
A program with touch sensors in the Scratch language for Studuino

Sometimes this is enough to solve the task. But we want more!

I made changes to the design and program of the robot and this is what I got:


Let's consider in more detail what so much more I decided to demand from the robot. I decided that two breakpoints are not enough for me and I want more. For this, I used an IR sensor, which is included in the kit. I fixed it on a moving platform, and below I arranged a strip of paper with black lines pre-drawn by the marker, on which the robot would have to stop. I also removed one of the touch sensors from the robot (on the right side).

IR Robot
Robot with an IR sensor

As a result, I got a classic diagram of the device of one of the axes of a 3D printer or a CNC machine. When turned on, the printer does not know where it is and goes all the way to one side (until it is touched by the limit switch), and after that it considers this point to zero and starts to count its position on this axis from it.

In this design, the countdown occurs on black stripes on paper. The number of these bands is known in advance, so when you reach the last band, you can return to the zero reference point. The Scratch program for Studuino is presented below.

Scratch IR Robot Program for Studuino
Scratch IR Robot Program for Studuino

If you carefully look at the program, you can see incomprehensible values ​​of 40 and 50, with which the value of the IR sensor is compared. To understand these numbers, you need to remember a little about what signals can be read from different sensors. There are digital and analog sensors. Digital sensors have a fixed number of positions and move from one position to another sharply and without intermediate values. Mostly used sensors with two positions. Touch sensors is the most striking example of a digital sensor: until the sensor is pressed, it gives a logical value of 1, and when pressed - a logical value of 0 (in this constructor and with these sensors this is the scheme, but there are schemes where it is done the other way around: pressed - 1, not pressed - 0).Analog sensors describe some inextricable relationship between the signal and the voltage or current at the output and do not have fixed values. The IR sensor emits an analog light signal, which may depend on various factors, such as ambient light, battery voltage, and even ambient temperature.

The analog signal is linearly converted to a number, for Scratch for Studuino - in the range from 0 to 100. This is done to simplify the work with them to end users (this programming environment was first developed for teaching children). In the Arduino IDE, an “honest” range of values ​​from 0 to 1023 is issued, which corresponds to the 10-bit ADC converter that is present in the Atmega168 controller. If you look at the differences in the graphs between the digital and analog signal, it becomes clear why the analog signal is a range of values.

Analog (left) and digital (right) signal
Analog (left) and digital (right) signal The

infrared sensor, which is used to determine the black tag line, works by the principle of capturing the reflected signal. Two elements can be clearly seen in the figure: IR LED and IR photodetector.

IR sensor
IR sensor

If you put an obstacle in front of the sensor from which IR rays will be reflected, the better they will be reflected from the obstacle (depending on the distance to the obstacle or the type of obstacle), the more they will be picked up by the IR photodetector and the sensor will return more value to the user during his survey.

The numbers 40 and 50 are selected empirically. In my case, the sensor showed, being above a white surface, values ​​of about 65-75. Above the black surface, the sensor returned values ​​in the range of 18-25. The number 40 is the moment when the sensor begins to switch from a white surface to black, and the number 50 is the moment of transition from a black surface to white. These figures are taken with a small margin in order to block the error in the measurement of the sensor. When developing a real design, it is necessary to take into account the conditions under which the sensor will take readings (external lighting, the location of the sensor, etc.), because all these factors will affect the sensor readings. You may have to develop an algorithm for constantly adjusting these values ​​depending on external conditions.

I will summarize a small result. Two possible solutions to the problem of moving the robot around the warehouse were considered. Both of these options required additional external "tags", which guided the robot. Is there any way to do without them? In order for the robot, for example, to know at what angle the motor shaft has turned and, depending on the angle value, has decided to stop or move on. There is a simple solution to this problem - the use of a motor with an encoder (angle sensor).

The set has DC motors with gear, but they do not have an encoder. The idea came to my mind: maybe I could try to make a simple encoder from the parts of the designer, especially since the gears from the set have a fairly large module (tooth size)?

The main elements of the encoder
The main elements of the encoder

The main problem was to choose the location and fix the IR sensor so that it intersects the gear tooth when it rotates. As a result, I got a test design, which is shown in the figure below.

Encoder Test Model
Encoder Test Model

As you can see in the image above, the IR sensor is fixed so that the gear crosses its working measurement area with its teeth during rotation. Opposite (on the other side of the gear) of the IR sensor, I additionally put an obstacle working on the reflection of infrared rays to get more correct data from the sensor. When the gear rotates and the IR sensor measures the signal reflection, there will be large values ​​when there is a tooth in front of the sensor and smaller ones when there is a “hole” between the gear teeth.

The program for working with the encoder is developed in the Arduino IDE. To test the efficiency of my idea, I wrote a simple program that started the engine to rotate at a constant speed and continuously output values ​​from the IR sensor to the debug console.

Program text
#define M1_A        2       //   1   1
#define M1_B        4       //   2   1
#define M1_PWM      3       //       1
#define SENSOR_PIN  A4      //     IR-sensor

void setup() {
  Serial.begin(9600);       //      
  pinMode(M1_A, OUTPUT);    //       " "
  pinMode(M1_B, OUTPUT);    
  analogWrite(M1_PWM, 100); //    
  digitalWrite(M1_A, HIGH); //    
  for (int i=0; i < 2000; i++) {    //   2000    -
    Serial.println(analogRead(SENSOR_PIN));   //      
  }
  digitalWrite(M1_A, LOW);  //   
}

void loop() {
}


According to the data that the program displayed on the console, I got the following graph:

Graph of IR sensor values ​​during gear rotation
Graph of changes in the values ​​of the IR sensor during rotation of the gear

The nature of the graph resembles the shape of the teeth of a gear, which suggests that indeed such data can be used to control the rotation of the engine using the gear from the designer set as an encoder disk. To eliminate “bounce” hysteresis is used, which is implemented as follows (symbols on the graph): MIDDLE is the average value between the maximum and minimum values ​​of the IR sensor readings, WIDTH is the deviation from MIDDLE to a greater or lesser value to create a certain “error band” »Signal measurements (the total width of this band is 2 * WIDTH). MIDDLE and WIDTH will be used in the engine rotation control algorithm. The algorithm for counting the teeth in the gear during engine rotation can be represented as follows:

Algorithm for counting teeth in the gear during engine rotation
Algorithm for counting teeth in the gear during engine rotation.

The algorithm uses the following notation:

  • prev_state - previous gear state;
  • cur_state - current state of the gear;
  • count - the number of gear teeth counted;
  • tmp - IR sensor readings.

The principle of counting gear teeth in this algorithm is based on a constant reading of the readings from the IR sensor and a change in the value of the cur_state variable when the signal level goes over the upper or lower line of the “error band”. If the value goes over the upper limit, then the variable cur_state becomes equal to 1, which means a gear tooth, and when going beyond the lower boundary, the variable cur_state becomes equal to 0, which means a gap between the gear teeth. The addition of the count variable occurs only when the state of the cur_state variable changes.

A program that uses this algorithm is presented below. In it, I described a subroutine that waits until the engine rotates the gear by a predetermined number of teeth and after that transfers control to the main program.

Program text
#define M1_A        2       //   1   1
#define M1_B        4       //   2   1
#define M1_PWM      3       //       1
#define SENSOR_PIN  A4      //     IR-sensor

#define MIDDLE      550     //         
                            // ""
#define WIDTH       50      //      ,   
      //    -     
      // 

int enc_tooth = 0;          // ,    
int cur_state = 0;          //   :  (1)  "" (0)
int prev_state = 0;         //   
int tmp;                    //      

void init_enc() {
  enc_tooth = 0;
  cur_state = 0;
  prev_state = 0;

  //         cur_state
  //    ,   = 1,    ""      
  //   0      
  if (analogRead(SENSOR_PIN)>MIDDLE) {
    prev_state = 1;
    cur_state = 1;
    enc_tooth++;
  }  
}

void wait_by_count(int count) {
  //       count,       IR 
  //           ""
  while (enc_tooth <= count) {
    //    IR-    
    tmp = analogRead(SENSOR_PIN);

    //       +  ,    
    if ((tmp + WIDTH) > MIDDLE) {
      cur_state = 1;
    } else {
    //       -  ,    ""
      if ((tmp - WIDTH) < MIDDLE) {
        cur_state = 0;
      }
    }

    //       ,      
    // ,     ""   -  ""  
    if (cur_state != prev_state) {
    //   ,   0  - ,     
    // 
      enc_tooth += cur_state;
    
    //        
      prev_state = cur_state;
    }
  }
}

void setup() {
  //        
  Serial.begin(115200);

  //        ""
  pinMode(M1_A, OUTPUT);
  pinMode(M1_B, OUTPUT);

  //   
  init_enc();

  //    
  analogWrite(M1_PWM, 100);
 
  //    ,      1 (    
  //  0)
  digitalWrite(M1_A, 1);

  // ,    30  
  wait_by_count(30);
  
  //   
  digitalWrite(M1_B, 1);

  Serial.print("  = ");
  Serial.println(enc_tooth);

}

void loop() {
}


The program starts the engine and waits until the gear rotates by 30 teeth - just such a number of teeth in the gear, and after that it stops the motor. Below is a video that demonstrates the operation of the program:


On a white piece of paper, which is glued to the gear, you can track its rotation by 360 degrees.

On this I want to end this article. In conclusion, I can say that I did not just stop at the encoder model. A full-fledged robot platform was assembled with two motors and two encoders (one for each wheel) and a program was made to synchronize wheel rotation according to encoders, but this is a topic for another article ... A

Robot platform with encoders based on IR sensors
robot platform with encoders based on IR sensors

As an educational designer in robotics, this is a good option for those children (well, adults) who want to join in such classes, especially since the manufacturer did everything to maximize the age range of those who can use this product (the presence of different programming environments ) You can start with the simplest and most elementary elements, and after obtaining basic knowledge, go to another level of development of robotics and electronics.

All Articles