Poor Man's Robot - Remote Control

by wolf2018 in Circuits > Robots

1518 Views, 16 Favorites, 0 Comments

Poor Man's Robot - Remote Control

RemoteControlTitle.png

The Poor Man's bi-ped Robot - using RP2040 and Micropython project consists of three instructables:

  • Poor man's bi-pedRobot Hardware describes how to build the robot hardware and documents the electronics to run the servos which move the robot.
  • Poor man's bi-ped Robot Controller describes the software which is running on the robot electronics to make the robot walk.
  • Poor man's Robot Remote Control (this instructable)describes the User interface to program the robot to walk a certain distance and control the parameters, which influence the way the robot walks.


This Poor man's bi-ped Robot Remote Control instructable describes how to control Robi, the bi-ped robot, using a Web User Interface (WebUI) to connect to Robi's Web server. With the WebUI Robi can be programmed to walk a certain distance, set parameters, which influence the way the robot takes steps, and displays status information received from Robi.

To debug or extend the WebUI at least some basic Python programming experience is needed to understand how the software is working, esp. some understanding of the code is needed to debug and resolve issues which you might encounter.

The software provided is a starting point and by no means is a complete robot remote controller, it is shared with the hope to be a helpful resource for your robot projects.

Have fun reading on - and if you have questions or improvement ideas - feel free to add a comment below.

Remark: In this instructable Robi (the name of the robot) is used synonymous to the robot controller

Supplies

controller.png

The Python environment

The WebUI is implemented in Python using Python version 3.9.7 with tkinter package installed. It typically runs on a PC or a Rapberry Pi. How to install Python and the tkinter module on Linux or Windows I did describe in detail in this instructable. If you are familiar to Python programming I recommend to use a virtual environment with python version 3.9.7.

A biped robot hardware with a robot controller to connect to.

The WebUI connects to the Web API (server) of the robot controller running on an RP2040 based picoW board. You can find the description of the robot controller in the Poor man's bi-ped Robot Controller instructable.

Update of the Robot Controller Software

With the development of the WebUI some of the modules for the robot controller have been updated.

Download the last recent version of the robot controller modules attached here and copy them to the robot controller. See Poor man's bi-ped Robot Controller instructable Step 8 Installing the robot control software for more details.

Remark: the files robi_def.py, pio_pwm.py, calc_angle.py, wifiConnect.py are needed as well. If you did not download them yet, please go to the instructable and download them as well.

Recomendation: Do not copy main.py to the controller yet. If there is already a main.py, delete it from the robot controller. This way the robot controller does not start automatically at power on so you can start it manually.

Installation and First Test

WebUI.png
user_variables.png

Installation of the WebUI:

After installation of Python and the tkinter module, copy the attached python program to a working directory on your computer.

Open a console (terminal window) and change to your working directory. The WebUI is started in your working directory with the command: python ./Robi_Ui.py

Once the program is running it should display the user interface as shown in the picture. At this point the WebUI is not yet connected to Robi's server.


Helpful Hints:

  • Should you have both python 2 and python 3 versions installed on your computer please use: python3 ./Robi_Ui.py
  • The robot controller receives an IP address from the WLan router. If you set the WLan router to always assign the same IP address for the robot controller, you can program this address as default, which avoids that you have to enter the IP each time you start the WebUI. Open file Robi_Ui.py with your editor, find the line starting with server = (see picture) and overwrite the IP address (do not change the port).
  • Make sure the computer and the robot controller are in the same network (sub-net).
  • In the same file Robi_Ui.py, a few lines above the server IP setting, you can change the debug level. Find the line starting with debug = (see picture). By default it is set to 1. If you run into errors you can set it to 2 to get full debug output. When you are ready to use the WebUI you can set it to 0 to minimize the debug output. Debug information is printed to the console window from which you started the WebUI.

Downloads

First Tests

Robi_startup.png
browser_input.png
Robi_Ui_connected.png

Starting the robot controller

For a first test, I recommend to connect the robot controller to your computer using an USB cable and start the robot controller manually using your favorite IDE. See the Poor man's bi-ped Robot Controller Step 6 Development Environment for suggestions.

To start the robot controller manually, at the micropython prompt enter >>> import robi_web

This way you get all debug output in your IDE's console or terminal window. See attached picture for a typical output to the console at start-up of the robot controller.

Find the IP-address:port printed out by the robot controller in the terminal window you started, e.g.

* Running on http://192.168.1.79:8081/

and enter the IP address:port in a browser window. The robot controller should respond with its status information, e.g. {"battery": 3.624792, "memory": 121200, "action": "stop", "message": "none", "w_status": "stop"}.

If you see this status information the robot controller's server is working fine.


Starting the webUI

Start the WebUI with the command: python ./Robi_Ui.py (use: python3 ./RobiUi.py should you have both python 2 and python 3 versions installed on your computer).

Enter the IP-address:port, press set IP:port button, then press button initialize. Remark: if you entered the IP address already as default in the software (see Helpful hints: in Step 1), you do not need to press set IP:port, you can press initialize right away.

The robot controller will report out the communication details and steps it takes and the WebUI should display status: ready, a battery voltage (if implemented in your hardware), free memory. You should see the initial parameters as set up by the robot controller (see picture).

The WebUI will report out the steps in the terminal window you used to start the WebUI.

If something goes wrong it will be reported by the robot controller and the WebUI in their respective terminal windows.

Once everything is working well, as a last step copy the file main.py to the robot controller. If done the robot controller will start automatically when you power on the robot.

Remark:

If you use a virtual environment you can automate the activation of the virtual environment and the program start with a simple shell script. For example: I am using the anaconda frame work for virtual environments. Find attached the file startUI.txt for reference. This is a shell script, which you can modify to meet your setup.

If you need to reset the RP2040 during testing you can avoid unplugging the USB cable all the time by adding a reset button to the picoW board. See the How to add a reset button web site of the Raspberry Pi foundation.

Downloads

The WebUI Sections and Typical Usage

WebUIsections.png
RobiControlDiagram.png

The WebUI contains three sections indicated by different background colors.

Please refer to the attached picture.

  • Connection and Status (grey background color)

Contains the basic functions to manage the connection to Robi's web server. You can enter Robi's IP address (Robi received from your WLan router) and the port. By default the port is 8081.

The button initialize establishes the connection to Robi's server and initializes the robot controller, disconnect closes the connection to the robot controller. The field Robi status msg displays the status received from Robi. There are fields to display Battery voltage, free memory and the http status of the last request.

  • Walking planning and actions (green background)

Contains the functions to set up the walking planning values using sliders. You start actions using radio buttons. Status of the walking enging is displayed right after the radio buttons.

Walking planning values are transferred to Robi by pressing the load values button and in the last column the actual values stored in the robot controller are displayed. Remark: Only the actual values are used for calculating a walking pattern.

  • Robi Parameters (white background)

Contains sliders to adjust the parameters used for walking planning. The button transfer sends the parameters to the robot controller.

The last column Robi parameters displays the actual parameters stored in the robot controller. Remark: Only the actual parameters are used when calculating a walking pattern.

Typical usage:

The high level flow diagram of the robot controller is attached here for your reference.

  1. Initialization: Power up the robot to start the robot controller. Start the WebUI (see Step 1) enter the correct IP adress and press initialize. The connection to Robi is established and Robi should stand upright.
  2. (Optional) Load the parameters to Robi by pressing the load values button. The parameters depend to a high degree on the hardware, adjust the parameters as needed. Default values are transferred during initialization.
  3. Set walking planning values: Use the sliders to set the target distance Robi should walk and the width of a single step. Press the load values button.
  4. Actions are triggered by pressing one of the radio buttons. The same radio button, esp. walk, can be pressed multiple times to repeat the action.
  5. ready: moves the CoM down to the position for walking
  6. walk: triggers the calculation of the walking pattern and starts the walking engine, Robi will walk the number of steps to make the target distance.
  7. stand: move Robi to the upright (resting) position.
  8. stop: de-initializes the servos and stops the robot controller
  9. Disconnect: stops the WebUi's lifetick. Remark: Disconnect will not shut down the robot controller. You can press initialize again to connect.
  10. Close the program by pressing the button (x) at the top right corner of the window.

The functions of each section are explained in more detail in the next steps.

In short the Web UI will connect to the robot controller and send requests to set parameters and values (data), used for walking planning, and send the actions Robi should perform.

How to Use Connection and Status

ConnectionAndStatus.png
onboard_led.jpg

Connection and Status functionality:

Connection functionality:

  • IP address:port Enter the IP address the robot controller received from your WLan router. By default the port is 8081. To activate an IP address entered press the button set IP:port.
  • The button initialize establishes the connection to Robi's server and initializes the robot controller, which results in Robi standing up straight. Caution: this will move Robi's servos to the neutral position right away. Make sure the servos can move the legs freely (not blocked) and Robi does not fall to the floor while initializing.
  • Disconnect will close the connection to Robi and stop the life tick. A disconnect will not impact the robot controller. When closing down, it is good practice to use a stop action to shut down the robot controller before disconnecting. Remark: As long as the robot controller is not shut down, initialize can be used to re-connect.

Status fields:

  • The field Battery voltage displays Robi's battery voltage (if you did implement this in the hardware). This should be monitored while Robi is in use to avoid depleting the battery below 3.3V (see your batteries specification).

The background color of the battery voltage field will be set to indicate the state of charge:

  • green for battery voltage > 3.85V ---> charge >70%
  • yellow for battery voltage between 3.85V and 3.6V ---> charge between 70% and 50%
  • amber for battery voltage between 3.6V and 3.3V---> charge between 50% and 20%
  • red for battery voltage below 3.3V ---> charge below 20%

Remark: If you power the Rp2040 picoW board using the USB connection, the battery voltage will show VSYS of the pico board instead of the battery voltage.

  • The field free memory is implemented to monitor RP2040's memory. This is not critical when running the robot controller only, but additional functionality (e.g. voice controlled commands, gestures, speech) might consume substantial memory.


  • Robi status msg displays the status, warning, error messages received from the robot controller


  • Life tick: The WebUI sends a GET request every ~3 seconds to request status from Robi. Robi returns battery voltage, walking status, free memory, walking action status to the WebUI and toggles the onboard LED. The corresponding fields are updated with data received. Life tick period can be changed. Open file Robi_Ui.py with your editor, find the line starting with lifetick_time = (see picture in Step 1: Installation) and enter the time in seconds (default is 3s).
  • If you want to use an "external" LED, connect the LED (with a ~300 Ohm resistor in series) to a free GPIO port and update the file cfg.py of the robot controller, where the Pin for the LED is defined. Find line starting with pico_led = and replace the string "LED" with the number of the GPIO pin you use.

Walking Planning and Execution

WalkPlanAndActions.png

Walking Planning:


Target distance is the total distance Robi should walk. It is measured in centimeter [cm]. For now it is limited to 20cm, so the WebUI works even in case Robi has still cables connected. It can be changed to any number by changing the slider maximum value in the program. To do so, open the file Robi_Ui.py and find the line target_distance_max= and change the value to whatever you desire.

Single step width is the distance Robi takes doing one step. This value is dependent on the robot hardware, see Poor man's bi-ped Robot Controller Step 5: Basics: Walking Pattern Generation for more details. For Robi the upper limit is 4cm. Should you want to change it open the file Robi_Ui.py and find the line step_width_max= and change the value to whatever you desire. Remark, keep in mind that the step should not be larger as the supporting leg. We move the CoM with the moving leg and if the Com goes beyond the supporting leg Robi will tilt and probably fall.

Leading leg can be Left or Right. Remark: Only Left leg leading is implemented for now. If you chose R, nothing will happen.

Remark: When the program starts the sliders show the max values . Once the sliders are moved the actual value of the slider is shown.


Execution actions:

Currently four actions are implemented. It is assumed that the walking planning values have been set and loaded to Robi. The actions are described in the typical sequence of usage:

  1. Ready will move the CoM of Robi to the value set in parameters. Typically the ready position is the starting and ending point for a walking action.
  2. Walk triggers the robot controller to calculate the walking pattern and then execute the pattern. Please refer to Poor man's bi-ped Robot Controller Step 5: Basics: Walking Pattern Generation for more details. The walk action can be repeated as many times as the user wants by pressing the walk button again, after the previous walk has been completed.
  3. Stand moves Robi to an upright standing position. This corresponds to the init position and should be the resting position before e.g. a stop action.
  4. Stop de-initializes the state machines for the servos and ends the robot controller program.


Remarks:

  • Action walk will start walking pattern calculation using the actual parameter values. They are set to default values when the robot controller is initialized. If you want to use different parameters you need to do the change in the WebUi and then transfer them before a walk action.
  • As of current implementation the robot controller uses one core of the RP2040 only, which means an action has to be completed before another action can be requested. Once the controller uses both cores, this might change and actions might be buffered and executed one after the other.

Setting the Parameters

parameters.png

Parameters:

Parameters can be used to optimize the way how Robi walks. Additionally most of the parameters depend on the robot's properties, such as leg length, the max and min angles the servos can move a limb, the speed of the servos and many more. Start with the default values and then optimize each parameter step by step.

micro step width [cm]: As explained in the instructable Poor man's bi-ped Robot Controller Step 5: Walking Pattern Generation, a step is split into multiple micro steps to enable a smooth walking pattern. A good range is 0.2 to 0.5. Divide step size by micro step width and you get the number of micro steps executed to make a full step. In general: Smaller micro steps make for a smoother walking pattern, but take more time to execute, which means Robi is on one supporting leg for a longer time. If Robi tilts too much while walking slightly increase the micro steps.

friction [%]: Friction (too much or not enough) causes Robi to not reach the programmed distance. This parameter can be used to compensate this effect. (Friction is not yet implemented.)

Delay [ms]: Robi is walking with one speed only, which typically is pretty fast. To allow for speed adjustments and slower movement the delay will be inserted between each micro step to slow down the movement. One other use case: Depending on the torque of the servos and the inertia of the robot hardware, a delay might be needed to allow the servos to reach their programmed position for each micro step. See a Remarks below for more on walking speed.

CoM height: The height of the center of mass (CoM), which is used during walking. The ready command will move Robi to CoM height set by this parameter. Typical ranges are 9.5 to 10.5. The upper and lower limit of the CoM height is dependent on the hardware and is set in module robi_def.py.

Remarks:

The basic Idea is to optimize each parameter with the goal to make Robi walk smooth. When you optimize, do it with one parameter at a time, as the parameters impact each other to some degree. For example if you change the CoM height you might need to adjust the micro step width and/or the delay. My experience shows that there are different sets of parameters which lead to a smooth walking execution. You get sets of values [single step width, CoM, micro step width, Delay] for smooth walking execution.

There are many ways to manage walking speed. E.g. to walk slower you can:

  • decrease the single step width, which results in more steps to reach the target distance
  • reduce the micro step width, so more micro steps are needed to make a single step
  • increase the delay, which slows down the speed for a single step

In a similar way you can increase speed by increasing single step width or micro step width or decrease the delay.

As already noted above, the basic Idea is to get sets of parameters [single step width, CoM, micro step width, Delay] for smooth walking execution. Play around a bit and have fun to see Robi walking!

Design Considerations and Future Improvements

Communication: PicoWeb is an unbloated and easy to use web tool kit running on small MCUs. The communication between the WebUI and the robot controller is "single request - single respone". The robot controller acts on a request to its API and once the request is completed reports a status back to the requestor. A life tick is implemented to poll the robot controller's status every few seconds (default is 3 seconds).

Modularity: The robot controller software is modular, so it can be extended or changed easily to adapt to user needs. E.g. the walking pattern generation is in module walking_positions, so if you like to use a different flow or algorithm you have to just change/replace this module.

One core vs. two cores: The RP2040 has two CPU cores. For the sake of finalizing the functionality first, only one core is used. A downside is that the walking execution is blocking, means that no other code (e.g. the API) can be executed while walking. A future improvement could be to move the walking execution to the second core. First test have been done and some functionality is built, but not yet completed.

If you want to play around with both cores find the line core2 = in the file cfg.py and set the vaiable to core2 = True.

Reset Button: if you adapt the software or play around with other walking patterns, frequent restart of the robot controller might be needed. To avoid power on/off or even un-plug/re-plug the USB cable a reset button is a good extension of the robot hardware. How to add a reset button.

WLan indicator: Ever now and then the connection to the WLan might be lost or cannot be established. If that occurs an exception is generated and the robot controller shuts down. If you are not operating with an USB cable, you would not recognize the issue right away. Next to the life tick LED on the pico board an additional (multi color) LED might be useful to indicate error states, such as WLan connection lost

Low battery shutdown: If Robi walks freely it is powered by a battery. In the WebUI state of charge is displayed to the user. For additional safety, a battery monitoring could be implemented in software (either in the robot controller or the WebUI) to emergency shut down the robot controller, when the battery is nearly empty.