PHILIP LONG

PhD, ROBOTICIST

Sourcing multiple workspaces

For reasons beyond me occasionally, one source overrides another. To ensure this does not happen the extend needs to be appended to the sourcing in the bashrc

source /opt/ros/indigo/setup.bash

source ~/catkin_ws_n/devel/setup.sh --extend </code>

Typically I alias two commands in ~/.bashrc, which allows me to extend a workspace or overwrite the previous one

alias sss='source ./devel/setup.bash'

alias sssx=’source ./devel/setup.bash –extend’
</code>



1. Command Line/ Bash

  • Recursive find
  • grep -r "search term" ./ ps -A | grep "process"

  • Recursive find in files of certain extensions (matlab files having a rospublisher)
  • grep -r --include=\*.m 'rospublisher' ./

  • Search and replace word in all files in tree :
  • find ./ -type f -exec sed -i -e 's/old_name/new_name/g' {} \;

  • Search and replace all filenames in tree :
  • find ./ -iname "laser_manager*" | rename -v "s/laser_manager/laser_sensor_set/g"

  • Remove all tilde files in directory tree
  • find . -name "*~" -exec rm {} \;

  • Counting words terminal
  • 	wc #Hit Enter  
    	The quick brown fox jumped over the lazy dog #Copy all text you need to count then hit ctrl+d
    	0       9      44 # Voila
      
  • Checking if Matlab functions are used by any files in folder
  • for f in *.m; do echo $f ; grep -r ${f:0:(-2)} ./ ; echo " ============== " ; done

  • Automate testing with bash, & - runs process in background/in parallel then wait - waits for all process to finish before incrementing loop
  •   for value in {1..5}
    	do
    	roslaunch package1 monitor.launch config:=config1 &
    	rosrun  package2  package_node test:=$value &
    	wait
      done
      

    2. Network Stuff

  • Remote copying scp -r username@ip:/path/to/folder/on/remote/pc /path/to/folder/on/local/pc
  • Scan network for device
  • sudo arp-scan --interface=eth0 --localnet
  • Start jekyll server for off-line website tests
  • jekyll --server

    3. Ubuntu

  • Compiz can be restarted using. This usually stops disappearing window bars
  • compiz --replace

    4. Stl

  • Appending vectors to other vectors
  • std::vector a,b; </code> a.insert(a.end(), b.begin(), b.end());
  • Multipling each element by an external scalar by using a lambda function
  • double scalar; std::for_each(a.begin(),b.end(), [scalar](double& n){n*=scalar;});
  • Finding the difference between two vectors and storing in a third vector
  • ev.clear(); std::transform(qdot_ref.begin(),qdot_ref.end(),qdot.begin(),std::back_inserter(ev),std::minus()); </code>

    5. Latex IEEE

  • Sometimes when checking for IEEE pdf compliant I get this wierd error: Type 3 font is a font that is not Type 1. This is due to using embedded fonts in an image, for instance using latex in inkscape. The easiest way I've found to resolve this issue is to convert eps to pdf before latex compliation, as follows:

  • convert image.eps image.pdf
    Then we can check everything is ok by running this command
    pdffonts image-eps-converted-to.pdf

    6. Using prime numbers for state machines

  • Often I have to create state machines for simple robot actions. Typically these are high level commands passed by an enum. For instance:
  • enum ACTION { LIFT_LEFT_HAND, LOOK_AROUND, LIFT_RIGHT_HAND, GRASP, RELEASE, TURN_OFF_LED,TURN_ON_LED} ;
    	switch my_action  
    {
    case LIFT_LEFT_HAND:
    liftLeftHand();
    break;
    case LOOK_AROUND:
    lookAround();
    break;
    case LIFT_LEFT_HAND_LOOK_AROUND:
    liftLeftHand();
    lookAround();
    }
  • This type of structure means all actions can be stored in one function. The problem is it tends to balloon when composite actions are possible, for example, TURN_ON_CAMERAS and LEDS and LOOK_AROUND. Instead of creating an case for each composite action what I think is a nice solution is using primes for enums. In doing we can combine as many actions as desired.
  • enum ACTION { LIFT_LEFT_HAND=2, LOOK_AROUND=3, LIFT_RIGHT_HAND=5, GRASP=7, RELEASE=11, TURN_OFF_LED=13,TURN_ON_LED=17} ;

    if (my_action%LIFT_LEFT_HAND==0)
    liftLeftHand();
    if (my_action%LOOK_AROUND==0)
    lookAround();