Friday, December 2, 2022

ROS experiments

I will be experimenting with the newest ROS2 at the time of this writing; Humble Hawksbill. Image a raspberry PI 4 2Gb with 64-bit rasbian OS on a 32Gb microSD. I am using putty to ssh into the pi and VNCviewer to interface with GUIs. 

Learn docker to install ROS2 on the RPI4

This is my first time using docker. After cloning the docker images repo, I went with the humble ros-base image.

The following are some useful docker commands:

  • docker ps
  • docker images
  • docker container start [CONTAINER-ID]
  • docker exec -ti [CONTAINER-ID] /bin/bash
  • docker container list -f "status=exited"
  • docker commit os_name image_name:version
  • docker container update --help (this might have saved me some time and disk space. I was committing so that I could rerun with new parameters)
  • docker rm container_id_or_name
  • The config file is a json file at the location ‘ /var/lib/docker/containers/[container-id]/config.v2.json
Build the container using the appropriate Dockerfile, then renamed it "ROS-TEST" to reference it without having to use the randomly generated container number.
  • $ sudo docker rename [container#] ROS-TEST

Set the timezone in a container

  • sudo rm -rf /etc/localtime
  • sudo ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
  • date

Moving on to the ROS2: Humble Hawksbill tutorials.

The environment set up witout problems. 

  • source /opt/ros/humble/setup.bash
  • echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
  • printenv | grep -i ROS
  • export ROS_DOMAIN_ID=24
  • echo "export ROS_DOMAIN_ID=24" >> ~/.bashrc

The turtlebot tutorial took a while to download and setup. When running the turtlebot simulator an error occured:

qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
[ros2run]: Aborted

The sim uses qt and qt can't find a display. Is this a problem with docker, vnc, or a combo of both? 

Make an image of the current container to run with environmental variables set: 

  • --env="Display"
  • --net=host
  • FIX: in RPI terminal "xhost +local:docker". This needs to be done every reboot that you wish to use a GUI. It can also be run while a container is running

"exit" docker. The container is no longer running. "docker container start ROS-TEST", the container is running in the background.

Turtlesim GUI still launches with errors:

libGL error: MESA-LOADER: failed to retrieve device information

MESA-LOADER: failed to retrieve device information

MESA-LOADER: failed to retrieve device information

libGL error: failed to create dri screen

libGL error: failed to load driver: vc4

libGL error: failed to open /dev/dri/card1: No such file or directory

libGL error: failed to load driver: vc4

qt.qpa.xcb: QXcbConnection: XCB error: 148 (Unknown), sequence: 191, resource id: 0, major code: 140 (Unknown), minor code: 20

However, teleop keys work for the movement. I'll look into the errors above if I run into problems. 

  • --volume="$HOME/.Xauthority:/root/.Xauthority:rw"

^ Adding this didn't get rid of the errors. I'm not even sure if that is how to share the RPI's xserver as a volume to the docker container though...

Moving on... rqt install is 1198MB. 

Everything works to finish the CLI tutorials.

The following error came up in Tutorials \Beginner: Client libraries \Using colcon to build packages.

CMake Error at CMakeLists.txt:14 (find_package):
  By not providing "Findexample_interfaces.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "example_interfaces", but CMake did not find one.

This is caused by a missing install and remedied by:  

  • sudo apt install ros-humble-example-interfaces

The RPI does not like "colcon build --symlink-install" very much. It went unresponsive for 1h 6m. Plus...more errors. I forgot to start from a clear directory though... When I re ran the build, it maxed out my ram and swap file, interrupting my VNC connection, and became generally unresponsive. 12 hours in, it was still unresponsive. I power cycled the RPI and got back into the container to try again. rm -r the ros2_ws directory and started over... It looks like it is going to have the same problem. Next attempt is to increase the RPI swap file from 100M to 1000M and reduce the amount of RAM the container has access to, it is currently unlimitted.

Swap increase:

  1. sudo dphys-swapfile swapoff
  2. sudo nano /etc/dphys-swapfile
  3. CONF_SWAPSIZE=100
  4. CONF_SWAPSIZE=2048 (Increased to 6144 later)
  5. sudo dphys-swapfile setup
  6. sudo dphys-swapfile swapon
  7. sudo reboot
Docker's memory and CPU usage: MEM reference. In step 5, I give docker access to only 3 of the RPI's 4 cpus, 1G of its memory, and 1.5G of swap so that it'll remain responsive and not kill other processes like VNC.
  1. sudo cp /boot/cmdline.txt /boot/cmdline.txt.bak
  2. sudo nano /boot/cmdline.txt
  3. add "cgroup_enable=memory cgroup_memory=1 swapaccount=1" to the end of the line, not on a new line.
  4. verify with "docker info"
  5. docker run -it --name guiROSlimited --memory="1g" --memory-swap="2.5g" --cpus="3" --env="DISPLAY" --net=host [IMAGE NAME]
Now running "colcon build --symlink-install" isn't crashing the pi or making ssh/VNC unsresponsive.
I'm starting to question whether I should have made the swap file 4 or 6G now...  26 minutes in, the RPI swap is at 1.47G and 0/22 modules have been build...45 minutes: container swap is full :-( ctl+c aborted. increasing swap to 6144.
  • want /var/swap=6144MByte, restricting to config limit: 2048MBytes, checking existing: keeping it
  • uncomment CONF_MAXSWAP=2048 and change to CONF_MAXSWAP=6144
31 minutes later, I forgot to run a new docker container with increased swap. It maxxed out faster. I created a new container for a fresh start.
  • docker run -it --name rosFresh1 --memory="1.25g" --memory-swap="4.5g" --cpus="3" --env="DISPLAY" --net=host ros_docker
  • sudo apt update
  • sudo apt upgrade

Monday, September 26, 2022

Stuck on a bug...

 After getting 1300 lines deep, the code has started to develop a bug. While running gait timers for leg/servo movement, Bluetooth disconnects and the program hangs... I've tried debugging and the error goes away if I had a serial.print()... but that is odd that it would fix it. I know that adding serial communication can sometimes take more time for a process... 

Anyway, I'm going to try running some multicore examples from https://community.element14.com/products/raspberry-pi/b/blog/posts/four-multicore-c-programs-for-raspberry-pi-pico-using-arduino-ide

Thursday, August 11, 2022

Pinky: Android RC control over Bluetooth to Arduino Nano PR2040 Connect.

 For remote control of Pinky the octobot I had a choice of wifi, Bluetooth, or an old drone TX and RX set up. I'm choosing to go with Bluetooth because everybody with a phone has the capability in their pockets. The old drone RX/TX setup would require additional components and take up internal cavity space in the robot. After two nights of testing I finally got BLE working last night by following these resources:


Tonight, 8/11/22, I'll try and build a joystick and control scheme into the app inventor to push command controls to the Arduino. After that, I'll try to port Pinky's old micropython codebase to the Arduino programming language and convert all of its classes to headers....
Update:8/13/2022
Finally got an app I am okay with. The code is vast, so if you want to see it, just download it to view it outside your browser.
Time to start working on the arduino code.
#include <ArduinoBLE.h>

#include <Arduino_LSM6DSOX.h>

BLEService RCService("27810000-4786-42e7-bd27-45257b2e988f"); // BLE LED Service
// BLE AppInventorRC Characteristic - custom 128-bit UUID, read and writable by central
BLEIntCharacteristic RC_AngleCharacteristic("27810001-4786-42e7-bd27-45257b2e988f", BLERead | BLEWrite | BLEWriteWithoutResponse);
BLEIntCharacteristic RC_SpeedCharacteristic("27810002-4786-42e7-bd27-45257b2e988f", BLERead | BLEWrite | BLEWriteWithoutResponse);
BLEIntCharacteristic RC_HeightCharacteristic("27810003-4786-42e7-bd27-45257b2e988f", BLERead | BLEWrite | BLEWriteWithoutResponse);
BLEIntCharacteristic RC_RotationCharacteristic("27810004-4786-42e7-bd27-45257b2e988f", BLERead | BLEWrite | BLEWriteWithoutResponse);

int LastSpeed = 0;
int LastAngle = 0;
int LastHeight = 0;
int LastRot = 0;

int tick = 0;
bool CentralConnected = 0;
//IMU
float x, y, z;

void setup() {
  Serial.begin(9600);
  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting Bluetooth® Low Energy failed!");
  }

  // set advertised local name and service UUID:
  BLE.setLocalName("Pinky_RX");
  BLE.setAdvertisedService(RCService);
  // add the characteristics to the service
  RCService.addCharacteristic(RC_AngleCharacteristic);
  RCService.addCharacteristic(RC_SpeedCharacteristic);
  RCService.addCharacteristic(RC_HeightCharacteristic);
  RCService.addCharacteristic(RC_RotationCharacteristic);
  // add service
  BLE.addService(RCService);
  // start advertising
  BLE.advertise();
  Serial.println("Pinky Peripheral, waiting for connections....");
  //IMU stuff
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
  }
    Serial.print("Gyroscope sample rate = ");
  Serial.print(IMU.gyroscopeSampleRate());
  Serial.println(" Hz");
  Serial.println();
  Serial.println("Gyroscope in degrees/second");
  Serial.println("X\tY\tZ");
}
void loop() {
  // listen for BLE peripherals to connect:
  BLEDevice central = BLE.central();
  // if a central is connected to peripheral:
  if (central) {
    if (!CentralConnected){
      Serial.print("Connected to central: ");
      // print the central's MAC address:
      Serial.println(central.address());
      // while the central is still connected to peripheral:
      CentralConnected = 1;
    }
   
    while (central.connected()) {
      //Serial.print("Waiting for the write thing: ");
      //delay(100);//This causes hangs / crashes
      if (RC_AngleCharacteristic.written() || RC_SpeedCharacteristic.written() || RC_HeightCharacteristic.written() || RC_RotationCharacteristic.written()) {
        //Debounce the BLE
        if (LastAngle != RC_AngleCharacteristic.value() || LastSpeed != RC_SpeedCharacteristic.value() || LastHeight != RC_HeightCharacteristic.value() || LastRot != RC_RotationCharacteristic.value()){
        tick++;
        Serial.println(tick);
        Serial.print("Angle: ");
        Serial.print(RC_AngleCharacteristic.value());
        Serial.print(" Speed: ");
        Serial.print(RC_SpeedCharacteristic.value());
        Serial.print(" Height: ");
        Serial.print(RC_HeightCharacteristic.value());
        Serial.print(" Rotation: ");
        Serial.println(RC_RotationCharacteristic.value());
        LastAngle = RC_AngleCharacteristic.value();
        LastSpeed = RC_SpeedCharacteristic.value();
        LastHeight = RC_HeightCharacteristic.value();
        LastRot = RC_RotationCharacteristic.value();
        }
       

      }
      // if (IMU.gyroscopeAvailable()) {
      // IMU.readGyroscope(x, y, z);

      // Serial.print(x);
      // Serial.print('\t');
      // Serial.print(y);
      // Serial.print('\t');
      // Serial.println(z);
      //}
    }
    if(CentralConnected){
      // when the central disconnects, print it out:
      Serial.print(F("Disconnected from central: "));
      Serial.println(central.address());
      CentralConnected = 0;
    }
  }
 
}

Thursday, May 12, 2022

Modified Integza pneumatic motor

Experimenting with the Integza Wankel for semester 3 project at Bellingham Technical College:

^3D printed Fused Filament Fabrication(FFF) PETG^
  • Modified the shaft to be longer and added a spline for energy transfer to a gear(bevel). Not sure how much torque transfer is capable of being delivered. Yet!
  • Modified the lid with 3.25M bolt holes, a wider shaft hole to fit a 688z (8 x 16 x 5mm) bearing, and chamfered bearing shaft hole to clear the 688z's inner race from catching. WORKS!
5/12/22
  • New 6802-RS bearing (15 x 24 x 5mm) required press-fitting. I might reduce the printed dimensions in the future. This solution is more rigid but has more friction than a 3D printed plain bearing.
  • The rotor needs to be sanded, it is too tall by 0.1 mm-ish. WORKS!
  • The pneumatic fittings are too big for the case and cracked the I/O ports. Remodeled with 9.75 mm ports, no threading added yet.
  • 9.75 was too big(wasted time, plastic, electricity). Pictured below, left.
  •  9.625 mm ID with .4 x 2mm chamfer works, tested on a subsection. Pictured below, upper right.
  • The next test is adding threads. I imported the fitting model into fusion 360 from the McMaster catalog.6 mm OD, 3/8threads.

Tuesday, October 19, 2021

Bellingham MakerFaire Results

Gallery of Bellingham Makerfaire interactive booth results:

1st firing (bisque)

All of these were designed on the spot 10/9/21 by 1st-time users of my sculpting software built for the makerfaire the week before (see previous post).













Monday, October 4, 2021

Contact-free-throwing

Use your hands to make digital vases that will be 3d printed out of porcelain!


10/3/21

1.Fire up TOUCHDESIGNER 88.

2. My install of TD88 no longer works with my leap motion devices. I guess that is to be expected since I haven't tried to use these together in almost a DECADE...Thanks to this video the leap motion is running again.

3. Figure out what the heck to do next...

4. 10/4/21
Day2: Make it better! Added limits for over and underhangs. Find a way to save to .obj files. The geometry types had to be a certain kind for the points in OBJ files to work. OBJ saver found in the Touchdesigner forums with a simple search.

5. 10/6/21
Day3: Test slicing, it works! Simplify 3d can turn my monsters into art! Tested the UI on Mike and Deb today, it was okay, but Deb's laptop doesn't handle live SOP updates very well. Tested around 5 fps on the studio laptop.
Steps for tonight: add highlights to the layer being moved, maybe a color change. Build out the performance UI to include multiple views (X&Z) plus an overhead map of the hand vs geo.

6. 10/8/21 Added a user interface with front and side views, as well as measurements, and a save indicator.
Here is an exported obj file:




Wednesday, September 29, 2021

After years... this is a life changer.  I feel grateful and stupid. For anybody that has a second 4k monitor.

https://www.alphr.com/microsoft/microsoft-windows-10/1001272/how-to-set-display-scaling-in-windows-10/