Semi-Autonomous Robotics: (2012) My 1st Software Project

I’m experimenting with committing past projects to github.

Over the summer (2012) at George Washington University Robotics Lab – Positronics Divison (with Roxana Leonetie as my mentor and Gregory Colella as my research partner), we wrote a package for the PR2 using ROS stacks and Python. In short, the PR2 completes a task moving a dowel into a hole (using only force proprioception) as a response to dynamic stimuli.

If you are unfamiliar with the PR2:

Greg was relatively new to Python (an experienced Java coder), and I learned to code the same summer that we completed the project (previously, I had dabbled in mainly math and physics). Bear this in mind while viewing our project.

This is an early demo I simulated in gazebo of the PR2 learning to replicate arm movements (a major part of the project).

Generate CSV of Google Music Playlist

I recently switched my music vendor from Google Music to Spotify. To avoid manually searching for each song, I semi-automized the transition as follows.

1. Generate a CSV (artist, title) from your Google Music Playlist. Zoom your window out all the way (querySelectorAll will only load a static list of currently active rows).

// Run in Chrome's Developer Tools Console: Crtl+Shift+I

var playlist = document.querySelectorAll('.song-table tr.song-row');
for(var i =0; i<playlist.length ; i++) { 
  var l = playlist[i]; 
  var title = l.querySelectorAll('td[data-col="title"] .content')[0].textContent;
  var artist = l.querySelectorAll('td[data-col="artist"] .content')[0].textContent;
  console.log(artist.replace(","," ") + ',' + title.replace(","," ")); //take out "," to clean up CSV
  
}

Scroll and rerun until you have all entries.

2. Open your CSV in vim to remove the VM290:8 at the end of each entry. For example:
Clamavi De Profundis,Far Over the Misty Mountains Cold VM290:8

:%s/.{8}$//

Now you have a CSV file of arists, titles to do with what you wish.
To proceed with migrating this playlist to Spotify specifically, continue to steps 3 & 4.

3. Copy/paste into Ivy.

4. Paste Ivy results into desired playlist.

Terminal Hexagonal Lattice

Here: have a script to generate plaintext hexagonal lattices for you when you’re feeling blue.

<code>import itertools

pattern1 = ". ."
pattern0 = "   "

def main(repeat,length):
  for _ in itertools.repeat(None, length):
  print (pattern1+pattern0)*repeat
  print (pattern0+pattern1)*repeat


if __name__ == "__main__":
    main(10,10)
</code>
<code>. .   . .   . .   . .   . .   . .   . .   . .   . .   . .   
   . .   . .   . .   . .   . .   . .   . .   . .   . .   . .
. .   . .   . .   . .   . .   . .   . .   . .   . .   . .   
   . .   . .   . .   . .   . .   . .   . .   . .   . .   . .
. .   . .   . .   . .   . .   . .   . .   . .   . .   . .   
   . .   . .   . .   . .   . .   . .   . .   . .   . .   . .
. .   . .   . .   . .   . .   . .   . .   . .   . .   . .   
   . .   . .   . .   . .   . .   . .   . .   . .   . .   . .
. .   . .   . .   . .   . .   . .   . .   . .   . .   . .   
   . .   . .   . .   . .   . .   . .   . .   . .   . .   . .
. .   . .   . .   . .   . .   . .   . .   . .   . .   . .   
   . .   . .   . .   . .   . .   . .   . .   . .   . .   . .
. .   . .   . .   . .   . .   . .   . .   . .   . .   . .   
   . .   . .   . .   . .   . .   . .   . .   . .   . .   . .
. .   . .   . .   . .   . .   . .   . .   . .   . .   . .   
   . .   . .   . .   . .   . .   . .   . .   . .   . .   . .
. .   . .   . .   . .   . .   . .   . .   . .   . .   . .   
   . .   . .   . .   . .   . .   . .   . .   . .   . .   . .
. .   . .   . .   . .   . .   . .   . .   . .   . .   . .   
   . .   . .   . .   . .   . .   . .   . .   . .   . .   . .</code>

SPOILERS: Using Simple Combinatorics

DISCLAIMER: This is the solution to Project Euler’s problem 15. Please attempt to solve the problem yourself before reading my solution.

Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.



How many such routes are there through a 20×20 grid?

I like to use this problem to demonstrate the efficacy of using simple maths to improve code.

Instead of the naive solution….

from itertools import permutations

def unique(iterable):
    seen = set()
    for x in iterable:
        if x in seen:
            continue
        seen.add(x)
        yield x

options = [1]*20 + [0]*20
counter = 0
for a in unique(permutations(options)):
 counter = counter+1

print counter

Use simple combinatorics!

To find the number of unique routes through a 20×20 grid, use our friend: the concept of permutations with repeated elements:

$\frac{\text{number of elements}!}{\text{repetitions of character}!*\text{repetitions of other character}!*…}$

import math
print math.factorial(40)/(math.factorial(20)*math.factorial(20))

Even better – one line in Haskell:

product [1..40] `div` product[1..20]^2