Control the Rollarm

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp

There are two ways to control the Rollarm: manual control (by handle), or PC control (by Labview). The detailed operations for two ways are as follows.

6.1  Manual Control

Step 1: Run the Rollarm.ino file under the path DIY Control Robot Arm kit for Arduino-Rollarm\Arduino Code. There are four code files in Rollarm, and you need to double-click Rollarm to open the four simultaneously. Rollarm.ino is the main program, when the others are subprograms.

When you open the main program, the subprograms will be opened automatically:

Step 2: Select the corresponding board and port, then click Upload.

Step 3: After the code upload, turn the power switch on, then we can try to control the Rollarm.

Step 4: Rotate the four potentiometer buttons in different colors to try the controlled servo and direction: the white button to control the Servo 4, the yellow to Servo 3, the orange to Servo 2, and the red one to control Servo 1.


6.2  Automatic Control

With the handle, the Rollarm can record its behaviors:

Rotate one potentiometer button to control one servo to the desired position, and press the yellow button shortly to let the control board record this step. Record the rest steps in this way.

When all the steps are done, press and hold the yellow button for a while (3s). So it will repeat the recorded steps (Rollarm can record at most 100 steps because of the control board’s memory limit).

Thus we can make it automatically carry blocks continuously:


6.3  Code Explanation

The program includes three parts: rotating the potentiometers to control the Rollarm, pressing the button slightly for less than one second to record Rollarm’s behaviors and pressing the button for a relatively longer time to make Rollarm repeat the recorded steps.

There are four potentiometers to control the arms. The 4 servos from top to bottom are connected to port 4-7 respectively of the expansion board, and the 4 potentiometers control the ports accordingly. In other words, spin the white potentiometer to control the uppermost servo, the yellow to control the next servo below, the orange to control the next servo, and the red one to control the bottom servo.

Since the Rollarm has four servos acting as the moving joint, we need to include a header file for driving the servos and define them.

// Create servo object to control a servo.#include <Servo.h> Servo Servo_0;Servo Servo_1;Servo Servo_2;Servo Servo_3;

After defining the function of driving the servos, we need to read the AD value of the potentiometers and convert it into the rotating angle of the servo since the servos are controlled by rotating the potentiometers.

//Read the values ot the potentiometers.void ReadPot(){  SensVal[0] = 0;  SensVal[1] = 0;  SensVal[2] = 0;  SensVal[3] = 0;   SensVal[0] = analogRead(A3);  SensVal[1] = analogRead(A2);  SensVal[2] = analogRead(A1);  SensVal[3] = analogRead(A0);} //The value of the potentiometer is matched to the angle value.void Mapping0(){  SensVal[0] = map(SensVal[0], 0, 1023, 10, 170);  SensVal[1] = map(SensVal[1], 0, 1023, 10, 170);  SensVal[2] = map(SensVal[2], 0, 1023, 10, 170);  SensVal[3] = map(SensVal[3], 0, 1023, 100, 175);}

After compiling the program, we need to make Rollarm remember the steps, which is done through pressing the button.

//Calculate the time the button  pressedvoid Button(){  if (digitalRead(3) == 0)  {    delay(10);    if (digitalRead(3) == 0)    {      KeyValue = 0;      while (!digitalRead(3))      {        KeyValue++;        delay(100);      }    }  } }

We can tell which part of the code the Rollarm is performing by reading the value upon pressing the button. When the value is larger than 10, it means Rollarm is repeating the steps. When it is between 0 and 10, it means Rollarm is remembering. And when it is 0, it means Rollarm is being controlled by the potentiometers. The specific program is as follows:

//Check the button.  static int Flag = 1;  Button();   //The time of pressing the button is not long then record the action.  if ((KeyValue < 10) && (KeyValue > 0))  {    KeyValue = 0;    Record();    Mapping1();  }  //Long press the button and open the auto mode ,start repeating the action.  else if (KeyValue > 10)  {    if (Flag == 1)    {      Flag = 0;      Calculate();    }    Drive_init();    delay(3000);    for (int i = 1; i < Time; i++)    {      Drive_repeat(i);      delay(500);    }  }  //Did not press the button , open the manual mode.  else  {    ReadPot();    Mapping0();

Next, we are going to call the function to write the value of the servo rotating angle. However, it is not merely about writing the values directly; the difference between two adjacent rotating values will also be written into the servos. Here we take a servo program for example.

//The first axis.  if (Dif0[n] > 0)  {    for (int j = Joint0[ 1]; j <= Joint0[n]; j++)    {      Servo_0.write(j);      delay(10);    }  }  else  {    for (int j = Joint0[ 1]; j >= Joint0[n]; j–)    {      Servo_0.write(j);      delay(10);    }  }

6.4  PC Control (by Labview)

6.4.1  Installing Labview Software

For this kit, we use the Labview software for control on PC. If you have other better options, welcome to share by post under FORUM on our website

Download the Labview package in the link below:

After downloading, unzip and open it. If you haven’t installed the Labview Runtime, you can get into the Labview\Rollarm Project\Rollarm Installer folder, install the setup file:

If you have installed the Labview Runtime, you can just get into the Labview\Rollarm Project\Rollarm folder, double click the Rollarm file:

The following interface will show up.

6.4.2      Running the Labview

Before running the software on the computer, we should install a driving program into Arduino. Open the folder LIFA_Base under path DIY Control Robot Arm kit for Arduino-Rollarm\Arduino Code

Open the file LIFA_Base.ino. Upload the sketch to the Arduino. DO NOT unplug the USB cable at the moment. Open the software, which includes two parts: manual control and automatic control.

1)    Manual Mode

a)   See the interface of manual control below. After the Labview is installed and run, this mode is enabled by default.

b)   Click the menu downlist icon for Serial Port, select the port according to your COM port. Here is COM1, which varies for different computers.

The interface is as follows:

If such an icon appears before the port, it indicates something goes wrong with the port:

To solve the problem, just replug the USB cable. Then start from sketch upload again.

Select the Board Type and Connection Type, here we take Uno and USB connection type as an example:

c)  There are three small icons at the top left. Click the middle one to run the software.

Then the three icons will change to the state below:

The initial position of the four axes is respectively set to 90°, 90°, 90°, and 150° from bottom to top, so the corresponding servos should be like as shown below:

d)   Click Start, and the button will change from dark to light green, as shown below:

You can move the slider on the window to control the Rollarm. On the right, there are 4 dashboards, 1, 2, 3 and 4, which correspond to the four servos respectively from bottom up.

2)    Automatic Mode

You can also switch between manual control and automatic control through the rocker switch between Manual and Auto. To switch to the automatic control, you need to click the Start button to disable it and the following interface will appear.

Fill the value of the rotating angle of the servos into the table under Auto Mode one by one. Enter the interval time below the table. The first interval time refers to the time between setting the rotating angles of two groups, each row considered as a group. Here the interval time on the left refers to the time between setting the rotating angle between M4 in row 1 and M2 in row 2 or M4 in row 2 and M1 in row 3…etc. The interval time on the right refers to the one between setting the two adjacent rotating angles within a group. After filling the figures, click the Start button.

Rollarm will then perform as you just set. Note that the range of the data for Mode 4 is 90~180. Otherwise, it will be stuck and damaged.