Categories
dev robots simulation

Catkin

ROS build tool. These are the patterns of use:

In order to help automate the merged build process, Catkin was distributed with a command-line tool called catkin_make. This command automated the above CMake work flow while setting some variables according to standard conventions. These defaults would result in the execution of the following commands:

$ mkdir build
$ cd build
$ cmake ../src -DCATKIN_DEVEL_SPACE=../devel -DCMAKE_INSTALL_PREFIX=../install
$ make -j<number of cores> -l<number of cores> [optional target, e.g. install]

To get DSO (Direct Sparse Odometry) working.

I followed these instructions: https://github.com/JakobEngel/dso_ros/issues/32

I made /opt/catkin_ws

git clone –single-branch –branch cmake https://github.com/NikolausDemmel/dso.git
git clone –single-branch –branch catkin https://github.com/NikolausDemmel/dso_ros.git

catkin init

catkin config -DCMAKE_BUILD_TYPE=Release

catkin build

Categories
AI/ML control Locomotion simulation The Sentient Table

ARS and PPO

https://pybullet.org/Bullet/phpBB3/viewtopic.php?t=12553

A couple of advanced data science algorithms. Implemented both for the walking table. ARS is great. We hear a lot about deep learning. This one is shallow learning, and does very well on simpler tasks. Just inputs and outputs, no hidden layers.

It’s similar to the Evolution Strategies algorithm. Generally trying some random stuff out, and slowly changing the model based on what gets you closer to the goal.

ARS: https://arxiv.org/pdf/1803.07055.pdf

Good lecture slides http://eddiesagra.com/wp-content/uploads/2019/03/Introduction-to-Machine-Learning-v1.2-Mar-11-2019.pdf

ARS – Augmented Random Search

https://github.com/colinskow/move37/blob/master/ars/ars.py

https://towardsdatascience.com/introduction-to-augmented-random-search-d8d7b55309bd

PPO – Proximal Policy Optimization

https://github.com/bulletphysics/bullet3/blob/master/examples/pybullet/gym/pybullet_envs/agents/ppo/algorithm.py

Categories
3D Research robots simulation

Gazebo Cassie Sim

Checked out https://github.com/agilityrobotics/cassie-gazebo-sim

There were some extra steps, as per usual. Ubuntu 18.04? https://automaticaddison.com/how-to-launch-gazebo-in-ubuntu/ – We need to change the URL to url: https://api.ignitionrobotics.org

cd ~/.ignition/fuel/config.yaml

and I needed to set some envs

GAZEBO_PLUGIN_PATH=/opt/cassie-gazebo-sim/plugin/build
GAZEBO_MODEL_PATH=/.gazebo/models

/.gazebo/models/cassie# gazebo cassie.world

It loads a derpy cassie robot

Then /opt/cassie-gazebo-sim/plugin/build# ./cassiectrl

runs the sim, which doesn’t do anything.

But the https://github.com/agilityrobotics/cassie-gazebo-sim/tree/master/plugin/include code is interesting, for remote controlling code in C using UDP. UDP is a good idea for remote control. Sends structs. Very straightforward. Nice. ZMQ probably nicer though.

Looks like it integrates with a fancy https://www.elmomc.com/ motion control company thing. Nice big UI. But yeah. Cassie robot is much too complicated.

Categories
Locomotion The Sentient Table

Robot prep: URDF

After much confusion, I made a table with legs that can move.

So I raised the table to z=1 plane and put the origin of the joints in the right place. THEN you set the legs/links with origin at -0.5 because the joint is at 1, and the leg is 1 long, and presumably it needs 0.5 because that’s the centre of the box.

I did visualisation by changing the filename in this file in the bullet3 folders, and running in python:

python3 biped2d_pybullet.py

seemed better than RViz

<?xml version="1.0"?>
<robot name="table">

  <material name="white">
    <color rgba="1 1 1 1"/>
  </material>

  <material name="black">
    <color rgba="0.2 0.2 0.2 1"/>
  </material>

  <material name="blue">
    <color rgba="0 0 1 1"/>
  </material>


	
  <link name="torso">
    <visual>
      <geometry>
        <box size="2 2 0.1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 1"/>
      <material name="white"/>
    </visual>
    <collision>
      <geometry>
        <box size="2 2 0.1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 1"/>
      <contact_coefficients mu="0.08" />
    </collision>
  </link>
 


 
  <link name="r_upperleg">
    <visual>
      <geometry>
        <box size="0.1 0.1 1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 -0.5"/>
      <material name="black"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.1 0.1 1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 -0.5"/>
      <contact_coefficients mu="0.08" />
    </collision>
  </link>

  
  <joint name="torso_to_rightleg" type="revolute">
    <parent link="torso"/>
    <child link="r_upperleg"/>
    <axis xyz="1 0 0"/>
    <limit effort="0.0" lower="-1.57." upper="1.57" velocity="1000.0"/>
    <origin rpy="0 0 0" xyz="1 1 1"/>
  </joint>





  
  <link name="l_upperleg">
    <visual>
      <geometry>
        <box size="0.1 0.1 1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 -0.5"/>
      <material name="black"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.1 0.1 1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 -0.5"/>
      <contact_coefficients mu="0.08" />
    </collision>
  </link>

  
  <joint name="torso_to_leftleg" type="revolute">
    <parent link="torso"/>
    <child link="l_upperleg"/>
    <axis xyz="1 0 0"/>
    <limit effort="10.0" lower="-1.57." upper="1.57" velocity="1000.0"/>
    <origin rpy="0 0 0" xyz="-1 1 1"/>
  </joint>








  <link name="front_r_upperleg">
    <visual>
      <geometry>
        <box size="0.1 0.1 1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 -0.5"/>
      <material name="black"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.1 0.1 1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 -0.5"/>
      <contact_coefficients mu="0.08" />
    </collision>
  </link>


  <joint name="torso_to_frontrightleg" type="revolute">
    <parent link="torso"/>
    <child link="front_r_upperleg"/>
    <axis xyz="1 0 0"/>
    <limit effort="0.0" lower="-1.57." upper="1.57" velocity="1000.0"/>
    <origin rpy="0 0 0" xyz="1 -1 1"/>
  </joint>








  <link name="front_l_upperleg">
    <visual>
      <geometry>
        <box size="0.1 0.1 1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 -0.5"/>
      <material name="black"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.1 0.1 1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 -0.5"/>
      <contact_coefficients mu="0.08" />
    </collision>
  </link>


  <joint name="torso_to_frontleftleg" type="revolute">
    <parent link="torso"/>
    <child link="front_l_upperleg"/>
    <axis xyz="1 0 0"/>
    <limit effort="10.0" lower="-1.57." upper="1.57" velocity="1000.0"/>
    <origin rpy="0 0 0" xyz="-1 -1 1"/>
  </joint>

  

</robot>
Categories
AI/ML arxiv Vision

Instance Segmentation

https://arxiv.org/pdf/2003.10152.pdf – SOLOv2

https://arxiv.org/pdf/2003.06148.pdf – PointINS: Point-based Instance Segmentation

cool site, paperswithcode.

https://paperswithcode.com/task/instance-segmentation?page=4

Categories
CNNs Vision

Visualize CNNs

https://github.com/fg91/visualizing-cnn-feature-maps

Image for post
Image for post

“There are two main ways to try to understand how a neural network recognizes a certain pattern. If you want to know what kind of pattern significantly activates a certain feature map you could 1) either try to find images in a dataset that result in a high average activation of this feature map or you could 2) try to generate such a pattern by optimizing the pixel values in a random image. The latter idea was proposed by Erhan et al. 2009

from: https://towardsdatascience.com/how-to-visualize-convolutional-features-in-40-lines-of-code-70b7d87b0030


class FilterVisualizer():
    def __init__(self, size=56, upscaling_steps=12, upscaling_factor=1.2):
        self.size, self.upscaling_steps, self.upscaling_factor = size, upscaling_steps, upscaling_factor
        self.model = vgg16(pre=True).cuda().eval()
        set_trainable(self.model, False)

    def visualize(self, layer, filter, lr=0.1, opt_steps=20, blur=None):
        sz = self.size
        img = np.uint8(np.random.uniform(150, 180, (sz, sz, 3)))/255  # generate random image
        activations = SaveFeatures(list(self.model.children())[layer])  # register hook

        for _ in range(self.upscaling_steps):  # scale the image up upscaling_steps times
            train_tfms, val_tfms = tfms_from_model(vgg16, sz)
            img_var = V(val_tfms(img)[None], requires_grad=True)  # convert image to Variable that requires grad
            optimizer = torch.optim.Adam([img_var], lr=lr, weight_decay=1e-6)
            for n in range(opt_steps):  # optimize pixel values for opt_steps times
                optimizer.zero_grad()
                self.model(img_var)
                loss = -activations.features[0, filter].mean()
                loss.backward()
                optimizer.step()
            img = val_tfms.denorm(img_var.data.cpu().numpy()[0].transpose(1,2,0))
            self.output = img
            sz = int(self.upscaling_factor * sz)  # calculate new image size
            img = cv2.resize(img, (sz, sz), interpolation = cv2.INTER_CUBIC)  # scale image up
            if blur is not None: img = cv2.blur(img,(blur,blur))  # blur image to reduce high frequency patterns
        self.save(layer, filter)
        activations.close()
        
    def save(self, layer, filter):
        plt.imsave("layer_"+str(layer)+"_filter_"+str(filter)+".jpg", np.clip(self.output, 0, 1))

and use it like this:

layer = 40
filter = 265
FV = FilterVisualizer(size=56, upscaling_steps=12, upscaling_factor=1.2)
FV.visualize(layer, filter, blur=5)
Categories
chicken_research CNNs deep

Bird audio CNNs

https://besjournals.onlinelibrary.wiley.com/doi/full/10.1111/2041-210X.13103

Contest in 2017 for bird call neural nets. Best ones used mel spectrogram of the audio with convolutional neural networks.

The winning algorithm’s code is available: https://jobim.ofai.at/gitlab/gr/bird_audio_detection_challenge_2017/tree/master

Categories
Gripper

Robot Grasping

https://twimlai.com/dex-net-and-the-third-wave-of-robot-learning/

According to Ken, there are three fundamental elements of uncertainty that make robot grasping extremely difficult:

Perception. Understanding the precise geometry of where everything is in a scene can be a complex task. There have been developments in depth sensors like LIDAR, “but they still don’t completely solve this problem because if there’s anything reflective or transparent on the surface, that causes the light to react in unpredictable ways, it doesn’t register as a correct position of where that surface really is.” Adding additional sensors doesn’t help much because they often create contradictions, “[the agent] doesn’t know what to trust” in order to act correctly. Perception is especially important in grasping because “a millimeter or less can make the difference between holding something and dropping it.”

Control.
  The robot has to maintain control of its grasp meaning, “The robot has to now get its gripper to the precise position in space, consistent with what it believes is happening from its sensors.” If the gripper moves slightly or holds it too tight, the object can drop or break.

Physics.
 This has to do with choosing the right place to grasp the object, understanding friction and mass are significant unknowns. To demonstrate how difficult this is, Ken gives the example of pushing a pencil across the table with your finger. We can estimate the pencil’s center of mass, but we ultimately do not know the frictional properties at play. It’s almost impossible to predict the trajectory because even “one microscopic grain of sand, anything under there is going to cause it to behave extremely differently.” 

https://berkeleyautomation.github.io/dex-net/

The first wave is the “classic physics” approach which prioritizes traditional understandings of physics in terms of forces, and torques, friction, mass — all that good stuff. The second wave is the more modern, “data-driven approaches that say: ‘Forget about the physics, let’s just learn it from observation purely’” and assume the physics will be learned naturally in the process. 

Then there’s what Ken advocates for, which is the third wave of robot learning that combines the two fields of thought. The goal is to synthesize the knowledge from both perspectives to optimize performance. However, “figuring out where that combination is is the challenge. And that’s really the story of Dex-Net.”

Categories
Vision

Monocular SLAM

For drawing a map of a place. (Simultaneous localization and mapping). Monocular meaning single camera.

https://vision.in.tum.de/research/vslam/lsdslam

https://ubilang.wordpress.com/2016/05/07/orb-slam-vs-lsd-slam/

and point clouds

http://pointclouds.org/blog/tocs/alexandrov/index.php

https://github.com/PointCloudLibrary/pcl

https://github.com/raulmur/ORB_SLAM2

https://github.com/tum-vision/lsd_slam

Categories
Vision

ImageHub and ImageNodes

I set up the https://github.com/jeffbass/imagenode and https://github.com/jeffbass/imagehub and https://github.com/jeffbass/imagezmq from earlier

I needed these. (latest openCV has bug)

pip3 install pyyaml numpy virtualenv zmq imutils psutil picamera
pip3 install opencv-contrib-python==4.1.0.25

On the imagehub side, it finds /root/imagenode.yaml and sets up a folder.

Then the imagenode side, it looks for the directory structure with imagenode/ imagezmq/ and imagenode.yaml in the parent folder. You replace the contents with the YAML examples in the tests folder.

Then when it detects motion in the blue box, it takes pics that arrive in ~/imagehub_data/images/2020-04-12#

So this is a good start for various applications.