├── Digital World Python Cheat Sheet ├── 10.009 Digital World Cheat Sheet.md └── assets │ └── turnstile-high-res-opt.jpg ├── Firebase ├── Documentation for Firebase.md ├── retrieve_test.py └── upload_test.py ├── Flipsky VESC 4.12 ├── Flipsky VESC 4.12 Documentation.md └── assets │ ├── 06_be544658-0682-45ea-8461-9ecee8e482f2_2048x2048.jpg │ ├── 1555308468557.png │ ├── 1555308481700.png │ ├── 1555308490615.png │ ├── 1555308503717.png │ ├── 1555308527000.png │ ├── 1555308539968.png │ ├── 1555308548007.png │ ├── 1555308556859.png │ ├── Capture.PNG │ └── Capture2.PNG ├── Git ├── 01_Basic_Git.md ├── 02_Git_in-depth.md ├── 03_Git_Advanced.md ├── assets │ ├── 02-1564677150817.svg │ ├── 02.svg │ ├── 03.svg │ ├── 05.svg │ ├── 1564656014639.png │ ├── 1564661426621.png │ ├── 1564670491164.png │ ├── 1564670575453.png │ ├── 1564670713444.png │ ├── 1564670827975.png │ ├── 1564670879735.png │ ├── 1564670936504.png │ ├── 1564671383062.png │ ├── 1564671619233.png │ ├── 1564673599570.png │ ├── 1564673699537.png │ ├── 1564673784329.png │ ├── 1564673837741.png │ ├── 1564673840133.png │ ├── 1564674025862.png │ ├── 1564674585048.png │ ├── 1564674760940.png │ ├── 1564674894012.png │ ├── 1564675060000.png │ ├── Interface1.png │ ├── add-submodule.png │ ├── branching.png │ ├── centr-decentr@2x.png │ ├── commit.png │ ├── create-new-repo.png │ ├── create-pr.png │ ├── delete-button.png │ ├── diff.png │ ├── git-model@2x.png │ ├── merge-without-ff@2x.png │ ├── multi_file.png │ ├── pick-branch.png │ ├── pr-form.png │ ├── pr-tab.gif │ ├── readme-edits.gif │ └── update-submodule.png └── git_guide.md ├── OpenCV-Cpp └── examples │ ├── load_image.cpp │ └── load_video_file.cpp ├── OpenCV-Python ├── OpenCV - Python.md ├── assets │ ├── 1563808324844.png │ ├── 1563810074231.png │ └── 1563894456180.png └── sample_code │ ├── aruco_detector.py │ ├── circumcenter_demo.py │ ├── contour_centroid_detection.py │ ├── draw_bounding_boxes.py │ ├── drone_arrow_test.py │ ├── hough_circles_demo.py │ ├── ip_cam_test.py │ ├── morph_transform_demo.py │ ├── picamera_scripts │ ├── pi_camera_single_frame.py │ └── pi_camera_video.py │ ├── red_thresholding_demo.py │ ├── roi_selection_demo.py │ ├── rotate.py │ ├── split_four.py │ ├── undistort_demo │ ├── camera_undistort_demo.py │ └── checkerboard_calib.py │ ├── video_cropper.py │ ├── webcam_image.py │ └── webcam_video.py ├── Pwntools └── pwntools.md ├── Quanum 3-Axis Mobius Gimbal ├── Documentation for Quanum 3-Axis Gimbal.md └── runcam2-mountv2.SLDPRT ├── README.md └── ros_smach ├── SMACH_Reference.md ├── assets ├── 1564069347372.png ├── Copy of remap_sm.jpg ├── SM-1564061452245.jpg ├── SM.jpg ├── UntitledDiagram.jpg ├── UntitledDiagram2.jpg ├── recovery.jpg └── simplestate.jpg └── example_ws ├── .catkin_workspace └── src ├── CMakeLists.txt ├── executive_smach ├── .catkin.options ├── .dependencies.rosinstall ├── .travis.yml ├── README.md ├── executive_smach │ ├── CHANGELOG.rst │ ├── CMakeLists.txt │ └── package.xml ├── smach │ ├── CHANGELOG.rst │ ├── CMakeLists.txt │ ├── epydoc.cfg │ ├── package.xml │ ├── rosdoc.yaml │ ├── setup.py │ └── src │ │ └── smach │ │ ├── __init__.py │ │ ├── concurrence.py │ │ ├── concurrence.pyc │ │ ├── container.py │ │ ├── container.pyc │ │ ├── exceptions.py │ │ ├── exceptions.pyc │ │ ├── iterator.py │ │ ├── iterator.pyc │ │ ├── log.py │ │ ├── log.pyc │ │ ├── sequence.py │ │ ├── sequence.pyc │ │ ├── state.py │ │ ├── state.pyc │ │ ├── state_machine.py │ │ ├── state_machine.pyc │ │ ├── user_data.py │ │ ├── user_data.pyc │ │ ├── util.py │ │ └── util.pyc ├── smach_msgs │ ├── CHANGELOG.rst │ ├── CMakeLists.txt │ ├── msg │ │ ├── SmachContainerInitialStatusCmd.msg │ │ ├── SmachContainerStatus.msg │ │ └── SmachContainerStructure.msg │ └── package.xml └── smach_ros │ ├── CHANGELOG.rst │ ├── CMakeLists.txt │ ├── epydoc.cfg │ ├── package.xml │ ├── rosdoc.yaml │ ├── setup.py │ ├── src │ └── smach_ros │ │ ├── __init__.py │ │ ├── action_server_wrapper.py │ │ ├── action_server_wrapper.pyc │ │ ├── condition_state.py │ │ ├── condition_state.pyc │ │ ├── introspection.py │ │ ├── introspection.pyc │ │ ├── monitor_state.py │ │ ├── monitor_state.pyc │ │ ├── service_state.py │ │ ├── service_state.pyc │ │ ├── simple_action_state.py │ │ ├── simple_action_state.pyc │ │ ├── util.py │ │ └── util.pyc │ └── test │ ├── concurrence.py │ ├── concurrence.test │ ├── introspection.py │ ├── introspection.test │ ├── monitor.py │ ├── monitor.test │ ├── ref_server.py │ ├── sequence.py │ ├── sequence.test │ ├── services.py │ ├── services.test │ ├── smach_actionlib.py │ ├── smach_actionlib.test │ ├── state_machine.py │ └── state_machine.test ├── smach_examples ├── CMakeLists.txt ├── Makefile ├── action │ └── Test.action ├── examples │ ├── actionlib_test.py │ ├── concurrence.py │ ├── iterator_tutorial.py │ ├── recovery.py │ ├── sequence.py │ ├── state_machine.py │ ├── state_machine_nesting.py │ ├── state_machine_simple_introspection.py │ └── user_data.py ├── mainpage.dox ├── package.xml └── setup.py ├── visualization ├── README.md ├── rqt_smach │ ├── CMakeLists.txt │ ├── README.md │ ├── doc │ │ ├── rqt_smach.md │ │ ├── rqt_smach_1.png │ │ ├── rqt_smach_10_nozoom.png │ │ ├── rqt_smach_11_tree.png │ │ ├── rqt_smach_12_treeclick.png │ │ ├── rqt_smach_13_treeinitial.png │ │ ├── rqt_smach_2_input_path.png │ │ ├── rqt_smach_3_hover.png │ │ ├── rqt_smach_4_click.png │ │ ├── rqt_smach_5_set_initial.png │ │ ├── rqt_smach_6_depth.png │ │ ├── rqt_smach_7_implicit.png │ │ ├── rqt_smach_8_keyboard.png │ │ ├── rqt_smach_9_autozoom.png │ │ ├── rqt_smach_running_1.png │ │ ├── rqt_smach_running_2.png │ │ └── rqt_smach_running_3.png │ ├── package.xml │ ├── plugin.xml │ ├── scripts │ │ └── rqt_smach │ ├── setup.py │ └── src │ │ └── rqt_smach │ │ ├── __init__.py │ │ ├── container_node.py │ │ ├── container_node.pyc │ │ ├── rqt_smach.py │ │ ├── rqt_smach.pyc │ │ └── rqt_smach.ui ├── smach_viewer │ ├── CHANGELOG.rst │ ├── CMakeLists.txt │ ├── package.xml │ ├── scripts │ │ └── smach_viewer.py │ ├── src │ │ └── smach_viewer │ │ │ └── __init__.py │ └── test │ │ ├── server.py │ │ └── server2.py └── visualization │ ├── CHANGELOG.rst │ ├── CMakeLists.txt │ └── package.xml └── xdot ├── CHANGELOG.rst ├── CMakeLists.txt ├── README.md ├── package.xml ├── scripts └── dot_viewer.py ├── setup.py ├── src └── xdot │ ├── __init__.py │ ├── wxxdot.py │ ├── xdot.py │ ├── xdot_qt.py │ └── xdot_qt.pyc └── test └── dot_files ├── clusters.dot ├── datastruct.gv.dot ├── fdpclust.dot ├── hello.dot ├── process.gv.dot ├── psg.gv.dot ├── softmaint.gv.dot ├── twopi2.gv.dot ├── unix.gv.dot └── world.gv.dot /Digital World Python Cheat Sheet/assets/turnstile-high-res-opt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Digital World Python Cheat Sheet/assets/turnstile-high-res-opt.jpg -------------------------------------------------------------------------------- /Firebase/retrieve_test.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Tue Sep 25 02:52:51 2018 4 | 5 | @author: Fasermaler 6 | """ 7 | import urllib 8 | import requests 9 | import json 10 | 11 | 12 | def download_file(num): 13 | my_url = "" + str(num) + ".jpg?alt=media" # Insert project URL Accordingly 14 | try: 15 | #k = urllib.request.urlretrieve(my_url, str(str(num) + ".jpg")) 16 | r = requests.get(my_url) 17 | with open(str(str(num) + ".jpg"), 'wb') as f: 18 | f.write(r.content) 19 | f.close() 20 | 21 | except urllib.error.URLError as e: 22 | message = json.loads(e.read()) 23 | print(message["error"]["message"]) 24 | else: 25 | pass 26 | 27 | download_file(1) 28 | 29 | -------------------------------------------------------------------------------- /Firebase/upload_test.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Tue Sep 25 01:05:35 2018 4 | 5 | @author: Fasermaler 6 | """ 7 | import pickle 8 | import firebase_admin 9 | import datetime 10 | import requests 11 | import urllib 12 | import time 13 | from datetime import date 14 | from firebase_admin import credentials 15 | from firebase_admin import firestore 16 | from google.cloud import storage 17 | 18 | 19 | try: 20 | firebase_admin.delete_app(firebase_admin.get_app()) 21 | except: 22 | pass 23 | 24 | # Use a service account 25 | cred = credentials.Certificate('') # Add JSON key accordingly 26 | firebase_admin.initialize_app(cred) 27 | 28 | firebase_admin.get_app() 29 | db = firestore.client() 30 | 31 | for i in range(1, 2): 32 | # test image available variable 33 | image_available = 0 34 | 35 | # 36 | 37 | def upload_file(): 38 | global image_available 39 | image_url = "%2Ftemp_img_1" #Append projecy URL accordingly 40 | data = pickle.dumps(cv2.imread('1.jpg')) 41 | files = {'file':'1.data'} 42 | with open('1.pkl', 'wb') as outfile: 43 | outfile.write(data) 44 | 45 | files = {'1.pkl', open('1.pkl', 'wb')} 46 | try: 47 | my_request = requests.post(url=image_url, files=files) 48 | image_available = 1 49 | except: 50 | print("Failed to get file from RPI 1 at: " + str(datetime.datetime.now())) 51 | image_available = 0 52 | upload_file() 53 | 54 | doc_ref = db.collection(u'RPIs').document(u'1') 55 | doc_ref.set({ 56 | u'1 rpi': u'1', 57 | u'2 date': str(date.today()), 58 | u'3 time': str(datetime.datetime.now().time()), 59 | u'4 imagestate': u'available' 60 | }) 61 | if image_available == 1: 62 | doc_ref.update({ 63 | u'4 imagestate': u'available' 64 | }) 65 | elif image_available == 0: 66 | doc_ref.update({ 67 | u'4 imagestate': u'unavailable' 68 | }) 69 | time.sleep(1) 70 | 71 | 72 | 73 | firebase_admin.delete_app(firebase_admin.get_app()) -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/06_be544658-0682-45ea-8461-9ecee8e482f2_2048x2048.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/06_be544658-0682-45ea-8461-9ecee8e482f2_2048x2048.jpg -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/1555308468557.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/1555308468557.png -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/1555308481700.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/1555308481700.png -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/1555308490615.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/1555308490615.png -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/1555308503717.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/1555308503717.png -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/1555308527000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/1555308527000.png -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/1555308539968.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/1555308539968.png -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/1555308548007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/1555308548007.png -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/1555308556859.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/1555308556859.png -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/Capture.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/Capture.PNG -------------------------------------------------------------------------------- /Flipsky VESC 4.12/assets/Capture2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Flipsky VESC 4.12/assets/Capture2.PNG -------------------------------------------------------------------------------- /Git/assets/1564656014639.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564656014639.png -------------------------------------------------------------------------------- /Git/assets/1564661426621.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564661426621.png -------------------------------------------------------------------------------- /Git/assets/1564670491164.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564670491164.png -------------------------------------------------------------------------------- /Git/assets/1564670575453.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564670575453.png -------------------------------------------------------------------------------- /Git/assets/1564670713444.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564670713444.png -------------------------------------------------------------------------------- /Git/assets/1564670827975.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564670827975.png -------------------------------------------------------------------------------- /Git/assets/1564670879735.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564670879735.png -------------------------------------------------------------------------------- /Git/assets/1564670936504.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564670936504.png -------------------------------------------------------------------------------- /Git/assets/1564671383062.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564671383062.png -------------------------------------------------------------------------------- /Git/assets/1564671619233.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564671619233.png -------------------------------------------------------------------------------- /Git/assets/1564673599570.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564673599570.png -------------------------------------------------------------------------------- /Git/assets/1564673699537.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564673699537.png -------------------------------------------------------------------------------- /Git/assets/1564673784329.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564673784329.png -------------------------------------------------------------------------------- /Git/assets/1564673837741.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564673837741.png -------------------------------------------------------------------------------- /Git/assets/1564673840133.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564673840133.png -------------------------------------------------------------------------------- /Git/assets/1564674025862.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564674025862.png -------------------------------------------------------------------------------- /Git/assets/1564674585048.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564674585048.png -------------------------------------------------------------------------------- /Git/assets/1564674760940.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564674760940.png -------------------------------------------------------------------------------- /Git/assets/1564674894012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564674894012.png -------------------------------------------------------------------------------- /Git/assets/1564675060000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/1564675060000.png -------------------------------------------------------------------------------- /Git/assets/Interface1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/Interface1.png -------------------------------------------------------------------------------- /Git/assets/add-submodule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/add-submodule.png -------------------------------------------------------------------------------- /Git/assets/branching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/branching.png -------------------------------------------------------------------------------- /Git/assets/centr-decentr@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/centr-decentr@2x.png -------------------------------------------------------------------------------- /Git/assets/commit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/commit.png -------------------------------------------------------------------------------- /Git/assets/create-new-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/create-new-repo.png -------------------------------------------------------------------------------- /Git/assets/create-pr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/create-pr.png -------------------------------------------------------------------------------- /Git/assets/delete-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/delete-button.png -------------------------------------------------------------------------------- /Git/assets/diff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/diff.png -------------------------------------------------------------------------------- /Git/assets/git-model@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/git-model@2x.png -------------------------------------------------------------------------------- /Git/assets/merge-without-ff@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/merge-without-ff@2x.png -------------------------------------------------------------------------------- /Git/assets/multi_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/multi_file.png -------------------------------------------------------------------------------- /Git/assets/pick-branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/pick-branch.png -------------------------------------------------------------------------------- /Git/assets/pr-form.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/pr-form.png -------------------------------------------------------------------------------- /Git/assets/pr-tab.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/pr-tab.gif -------------------------------------------------------------------------------- /Git/assets/readme-edits.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/readme-edits.gif -------------------------------------------------------------------------------- /Git/assets/update-submodule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Git/assets/update-submodule.png -------------------------------------------------------------------------------- /OpenCV-Cpp/examples/load_image.cpp: -------------------------------------------------------------------------------- 1 | //Uncomment the following line if you are compiling this code in Visual Studio 2 | //#include "stdafx.h" 3 | 4 | #include 5 | #include 6 | 7 | using namespace cv; 8 | using namespace std; 9 | 10 | // Put file name here 11 | String file_name("test.jpg"); 12 | 13 | int main(int argc, char** argv) 14 | { 15 | // Read the image file 16 | Mat image = imread(file_name, IMREAD_COLOR); 17 | 18 | // Check for failure 19 | if (image.empty()) 20 | { 21 | cout << "Could not open or find the image" << endl; 22 | cin.get(); //wait for any key press 23 | return -1; 24 | } 25 | 26 | String windowName = "The Guitar"; //Name of the window 27 | 28 | namedWindow(windowName); // Create a window 29 | 30 | imshow(windowName, image); // Show our image inside the created window. 31 | 32 | waitKey(0); // Wait for any keystroke in the window 33 | 34 | destroyWindow(windowName); //destroy the created window 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /OpenCV-Cpp/examples/load_video_file.cpp: -------------------------------------------------------------------------------- 1 | //Uncomment the following line if you are compiling this code in Visual Studio 2 | //#include "stdafx.h" 3 | 4 | #include 5 | #include 6 | 7 | using namespace cv; 8 | using namespace std; 9 | 10 | // video file 11 | String vid_file("test.mp4") 12 | 13 | int main(int argc, char* argv[]) 14 | { 15 | //open the video file for reading 16 | VideoCapture cap(vid_file); 17 | 18 | // if not success, exit program 19 | if (cap.isOpened() == false) 20 | { 21 | cout << "Error" << endl; 22 | cin.get(); //wait for any key press 23 | return -1; 24 | } 25 | 26 | //get the frames rate of the video 27 | double fps = cap.get(CAP_PROP_FPS); 28 | cout << "Frames per seconds : " << fps << endl; 29 | 30 | String window_name = "video test"; 31 | 32 | namedWindow(window_name, WINDOW_NORMAL); //create a window 33 | 34 | while (true) 35 | { 36 | Mat frame; 37 | bool bSuccess = cap.read(frame); // read a new frame from video 38 | 39 | //Breaking the while loop at the end of the video 40 | if (bSuccess == false) 41 | { 42 | cout << "Found the end of the video" << endl; 43 | break; 44 | } 45 | 46 | //show the frame in the created window 47 | imshow(window_name, frame); 48 | 49 | //wait for for 10 ms until any key is pressed. 50 | //If the 'Esc' key is pressed, break the while loop. 51 | //If the any other key is pressed, continue the loop 52 | //If any key is not pressed withing 10 ms, continue the loop 53 | if (waitKey(10) == 27) 54 | { 55 | cout << "Stopping Video" << endl; 56 | break; 57 | } 58 | } 59 | 60 | return 0; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /OpenCV-Python/assets/1563808324844.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/OpenCV-Python/assets/1563808324844.png -------------------------------------------------------------------------------- /OpenCV-Python/assets/1563810074231.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/OpenCV-Python/assets/1563810074231.png -------------------------------------------------------------------------------- /OpenCV-Python/assets/1563894456180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/OpenCV-Python/assets/1563894456180.png -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/aruco_detector.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # This is a class implementation of aruco detection 18 | 19 | 20 | import cv2 21 | import numpy as np 22 | 23 | import cv2.aruco as aruco 24 | 25 | 26 | class aruco_detector: 27 | 28 | # aruco format determines the type of aruco markers being used (number of bits) 29 | # allowable values are 4, 5 or 6 30 | def __init__(self, aruco_format=6): 31 | 32 | # Checks aruco_format, will always default to 6x6 aruco if funny values are set 33 | if aruco_format == 4: 34 | 35 | self.aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_250) 36 | 37 | elif aruco_format == 5: 38 | 39 | self.aruco_dict = aruco.Dictionary_get(aruco.DICT_5X5_250) 40 | 41 | else: 42 | 43 | self.aruco_dict = aruco.Dictionary_get(aruco.DICT_6X6_250) 44 | 45 | # create aruco params 46 | self.parameters = aruco.DetectorParameters_create() 47 | 48 | #font for displaying text (below) 49 | self.font = cv2.FONT_HERSHEY_SIMPLEX 50 | 51 | # takes a frame (default is full color frame) 52 | # returns the list of corners and ids 53 | def return_aruco_ids(self, frame, full_color=True): 54 | 55 | if full_color: 56 | 57 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 58 | 59 | 60 | else: 61 | 62 | gray = frame.copy() 63 | # gets the corners and ids of aruco markers 64 | corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, self.aruco_dict, parameters=self.parameters) 65 | 66 | 67 | return corners, ids 68 | 69 | # subroutine to draw the markers on a selected frame 70 | # takes in corners, ids and text to be drawn 71 | # set id_flag or text_flag to True if they need to be drawn 72 | def draw_markers(self, frame, corners, ids, text=None, id_flag=False, text_flag=False): 73 | if ids == None: 74 | 75 | print("[ERROR] No Markers to draw") 76 | aruco.drawDetectedMarkers(frame, corners) 77 | print(corners) 78 | 79 | 80 | if id_flag: 81 | for i in range(len(ids)): 82 | cv2.putText(frame, ids[i], (corners[i]), self.font, 1, (0,255,0),2,cv2.LINE_AA) 83 | 84 | if text_flag: 85 | for i in range(len(text)): 86 | cv2.putText(frame, text[i], ((int(corners[i][0][0][0]), int(corners[i][0][0][1]))), self.font, 1, (0,255,0),1,cv2.LINE_AA) 87 | 88 | 89 | 90 | ## Test code ## 91 | 92 | if __name__ == '__main__': 93 | image = cv2.imread("test.jpg") 94 | a_detector = aruco_detector() 95 | corner, ids = a_detector.return_aruco_ids() 96 | a_detector.draw_markers(image, corner, ids) 97 | 98 | cv2.imshow('image', image) 99 | if cv2.waitKey(1) & 0xFF == ord('q'): 100 | break 101 | 102 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/circumcenter_demo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | # This is a circumcenter detection demo 17 | # It requires sympy to run 18 | 19 | 20 | import cv2 21 | import numpy as np 22 | import time 23 | import random 24 | 25 | 26 | from PIL import Image 27 | from math import cos 28 | from sympy import Point, Polygon, pi 29 | 30 | # =========== INSERT YOUR GRAYSCALE IMAGE HERE =============== 31 | GRAYSCALE_IMAGE = 'test.jpg' 32 | # ============================================================ 33 | 34 | frame = cv2.imread(GRAYSCALE_IMAGE, 0) 35 | height, width = frame.shape[:2] 36 | centre = (int(width/2), int(height/2)) 37 | dX, dY = 0,0 38 | 39 | trials = 1 40 | try: 41 | # Get the array of indices of detected pixels 42 | thresholded_array = np.argwhere(frame >= 0.3) 43 | thresholded_list = thresholded_array.tolist() 44 | print(thresholded_list) 45 | 46 | 47 | if len(thresholded_list) > trials*3: 48 | # sets the number of trials before averaging to get the centre 49 | 50 | total_centres_X = 0 51 | total_centres_Y = 0 52 | hoop_centre = (0,0) 53 | arr_len_3rd = int(len(thresholded_list) / 3) 54 | for i in range(trials): 55 | r1 = random.randrange(0, int(arr_len_3rd/2)) 56 | 57 | #r2 = random.randrange(0, arr_len_3rd) 58 | # rerolls if the same number was rolled 59 | #while r2 == r1: 60 | r2 = random.randrange(arr_len_3rd, 2*arr_len_3rd) 61 | r3 = random.randrange(int(2.5*arr_len_3rd), len(thresholded_list)) 62 | #while r3 == r1 or r3 == r2: 63 | #r3 = random.randrange(0, len(thresholded_list)) 64 | print(thresholded_list[r1],thresholded_list[r2],thresholded_list[r3]) 65 | current_centre = Polygon(thresholded_list[r1],thresholded_list[r2],thresholded_list[r3]).circumcenter 66 | print(current_centre) 67 | total_centres_X += int(current_centre.y) 68 | total_centres_Y += int(current_centre.x) 69 | cv2.circle(frame, (thresholded_list[r1][1], thresholded_list[r1][0]), 5, (0, 0, 255), -1) 70 | cv2.circle(frame, (thresholded_list[r2][1], thresholded_list[r2][0]), 5, (0, 0, 255), -1) 71 | cv2.circle(frame, (thresholded_list[r3][1], thresholded_list[r3][0]), 5, (0, 0, 255), -1) 72 | 73 | cX = int(total_centres_X / trials) 74 | cY = int(total_centres_Y / trials) 75 | 76 | print(cX,cY) 77 | except: 78 | print("no circle detected") 79 | 80 | # put text and highlight the center 81 | try: 82 | cv2.circle(frame, (cX, cY), 5, (255, 255, 255), -1) 83 | cv2.line(frame, centre, (cX, cY), (255,0,0), 2) 84 | 85 | #cv2.putText(frame, "centroid", (cX - 25, cY - 25),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2) 86 | 87 | dX = cX - centre[0] 88 | dY = centre[1] - cY 89 | cv2.putText(frame, ("(" + str(dX) + ", " + str(dY) + " )"), (centre[0] - 20, centre[1] - 20), 90 | cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2) 91 | 92 | except: 93 | print("No centre detected") 94 | 95 | 96 | 97 | 98 | 99 | cv2.imwrite('output.jpg', img_rec_red2) -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/contour_centroid_detection.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # Contour and centroid Detection Demo 18 | 19 | 20 | import cv2 21 | import numpy as np 22 | 23 | 24 | cap = cv2.VideoCapture(0) 25 | 26 | while True; 27 | 28 | ret, frame = cap.read() 29 | 30 | if ret: 31 | 32 | img2, contours, hierarchy = cv2.findContours(frame,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) 33 | for c in contours: 34 | if cv2.contourArea(c) > minimumArea: 35 | # calculate moments for each contour 36 | M = cv2.moments(c) 37 | cX = int(M["m10"] / M["m00"]) 38 | cY = int(M["m01"] / M["m00"]) 39 | cv2.circle(frame, (cX, cY), 5, (255, 100, 255), -1) 40 | cv2.putText(frame, "centroid", (cX - 25, cY - 25),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2) 41 | cv2.drawContours(frame, [c], -1, (255, 100, 255), 2) 42 | x,y,w,h = cv2.boundingRect(c) 43 | cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2) 44 | rX = int(x+(w/2)) 45 | rY = int(y+(h/2)) 46 | cv2.circle(frame, (rX, rY), 5, (0,255,255), -1) 47 | 48 | 49 | cv2.imshow('centroid_test', frame) 50 | 51 | key = cv2.waitKey(1) & 0xFF 52 | 53 | if key == ord("q"): 54 | break 55 | 56 | 57 | cap.release() 58 | cv2.destroyAllWindows() 59 | -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/draw_bounding_boxes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | # This script contains 2 functions for drawing bounding boxes on frames based on the output of a model 17 | # Convention 0 refers to [x, y, w, h] convention 18 | # Convention 1 refers to [x1, y1, x2, y2] convention 19 | 20 | import cv2 21 | 22 | 23 | def draw_boxes_conv0(frame, boundingboxlist): 24 | 25 | for box in boundingboxlist: 26 | x = box[0] 27 | y = box[1] 28 | w = box[2] 29 | h = box[3] 30 | cv2.rectangle(frame, (x, y), (int(x + w), int(y + h)), (0,0,255), 3) 31 | 32 | return frame 33 | 34 | def draw_boxes_conv1(frame, boundingboxlist): 35 | 36 | for box in boundingboxlist: 37 | x1 = box[0] 38 | y1 = box[1] 39 | x2 = box[2] 40 | y2 = box[3] 41 | cv2.rectangle(frame, (x1, y1), (x2, y2), (0,0,255), 3) 42 | 43 | return frame -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/hough_circles_demo.py: -------------------------------------------------------------------------------- 1 | # This script was adapted from https://docs.opencv.org/master/da/d53/tutorial_py_houghcircles.html 2 | # It is only lightly modified by Fasermaler 3 | 4 | import numpy as np 5 | import cv2 as cv 6 | 7 | # ================== PUT IMAGE HERE ================= 8 | IMAGE = 'test.jpg' 9 | # =================================================== 10 | 11 | img = cv.imread(IMAGE, 0) 12 | img = cv.medianBlur(img,5) 13 | cimg = cv.cvtColor(img,cv.COLOR_GRAY2BGR) 14 | circles = cv.HoughCircles(img,cv.HOUGH_GRADIENT,1,20, 15 | param1=50,param2=30,minRadius=0,maxRadius=0) 16 | circles = np.uint16(np.around(circles)) 17 | for i in circles[0,:]: 18 | # draw the outer circle 19 | cv.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2) 20 | # draw the center of the circle 21 | cv.circle(cimg,(i[0],i[1]),2,(0,0,255),3) 22 | cv.imshow('detected circles',cimg) 23 | cv.waitKey(0) 24 | cv.destroyAllWindows() -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/ip_cam_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # IP Camera test viewer 18 | # Change the connection URL to the correct URL and go ahead to test your IP camera! 19 | 20 | 21 | import numpy as np 22 | import cv2 23 | import time 24 | 25 | 26 | # ================= PUT CONNECTION URL HERE ==================== 27 | CONNECTION_URL = 'rtsp://admin:12345@192.168.0.11:554/MediaInput/h264' 28 | # ============================================================== 29 | 30 | cap = cv2.VideoCapture(CONNECTION_URL) 31 | 32 | 33 | 34 | count = 0 35 | while(True): 36 | 37 | ret, frame = cap.read() 38 | 39 | try: 40 | cv2.imshow('frame', frame) 41 | 42 | except Exception as e: 43 | print(e) 44 | 45 | # Check if connection failed for 10s before closing 46 | if count > 10: 47 | break 48 | else: 49 | count+= 1 50 | time.sleep(1) 51 | print(count) 52 | 53 | if cv2.waitKey(1) & 0xFF == ord('q'): 54 | break 55 | 56 | cap.release() 57 | cv2.destroyAllWindows() 58 | 59 | -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/morph_transform_demo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # This is a morphological transform demo 18 | # It will display the effects of a simple cross kernel with erode, dilate, blackhat and tophat 19 | 20 | 21 | cap = cv2.VideoCapture(0) 22 | 23 | # Feel free to design a new kernel of your choosing 24 | KERNEL = cv2.getStructuringElement(cv2.MORPH_CROSS,(9,9)) # 9x9 cross kernel 25 | 26 | # Invert the frame 27 | INVERT = False 28 | 29 | # Enable or disable thresholding 30 | # Disabling will mena the image will be converted to gray 31 | THRESH = True 32 | 33 | 34 | while True: 35 | 36 | ret, frame = cap.read() 37 | 38 | if ret: 39 | cv2.imshow('original', frame) 40 | 41 | if THRESH: 42 | ret, gray_img = cv2.threshold(frame,10,255,cv2.THRESH_BINARY) 43 | else: 44 | gray_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 45 | 46 | if INVERT: 47 | gray_img = cv2.bitwise_not(gray_img, gray_img) 48 | 49 | 50 | cv2.imshow('thresholded', gray_img) 51 | 52 | eroded_frame = cv2.erode(gray_img, kernel) # Erode transform 53 | dilated_frame = cv2.dilate(gray_img, kernel) # Dilate transform 54 | 55 | tophat = cv2.morphologyEx(gray_img, cv2.MORPH_TOPHAT, kernel) # Top Hat transform 56 | blackhat = cv2.morphologyEx(gray_img, cv2.MORPH_BLACKHAT, kernel) # Black Hat transform 57 | 58 | 59 | cv2.imshow('eroded', eroded_frame) 60 | cv2.imshow('dilated', dilated_frame) 61 | cv2.imshow('tophat', tophat) 62 | cv2.imshow('blackhat', blackhat) 63 | 64 | 65 | 66 | if cv2.waitKey(1) & 0xFF == ord('q'): 67 | break 68 | 69 | cap.release() 70 | cv2.destroyAllWindows() 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/picamera_scripts/pi_camera_single_frame.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # This script gets one frame from the Pi Camera and displays it 18 | 19 | 20 | from picamera.array import PiRGBArray 21 | from picamera import PiCamera 22 | import time 23 | import cv2 24 | 25 | # initialize the camera and grab a reference to the raw camera capture 26 | camera = PiCamera() 27 | rawCapture = PiRGBArray(camera) 28 | 29 | # allow the camera to warmup 30 | time.sleep(0.1) 31 | 32 | # grab an image from the camera 33 | camera.capture(rawCapture, format="bgr") 34 | image = rawCapture.array 35 | 36 | # display the image on screen and wait for a keypress 37 | cv2.imwrite("test.jpg", image) 38 | #cv2.waitKey(0) -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/picamera_scripts/pi_camera_video.py: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/python 3 | # coding=utf-8 4 | 5 | # 29-05-2019 6 | 7 | # This script was written by: 8 | 9 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 10 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 11 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 12 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 13 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 14 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 15 | 16 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 17 | 18 | # Pi Camera Video script with options and frame buffer flush 19 | 20 | 21 | 22 | from picamera.array import PiRGBArray 23 | from picamera import PiCamera 24 | import cv2 25 | import timestamp 26 | import time 27 | import numpy as np 28 | from PIL import Image 29 | 30 | 31 | # Set if you'd like the buffer to be cleared 32 | CLEAR_BUFFER = False 33 | 34 | # initialize the camera and grab a reference to the raw camera capture 35 | camera = PiCamera() 36 | camera.resolution = (426, 240) 37 | camera.framerate = 32 38 | 39 | 40 | # ======================== ADDITIONAL OPTIONS: UNCOMMENT IF NECESSARY ========================== 41 | camera.exposure_mode = 'off' # Turn off auto exposure compensation 42 | camera.exposure_compensation = -3 # Set the specific level of exposure compensation 43 | camera.drc_strength = 'off' # Sets the dynamic range compression 44 | camera.still_stats = False # Retrieves or sets whether statistics will be calculated from still frames or the prior preview frame 45 | camera.awb_mode = 'off' # Turn off auto white balance 46 | camera.awb_gains = (Fraction(25, 16), Fraction(25,16)) # Set a specific white balance gain 47 | # ============================================================================================== 48 | 49 | rawCapture = PiRGBArray(camera, size=(426, 240)) 50 | 51 | # allow the camera to warmup 52 | time.sleep(0.1) 53 | 54 | # Initializes the image counting 55 | count = 0 56 | 57 | # capture frames from the camera 58 | for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): 59 | # grab the raw NumPy array representing the image, then initialize the timestamp 60 | # and occupied/unoccupied text 61 | 62 | 63 | # Clears the buffer if the user would like it 64 | if CLEAR_BUFFER: 65 | for i in range(5): # Clears the 5 frame buffer 66 | frame = img.array 67 | 68 | else: 69 | image = frame.array 70 | 71 | # show the frame 72 | cv2.imshow("Pi Camera Video Test", image) 73 | #img2 = Image.fromarray(frame, 'RGB') 74 | #img2.show() 75 | key = cv2.waitKey(1) & 0xFF 76 | 77 | # clear the stream in preparation for the next frame 78 | rawCapture.truncate(0) 79 | 80 | # if the `q` key was pressed, break from the loop 81 | # if the `c` key was pressed, saved the current frame 82 | if key == ord("q"): 83 | break 84 | elif key == ord('c'): 85 | filename = "image" + str(count) + ".jpg" 86 | cv2.imwrite(filename, image) 87 | count += 1 88 | 89 | 90 | 91 | 92 | cv2.destroyAllWindows() 93 | camera.close() -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/red_thresholding_demo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # Red thresholding demo 18 | # Filters red and only red to produce a very strong signal 19 | # Will require calibration and is very suseceptible to lighting changes 20 | # This is not a robust algorithm and should not be treated as such 21 | # However, in specific use cases, it will produce a much clearer signal than hue or other color based methods 22 | 23 | 24 | # Sets the percentage red threshold, below which a pixel will be eliminated from the final result 25 | PERC_RED_THRESH = 0.3 26 | 27 | cap = cv2.VideoCapture(0) 28 | 29 | 30 | while True: 31 | 32 | ret, frame = cap.read() 33 | 34 | if ret: 35 | cv2.imshow('original', frame) 36 | 37 | # Gets the individual color channels 38 | # The format assumed here is bgr 39 | b_channel = np.array(frame[:,:,0]).astype('float') 40 | g_channel = np.array(frame[:,:,1]).astype('float') 41 | r_channel = np.array(frame[:,:,2]).astype('float') 42 | 43 | # Create a base channel where all values are added together 44 | bgr_channel = np.add((np.add(b_channel, g_channel)), r_channel) 45 | 46 | # Take the average of the blue and green channels and subtract it from the red channel 47 | # This will eliminate white color from the final image 48 | reduce_white = np.subtract(r_channel,((b_channel + g_channel)/ 2)) 49 | 50 | # Find the percentage red by dividing the previous channel by 255 51 | perc_red = np.divide(reduce_white,255) 52 | 53 | # Eliminate all pixels that fail to meet the minimum percentage red using numpy conditional array value setting 54 | perc_red[perc_red < PERC_RED_THRESH] = 0 55 | 56 | # Set the values back to within a range of 255 and set the type back to uint8 so that the frame becomes valid for OpenCV processing 57 | final_image = perc_red * 255 58 | final_image = np.floor(final_image).astype('uint8') 59 | 60 | cv2.imshow('red filtered', final_image) 61 | 62 | # Run another round of openCV thresholding as required 63 | ret, th = cv2.threshold(final_image,10,255,cv2.THRESH_BINARY) 64 | 65 | cv2.imshow('thresholded red', th) 66 | 67 | if cv2.waitKey(1) & 0xFF == ord('q'): 68 | break 69 | 70 | cap.release() 71 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/roi_selection_demo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # This is an ROI selection demo 18 | # Instructions can be found on the utility itself 19 | 20 | import numpy as np 21 | import cv2 22 | 23 | 24 | 25 | # Defines the font to be used 26 | font = cv2.FONT_HERSHEY_SIMPLEX 27 | 28 | # Initializes the reference points array 29 | ref_points = [] 30 | 31 | # Mouse event function 32 | def mouse_selection(event, x, y, flags, params): 33 | global ref_points 34 | 35 | if (event == cv2.EVENT_LBUTTONDOWN) and (len(ref_points) < 4): 36 | ref_points.append((x,y)) 37 | 38 | 39 | cap = cv2.VideoCapture(0) 40 | 41 | # Skips the first 49 frames due to initialization 42 | for i in range(50): 43 | ret, frame = cap.read() 44 | 45 | cap.release() 46 | 47 | frame_width = frame.shape[0] 48 | # Resize the frame if the resolution is too large 49 | if frame_width > 1000: 50 | frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation = cv2.INTER_CUBIC) 51 | 52 | # Creates the padding around the image 53 | bordersize = 200 54 | orig_border = cv2.copyMakeBorder(frame, 55 | top=bordersize, 56 | bottom=bordersize, 57 | left=bordersize, 58 | right=bordersize, 59 | borderType=cv2.BORDER_CONSTANT, 60 | value=[96, 96, 96]) 61 | 62 | row, col = orig_border.shape[:2] 63 | 64 | cv2.namedWindow("ROI Selector") 65 | cv2.setMouseCallback("ROI Selector", mouse_selection) 66 | 67 | # Status variable for on-screen status printout 68 | status = "" 69 | 70 | while True: 71 | # ensures that every frame gets refreshed 72 | frame = orig_border.copy() 73 | 74 | # On-screen Keyboard legend 75 | cv2.putText(frame, 'ROI Selection Demo written by Fasermaler', (10,30), font, 1, (0, 128 ,255),2, cv2.LINE_AA) 76 | cv2.putText(frame, "Keyboard Shortcuts:", (10,50), font, 0.5, (0, 255 ,255),2, cv2.LINE_AA) 77 | cv2.putText(frame, "U - Undo", (10,70), font, 0.5, (0, 255 ,255),2, cv2.LINE_AA) 78 | cv2.putText(frame, "Esc - Clear", (10,90), font, 0.5, (0, 255 ,255),2, cv2.LINE_AA) 79 | cv2.putText(frame, "S - Save", (10,110), font, 0.5, (0, 255 ,255),2, cv2.LINE_AA) 80 | cv2.putText(frame, "Q - Quit", (10,130), font, 0.5, (0, 255 ,255),2, cv2.LINE_AA) 81 | 82 | # Draw lines with each point clicked 83 | if len(ref_points) > 1: 84 | cv2.line(frame, ref_points[0], ref_points[1], (0, 0, 255), 2) 85 | if len(ref_points) > 2: 86 | cv2.line(frame, ref_points[1], ref_points[2], (0, 0, 255), 2) 87 | if len(ref_points) > 3: 88 | cv2.line(frame, ref_points[2], ref_points[3], (0, 0, 255), 2) 89 | cv2.line(frame, ref_points[3], ref_points[0], (0, 0, 255), 2) 90 | 91 | # Correct the reference points due to padding and/or scaling 92 | corrected_ref_points = [] 93 | for i in range(len(ref_points)): 94 | if frame_width < 1000: 95 | corrected_point = (ref_points[i][0] - bordersize), (ref_points[i][1] - bordersize) 96 | else: 97 | corrected_point = (ref_points[i][0] - bordersize)*2, (ref_points[i][1] - bordersize)*2 98 | corrected_ref_points.append(corrected_point) 99 | 100 | # Reflect the selected points on screen 101 | cv2.putText(frame, 'Selected Points: ' + str(corrected_ref_points), (10,row-10), font, 0.5, (0, 0 ,255),2, cv2.LINE_AA) 102 | cv2.putText(frame, status, (col-55,row-10), font, 0.5, (0, 255 ,0),2, cv2.LINE_AA) 103 | cv2.imshow('ROI Selector', frame) 104 | 105 | #print(ref_points) 106 | 107 | 108 | # Various key events 109 | key = cv2.waitKey(1) & 0xFF 110 | 111 | # Esc key will reset the ref_points list 112 | if key == 27: 113 | ref_points = [] 114 | status = "RESET" 115 | 116 | # U key will remove last point selected 117 | if key == ord('u'): 118 | ref_points.pop() 119 | status = "UNDO" 120 | 121 | # S key will save if the ref_points list has 4 points 122 | if key == ord('s'): 123 | if len(ref_points) < 4: 124 | status = "ERROR" 125 | else: 126 | # THIS IS WHERE YOUR REF POINTS ARE 127 | # STORE THEM ELSEWHERE IF YOU NEED THEM 128 | print("Your selected ROI points are:\n") 129 | print(str(corrected_ref_points)) 130 | status = "SAVED" 131 | 132 | # Q will exit 133 | if key == ord('q'): 134 | break 135 | 136 | cv2.destroyAllWindows() 137 | 138 | -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/rotate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # This script contains a rotation function to rotate an image based on the angle required 18 | 19 | import cv2 20 | 21 | 22 | def rotate(image, angle, center=None, scale=1.0): 23 | 24 | (h, w) = image.shape[:2] 25 | 26 | 27 | if center is None: 28 | center = (w / 2, h / 2) 29 | 30 | M = cv2.getRotationMatrix2D(center, angle, scale) 31 | rotated = cv2.warpAffine(image, M, (w, h)) 32 | 33 | return rotated 34 | -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/split_four.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # This script splits a frame into 4 and returns the cropped images as a cropped array 18 | import cv2 19 | 20 | 21 | def split_into_four(frame): 22 | 23 | 24 | Width, Height = frame.shape[1], frame.shape[0] 25 | crop_h, crop_w = int(Height/2), int(Width/2) 26 | 27 | # Get the 4 cropped frames and put them in an array 28 | crop1 = frame[0:crop_h, 0:crop_w] 29 | crop2 = frame[0:crop_h, crop_w:Width] 30 | crop3 = frame[crop_h:Height, 0:crop_w] 31 | crop4 = frame[crop_h:Height, crop_w:Width] 32 | crop_array = [crop1, crop2, crop3, crop4] 33 | 34 | 35 | return crop_array 36 | -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/undistort_demo/camera_undistort_demo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # Camera undistortion demo 18 | # This is an undistortion demo, the mtx and dist should be obtained from the camera calib process 19 | 20 | import cv2 21 | 22 | import time 23 | import numpy as np 24 | from PIL import Image 25 | 26 | 27 | cap = cv2.VideoCapture(0) 28 | 29 | mtx = np.array([[ 1.31960797e+03, 0.00000000e+00, 1.00916350e+03], 30 | [ 0.00000000e+00, 1.35786213e+03, 6.36593029e+02], 31 | [ 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]) 32 | dist = np.array([[ -3.86818203e-01, 2.81274627e+00, -2.46548663e-02, 33 | -1.66810086e-05, -1.20151138e+01]]) 34 | 35 | while True: 36 | 37 | ret, frame = cap.read() 38 | 39 | h, w = frame.shape[:2] 40 | newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h)) 41 | undistort = cv2.undistort(frame, mtx, dist, None, newcameramtx) 42 | 43 | # show the frame 44 | cv2.imshow("preview", undistort) 45 | #img2 = Image.fromarray(frame, 'RGB') 46 | #img2.show() 47 | key = cv2.waitKey(1) & 0xFF 48 | 49 | # clear the stream in preparation for the next frame 50 | rawCapture.truncate(0) 51 | 52 | # if the `q` key was pressed, break from the loop 53 | if key == ord("q"): 54 | break 55 | # elif key == ord('c'): 56 | # filename = "image" + str(count) + ".jpg" 57 | # cv2.imwrite(filename, image) 58 | # count += 1 59 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/undistort_demo/checkerboard_calib.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | 17 | # Camera calibration script used to find the camera calibration matrix 18 | # Uses glob 19 | 20 | 21 | import numpy as np 22 | import cv2 as cv 23 | import glob 24 | # termination criteria 25 | criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 30, 0.001) 26 | # prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0) 27 | objp = np.zeros((6*7,3), np.float32) 28 | objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2) 29 | # Arrays to store object points and image points from all the images. 30 | objpoints = [] # 3d point in real world space 31 | imgpoints = [] # 2d points in image plane. 32 | images = glob.glob('*.jpg') 33 | for fname in images: 34 | img = cv.imread(fname) 35 | gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) 36 | # Find the chess board corners 37 | ret, corners = cv.findChessboardCorners(gray, (7,6), None) 38 | # If found, add object points, image points (after refining them) 39 | if ret == True: 40 | objpoints.append(objp) 41 | corners2 = cv.cornerSubPix(gray,corners, (11,11), (-1,-1), criteria) 42 | imgpoints.append(corners) 43 | # Draw and display the corners 44 | cv.drawChessboardCorners(img, (7,6), corners2, ret) 45 | cv.imshow('img', img) 46 | ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None) 47 | print(ret, mtx, dist, rvecs, tvecs) 48 | cv.waitKey(5) 49 | cv.destroyAllWindows() -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/video_cropper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | # This script allows the user to select a region of interest and then outputs a cropped video 17 | 18 | 19 | import cv2 20 | import numpy as np 21 | 22 | # =========== DEFINE INPUT AND OUTPUT VIDEO PATHS HERE ============ 23 | VIDEO_PATH = 'input_vid.mp4' 24 | OUTPUT = 'output_vid.avi' 25 | # ================================================================= 26 | 27 | 28 | 29 | cap = cv2.VideoCapture(VIDEO_PATH) 30 | 31 | frame_width = int(cap.get(3)) 32 | frame_height = int(cap.get(4)) 33 | refPt = [] 34 | cropping = False 35 | 36 | 37 | 38 | def click_and_crop(event, x, y, flags, param): 39 | # grab references to the global variables 40 | global refPt, cropping 41 | 42 | # if the left mouse button was clicked, record the starting 43 | # (x, y) coordinates and indicate that cropping is being 44 | # performed 45 | if event == cv2.EVENT_LBUTTONDOWN: 46 | refPt = [(x, y)] 47 | cropping = True 48 | 49 | # check to see if the left mouse button was released 50 | elif event == cv2.EVENT_LBUTTONUP: 51 | # record the ending (x, y) coordinates and indicate that 52 | # the cropping operation is finished 53 | refPt.append((x, y)) 54 | cropping = False 55 | 56 | # draw a rectangle around the region of interest 57 | cv2.rectangle(frame, refPt[0], refPt[1], (0, 255, 0), 2) 58 | cv2.imshow("image", frame) 59 | 60 | ret, frame = cap.read() 61 | clone = frame.copy() 62 | cv2.namedWindow('select ROI') 63 | cv2.setMouseCallback('select ROI', click_and_crop) 64 | 65 | 66 | while True: 67 | cv2.imshow('select ROI', frame) 68 | key = cv2.waitKey(1) & 0xFF 69 | 70 | # if the 'r' key is pressed, reset the cropping region 71 | if key == ord("r"): 72 | frame = clone.copy() 73 | 74 | # if the 'c' key is pressed, break from the loop 75 | elif key == ord("c"): 76 | roi = frame[refPt[0][1]:refPt[1][1], refPt[0][0]:refPt[1][0]] 77 | out = cv2.VideoWriter(OUTPUT,cv2.VideoWriter_fourcc(*'XVID'), 300, (roi.shape[1], roi.shape[0])) 78 | 79 | break 80 | 81 | if len(refPt) == 2: 82 | while True: 83 | ret, frame = cap.read() 84 | if ret: 85 | roi = frame[refPt[0][1]:refPt[1][1], refPt[0][0]:refPt[1][0]] 86 | cv2.imshow('ROI', roi) 87 | out.write(roi) 88 | if cv2.waitKey(1) & 0xFF == ord('q'): 89 | break 90 | 91 | cap.release() 92 | out.release() 93 | 94 | cv2.destroyAllWindows() 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/webcam_image.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | # This is a webcam single image display demo - it will display a single image upon instancing 17 | 18 | import cv2 19 | import numpy as np 20 | 21 | 22 | cap = cv2.VideoCapture(0) 23 | 24 | while True: 25 | ret, frame = cap.read() 26 | if ret: 27 | break 28 | 29 | cap.release() 30 | 31 | while True; 32 | 33 | cv2.imshow("Webcam Image Test", frame) 34 | 35 | key = cv2.waitKey(1) & 0xFF 36 | 37 | 38 | # if the `q` key was pressed, break from the loop 39 | # if the `c` key was pressed, saved the current frame 40 | if key == ord("q"): 41 | break 42 | 43 | 44 | 45 | 46 | 47 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /OpenCV-Python/sample_code/webcam_video.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # 29-05-2019 5 | 6 | # This script was written by: 7 | 8 | # ███████╗ █████╗ ███████╗███████╗██████╗ ███╗ ███╗ █████╗ ██╗ ███████╗██████╗ 9 | # ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔══██╗ 10 | # █████╗ ███████║███████╗█████╗ ██████╔╝██╔████╔██║███████║██║ █████╗ ██████╔╝ 11 | # ██╔══╝ ██╔══██║╚════██║██╔══╝ ██╔══██╗██║╚██╔╝██║██╔══██║██║ ██╔══╝ ██╔══██╗ 12 | # ██║ ██║ ██║███████║███████╗██║ ██║██║ ╚═╝ ██║██║ ██║███████╗███████╗██║ ██║ 13 | # ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ 14 | 15 | # For maintenance or enquiries, contact me at: https://github.com/fasermaler 16 | # This is a webcam video display demo 17 | # Press c to capture a frame 18 | 19 | import cv2 20 | import numpy as np 21 | 22 | 23 | cap = cv2.VideoCapture(0) 24 | 25 | while True; 26 | 27 | ret, frame = cap.read() 28 | 29 | if ret: 30 | # show the frame 31 | cv2.imshow("Webcam Video Test", frame) 32 | 33 | key = cv2.waitKey(1) & 0xFF 34 | 35 | 36 | 37 | # if the `q` key was pressed, break from the loop 38 | # if the `c` key was pressed, saved the current frame 39 | if key == ord("q"): 40 | break 41 | elif key == ord('c'): 42 | filename = "image" + str(count) + ".jpg" 43 | cv2.imwrite(filename, image) 44 | count += 1 45 | 46 | 47 | 48 | cap.release() 49 | cv2.destroyAllWindows() 50 | -------------------------------------------------------------------------------- /Quanum 3-Axis Mobius Gimbal/Documentation for Quanum 3-Axis Gimbal.md: -------------------------------------------------------------------------------- 1 | # Quanum 3-Axis Mobius Camera Based Gimbal 2 | 3 | Documentation for the Quanum 3-Axis Mobius Camera Based Gimbal. (Purchase link [here](https://hobbyking.com/en_us/quanum-3-axis-mobius-camera-based-gimbal.html?gclid=CjwKCAjwgabeBRBuEiwACD4R5pzr1hS_OftXpa5OPtl5WfkAG35Ie4TQcBOMSMw8y5pVsvsa1bz7rRoC8JMQAvD_BwE&gclsrc=aw.ds&___store=en_us) on Hobbyking). The official manual is sparse and available [here](https://cdn-global-hk.hobbyking.com/media/file/74871598X976235X4.pdf). 4 | 5 | ### Tuning Setup for the Gimbal 6 | 7 | The tuning of the PID and motor speed is to be done on **SimpleBGC_GUI_2_40b8**. This version is specific to the gimbal. The download is available [here](http://www.basecamelectronics.com/files/SimpleBGC_GUI_2_40b8.zip). Ensure that the gimbal is tuned with the camera or whichever weights you'd intend to carry in the actual flight/operation of the gimbal. 8 | 9 | 1. Set all power to 0 10 | 2. Set all PID to 0 11 | 3. Set Pitch power up in increments of 50 until you feel satisfactory resistance when you push on the camera 12 | 4. Increment Pitch P as much as possible until it begins to wobble, then drop it a bit 13 | 5. Increment pitch D until the wobbling stops, then continue to increasing until D starts to oscillate a high frequency, then drop D a bit 14 | 6. Observe camera as you change the angle, if you observe that the camera does not remain completely level it means that there is some steady state error which means we have to tune pitch I, else skip ahead to step 8 15 | 7. Increment Pitch I very slowly until the camera remains level throughout the entire range of motions 16 | 8. Set the same power and PID values for roll as well and test. 17 | 1. If camera over compensates roll, then reduce roll I 18 | 2. If camera wobbles too much, then reduce roll D 19 | 9. Set same power and PID values for Yaw from Pitch 20 | 1. If camera over compensates yaw, then reduce yaw I 21 | 2. If camera wobbles too much, then reduce yaw D 22 | 23 | ### Custom Mount for the Runcam 2 24 | 25 | To attach the Runcam 2, a custom mount was made and printed out. The CAD file is named "runcam2-mountv2.SLDPRT" and can be found in this folder. 26 | 27 | 1. Remove the screws to the original Runcam mount 28 | 2. Using a sharp tool, pry the IMU from the base of the mount 29 | 3. The IMU will now be free, but the wires of the IMU will run through the existing mount - unsolder these wires. However, the wires will be 1 red and 3 black, which means that **labelling the wires is necessary**. 30 | 4. If labelling of the wires is not possible, remove the top plate of the gimbal (the gimbal base) to look at the wiring going straight into the board. Feel free to conduct continuity checks with a multimeter to check on which wire is which 31 | 5. Thread the wires through the wire ports on the 3d-printed mount. 32 | 6. Solder the wires back onto the IMU through the wire ports on the new mount. Do continuity checks with a multimeter to check your work if necessary. 33 | 7. Attach the IMU firmly in the IMU slot using mounting tape or any form of flat adhesion - **this is critical** 34 | 8. Reattach the mount onto the gimbal arm using the original screws 35 | 9. The new mount should have been installed. Calibration can now begin 36 | 37 | -------------------------------------------------------------------------------- /Quanum 3-Axis Mobius Gimbal/runcam2-mountv2.SLDPRT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/Quanum 3-Axis Mobius Gimbal/runcam2-mountv2.SLDPRT -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Coding Notes / Miscellaneous Documentation 2 | 3 | Just a collection of random notes because I tend to forget things. 4 | 5 | ------ 6 | 7 | If you like my stuff, I would humbly ask you to drop a star. 8 | 9 | Thank you! 10 | 11 | ## Author's Note 12 | 13 | I'm unlikely to ever fully cover basics such as C++, Java and etc because I feel that other sites and resources cover them better. For instance, [Learn C++](https://www.learncpp.com/) is an excellent site for learning C++ and any attempts by myself to document it would be extremely lengthy and would not do it any justice. If you'd like a python reference, the [Digital World Python Cheatsheet](https://github.com/Fasermaler/coding-notes/blob/master/Digital%20World%20Python%20Cheat%20Sheet/10.009%20Digital%20World%20Cheat%20Sheet.md) might serve as such. 14 | 15 | Some documentation might just be notes and troubleshooting methods that I have had to use in the past when dealing with frameworks and thus might not be beginner-centric. 16 | 17 | Additional resources to learn these things and more can be found in [Additional Materials and Resources](#mats) 18 | 19 | ## Current Documentation File Tree 20 | 21 | - [Firebase](https://github.com/Fasermaler/coding-notes/blob/master/Firebase/Documentation%20for%20Firebase.md) 22 | - Firebase-admin SDK Documentation 23 | - Blob Documentation 24 | - [Retrieve](https://github.com/Fasermaler/coding-notes/blob/master/Firebase/retrieve_test.py) and [Upload](https://github.com/Fasermaler/coding-notes/blob/master/Firebase/upload_test.py) test codes 25 | - [OpenCV - Python](https://github.com/Fasermaler/coding-notes/blob/master/OpenCV-Python/OpenCV%20-%20Python.md) 26 | - Imports, Basic I/O, Slicing 27 | - PiCamera and IP Cameras 28 | - Drawing Functions 29 | - Hough Line / Hough Circle 30 | - Morphological Transforms 31 | - Centroid / Contours 32 | - Mouse Events 33 | - SIFT 34 | - Camera Calibration 35 | - Aruco 36 | - and a whole bunch of tips and tricks 37 | - Plenty of [example code](https://github.com/Fasermaler/coding-notes/tree/master/OpenCV-Python/sample_code) as well! 38 | - [ROS SMACH](https://github.com/Fasermaler/coding-notes/blob/master/ROS_SMACH/SMACH_Reference.md) 39 | - Data Transfers 40 | - Action Servers 41 | - Visualization 42 | - Concurrency 43 | - Visualizations 44 | - Recovery behavior 45 | - Includes [example workspace](https://github.com/Fasermaler/coding-notes/tree/master/ROS_SMACH/example_ws) with working visualization! 46 | - [Pwntools](https://github.com/Fasermaler/coding-notes/blob/master/Pwntools/pwntools.md) 47 | - Tubes 48 | - GDB 49 | - Assembly 50 | - ELF 51 | - [Flipsky VESC](https://github.com/Fasermaler/coding-notes/blob/master/Flipsky%20VESC%204.12/Flipsky%20VESC%204.12%20Documentation.md) 52 | - Introduction 53 | - Connections 54 | - Usage and Tuning for FOC 55 | - [Digital World Python Cheat Sheet](https://github.com/Fasermaler/coding-notes/blob/master/Digital%20World%20Python%20Cheat%20Sheet/10.009%20Digital%20World%20Cheat%20Sheet.md) 56 | - Python Cheat Sheet for SUTD's Digital World Module 57 | - [Quanum 3-Axis Mobius Camera Gimbal](https://github.com/Fasermaler/coding-notes/blob/master/Quanum%203-Axis%20Mobius%20Gimbal/Documentation%20for%20Quanum%203-Axis%20Gimbal.md) 58 | - Tuning 59 | - [3D CAD for Runcam mount](https://github.com/Fasermaler/coding-notes/blob/master/Quanum%203-Axis%20Mobius%20Gimbal/runcam2-mountv2.SLDPRT) 60 | 61 | ## Additional Materials 62 | 63 | [go to top](#top) 64 | 65 | - C 66 | - [Book: Computer Systems: A Programmer's Perspective](https://www.amazon.com/Computer-Systems-Programmers-Perspective-3rd/dp/013409266X) 67 | - Essential reading for any programmer as it touches on how computer systems actually work and how software can be made more efficient or robust by knowing the underlying systems (software or hardware) 68 | - [Book: Programming in ANSI C](https://www.amazon.in/Programming-ANSI-C-Balagurusamy/dp/933921966X) 69 | - Excellent no-frill reference that goes into great detail into the basics as well as intricacies of programming in C. 70 | 71 | - C++ 72 | - [Website: Learn C++](https://www.learncpp.com/) 73 | - Thorough step-by-step, topical walk-through of all the major components of C++ programming. Also has lots of pointers for good practices when writing code 74 | - [Website: Codecademy C++](https://www.codecademy.com/learn/learn-c-plus-plus) 75 | - Interactive online course to get you started immediately on C++ basics. The good part is that it reduces the initial barrier towards learning C++ as it runs directly on browser. 76 | 77 | - Python 78 | - [Book: Learn Python the Hard Way](https://www.amazon.com/Learn-Python-Hard-Way-Introduction/dp/0321884914) 79 | - Learn python the hard way is an excellent book that puts the reader through a myriad of exercises to learn and write python code properly, instilling good coding practices early. 80 | - [Website: Codecademy Python](https://www.codecademy.com/learn/learn-python) 81 | - Usually the go-to course for anyone trying to pick up python for the first time. It allows you to get right into the basics in your browser - no frills. 82 | 83 | - OpenCV - Python 84 | - [pyimagesearch](https://www.pyimagesearch.com/) 85 | - Great all around reference with plenty of example code and use cases 86 | - Has an email openCV course that is actually not garbage 87 | 88 | - Keras 89 | - [Book: Deep Learning with Python](https://www.amazon.com/Deep-Learning-Python-Francois-Chollet/dp/1617294438) 90 | - This book is literally written by the creator of Keras. It is a (relatively) fast read that goes through Keras functionality through examples as well as explaining Deep Learning concepts from the ground up. 91 | 92 | ## Useful Repositories 93 | 94 | - [rlcode](https://github.com/rlcode) 95 | - Lots of repositories on reinforcement learning and DQNs 96 | - Plenty of minimal code that can serve as building blocks 97 | - This person basically lives, breathes and eats reinforcement learning 98 | - [TheAlgorithms](https://github.com/TheAlgorithms/) 99 | - Lots of implementations for many many different types of algorithms in all languages 100 | - A good reference 101 | - [AtsushiSakai's Python Robotics](https://github.com/AtsushiSakai/PythonRobotics) 102 | - Huge repository of Python implementations of well known robotics algorithms 103 | - Includes visualizations as well 104 | 105 | 106 | 107 | ## To-Do 108 | 109 | One day, I'll get around to doing these. 110 | 111 | - Gazebo 7 for ROS Kinetic 112 | - EMACS 113 | - Basic and advanced Bash + Regex -------------------------------------------------------------------------------- /ros_smach/assets/1564069347372.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/assets/1564069347372.png -------------------------------------------------------------------------------- /ros_smach/assets/Copy of remap_sm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/assets/Copy of remap_sm.jpg -------------------------------------------------------------------------------- /ros_smach/assets/SM-1564061452245.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/assets/SM-1564061452245.jpg -------------------------------------------------------------------------------- /ros_smach/assets/SM.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/assets/SM.jpg -------------------------------------------------------------------------------- /ros_smach/assets/UntitledDiagram.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/assets/UntitledDiagram.jpg -------------------------------------------------------------------------------- /ros_smach/assets/UntitledDiagram2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/assets/UntitledDiagram2.jpg -------------------------------------------------------------------------------- /ros_smach/assets/recovery.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/assets/recovery.jpg -------------------------------------------------------------------------------- /ros_smach/assets/simplestate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/assets/simplestate.jpg -------------------------------------------------------------------------------- /ros_smach/example_ws/.catkin_workspace: -------------------------------------------------------------------------------- 1 | # This file currently only serves to mark the location of a catkin workspace for tool integration 2 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | /opt/ros/kinetic/share/catkin/cmake/toplevel.cmake -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/.catkin.options: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/.catkin.options -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/.dependencies.rosinstall: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/.dependencies.rosinstall -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/.travis.yml: -------------------------------------------------------------------------------- 1 | # Generic .travis.yml file for running continuous integration on Travis-CI with 2 | # any ROS package. 3 | # 4 | # Available here: 5 | # - http://felixduvallet.github.io/ros-travis-integration 6 | # - https://github.com/felixduvallet/ros-travis-integration 7 | # 8 | # This installs ROS on a clean Travis-CI virtual machine, creates a ROS 9 | # workspace, resolves all listed dependencies, and sets environment variables 10 | # (setup.bash). Then, it compiles the entire ROS workspace (ensuring there are 11 | # no compilation errors), and runs all the tests. If any of the compilation/test 12 | # phases fail, the build is marked as a failure. 13 | # 14 | # We handle two types of package dependencies: 15 | # - packages (ros and otherwise) available through apt-get. These are installed 16 | # using rosdep, based on the information in the ROS package.xml. 17 | # - dependencies that must be checked out from source. These are handled by 18 | # 'wstool', and should be listed in a file named dependencies.rosinstall. 19 | # 20 | # There are two variables you may want to change: 21 | # - ROS_DISTRO (default is indigo). Note that packages must be available for 22 | # ubuntu 14.04 trusty. 23 | # - ROSINSTALL_FILE (default is dependencies.rosinstall inside the repo 24 | # root). This should list all necessary repositories in wstool format (see 25 | # the ros wiki). If the file does not exists then nothing happens. 26 | # 27 | # See the README.md for more information. 28 | # 29 | # Author: Felix Duvallet 30 | 31 | # NOTE: The build lifecycle on Travis.ci is something like this: 32 | # before_install 33 | # install 34 | # before_script 35 | # script 36 | # after_success or after_failure 37 | # after_script 38 | # OPTIONAL before_deploy 39 | # OPTIONAL deploy 40 | # OPTIONAL after_deploy 41 | 42 | ################################################################################ 43 | 44 | # Use ubuntu trusty (14.04) with sudo privileges. 45 | sudo: required 46 | language: generic 47 | cache: 48 | - apt 49 | matrix: 50 | include: 51 | - dist: precise 52 | os: linux 53 | env: 54 | - ROS_DISTRO=hydro 55 | - dist: trusty 56 | os: linux 57 | env: 58 | - ROS_DISTRO=indigo 59 | - dist: trusty 60 | os: linux 61 | env: 62 | - ROS_DISTRO=jade 63 | 64 | # Configuration variables. All variables are global now, but this can be used to 65 | # trigger a build matrix for different ROS distributions if desired. 66 | virtualenv: 67 | system_site_packages: true 68 | env: 69 | global: 70 | - ROS_CI_DESKTOP="`lsb_release -cs`" # e.g. [precise|trusty|...] 71 | - CI_SOURCE_PATH=$(pwd) 72 | - ROSINSTALL_FILE=$CI_SOURCE_PATH/.dependencies.rosinstall 73 | - CATKIN_OPTIONS=$CI_SOURCE_PATH/.catkin.options 74 | - ROS_PARALLEL_JOBS='-j8 -l6' 75 | 76 | ################################################################################ 77 | 78 | # Install system dependencies, namely a very barebones ROS setup. 79 | before_install: 80 | - sudo sh -c "echo \"deb http://packages.ros.org/ros/ubuntu $ROS_CI_DESKTOP main\" > /etc/apt/sources.list.d/ros-latest.list" 81 | - wget http://packages.ros.org/ros.key -O - | sudo apt-key add - 82 | - sudo apt-get update -qq 83 | - sudo apt-get install -y python-catkin-pkg python-rosdep python-wstool ros-$ROS_DISTRO-catkin 84 | - source /opt/ros/$ROS_DISTRO/setup.bash 85 | # Prepare rosdep to install dependencies. 86 | - sudo rosdep init 87 | - rosdep update 88 | 89 | # Create a catkin workspace with the package under integration. 90 | install: 91 | - mkdir -p ~/catkin_ws/src 92 | - cd ~/catkin_ws/src 93 | - catkin_init_workspace 94 | # Create the devel/setup.bash (run catkin_make with an empty workspace) and 95 | # source it to set the path variables. 96 | - cd ~/catkin_ws 97 | - catkin_make 98 | - source devel/setup.bash 99 | # Add the package under integration to the workspace using a symlink. 100 | - cd ~/catkin_ws/src 101 | - ln -s $CI_SOURCE_PATH . 102 | 103 | # Install all dependencies, using wstool and rosdep. 104 | # wstool looks for a ROSINSTALL_FILE defined in the environment variables. 105 | before_script: 106 | # source dependencies: install using wstool. 107 | - cd ~/catkin_ws/src 108 | - wstool init 109 | - if [[ -f $ROSINSTALL_FILE ]] ; then wstool merge $ROSINSTALL_FILE ; fi 110 | - wstool up 111 | # package depdencies: install using rosdep. 112 | - cd ~/catkin_ws 113 | - rosdep install -y --from-paths src --ignore-src --rosdistro $ROS_DISTRO 114 | 115 | # Compile and test. If the CATKIN_OPTIONS file exists, use it as an argument to 116 | # catkin_make. 117 | script: 118 | - cd ~/catkin_ws 119 | - catkin_make $( [ -f $CATKIN_OPTIONS ] && cat $CATKIN_OPTIONS ) 120 | - source devel/setup.bash # NOTE: This is required on Travis for Trusty 121 | # Testing: Use both run_tests (to see the output) and test (to error out). 122 | - catkin_make run_tests # This always returns 0, but looks pretty. 123 | - catkin_make test # This will return non-zero if a test fails. 124 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/README.md: -------------------------------------------------------------------------------- 1 | SMACH 2 | ===== 3 | 4 | SMACH is a task-level python execution framework for rapidly composing complex 5 | robot behaviors. 6 | 7 | ![travis](https://travis-ci.org/jbohren/executive_smach.svg?branch=master) 8 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/executive_smach/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package executive_smach 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 2.0.0 (2014-04-17) 6 | ------------------ 7 | 8 | 1.3.1 (2013-07-22) 9 | ------------------ 10 | * adding changelogs 11 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/executive_smach/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(executive_smach) 3 | find_package(catkin REQUIRED) 4 | catkin_metapackage() 5 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/executive_smach/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | executive_smach 4 | 2.0.0 5 | 6 | This metapackage depends on the SMACH library and ROS SMACH integration 7 | packages. 8 | 9 | Jonathan Bohren 10 | BSD 11 | 12 | http://ros.org/wiki/smach 13 | Jonathan Bohren 14 | Wim Meeussen 15 | 16 | catkin 17 | smach 18 | smach_ros 19 | smach_msgs 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package smach 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 2.0.0 (2014-04-17) 6 | ------------------ 7 | * Merging changes, resolving conflicts, from strands-project (@cburbridge) 8 | * cleaning up and removing rosbuild support 9 | * merging groovy and hydro 10 | * Fix get_internal_edges returning list of tuples, not list of lists 11 | * Remove old methods set_userdata 12 | * Remove superfluous parent class declaration 'UserData' from 'Remapper' 13 | * Add local error base class 'SmachError', extending Exception 14 | * Fix syntax errors, doc typos and indentations glitches 15 | * Fixed invalid exception type in concurrence.py 16 | * Checking threads have fully terminated before cleanup of outcomes dict 17 | This commit uses thread.isAlive() on each concurrent state runner to check for termination of all the threads before continuing. This is necessary as only checking that the outcome has been filled in does not mean the thread has completed; if the thread has not completed it may not yet have called the termination callback. If this loop exits before the termination callback of the last thread is called, then the callback will occasionally be sent an empty dictionary (when the main thread has got to line 305). 18 | * cope with missed state termination notifications 19 | Concurrent states could terminate and notify _ready_event without the concurrence container realising, as it could be busy checking the outcome values. This makes the concurrency container get stuck on line 250. This commit adds a timeout to the wait to safely cope with missing notifications. 20 | * Adding event for thread synchronization in concurrence and using event not condition in monitor state 21 | * Contributors: Felix Kolbe, Jonathan Bohren, Piotr Orzechowski, cburbridge 22 | 23 | 1.3.1 (2013-07-22) 24 | ------------------ 25 | * adding changelogs 26 | * added missing catkin_package() calls in CMakeLists.txt files of packages smach and smach_ros 27 | * Updating maintainer name 28 | 29 | * added missing catkin_package() calls in CMakeLists.txt files of packages smach and smach_ros 30 | * Updating maintainer name 31 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | 3 | project(smach) 4 | 5 | find_package(catkin REQUIRED COMPONENTS) 6 | 7 | catkin_python_setup() 8 | 9 | catkin_package() 10 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/epydoc.cfg: -------------------------------------------------------------------------------- 1 | [epydoc] 2 | url: http://ros.org/wiki/smach 3 | 4 | css: white 5 | frames: no 6 | 7 | imports: yes 8 | inheritance: grouped 9 | private: no 10 | 11 | parse: yes 12 | introspect: no 13 | 14 | verbosity: 10 15 | #debug: 1 16 | 17 | graph: all 18 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | smach 4 | 2.0.0 5 | 6 | SMACH is a task-level architecture for rapidly creating complex robot 7 | behavior. At its core, SMACH is a ROS-independent Python library to build 8 | hierarchical state machines. SMACH is a new library that takes advantage of 9 | very old concepts in order to quickly create robust robot behavior with 10 | maintainable and modular code. 11 | 12 | 13 | Jonathan Bohren 14 | BSD 15 | 16 | Jonathan Bohren 17 | 18 | catkin 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/rosdoc.yaml: -------------------------------------------------------------------------------- 1 | - builder: epydoc 2 | output_dir: python 3 | config: epydoc.cfg 4 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup 4 | from catkin_pkg.python_setup import generate_distutils_setup 5 | 6 | d = generate_distutils_setup( 7 | packages=['smach'], 8 | package_dir={'': 'src'} 9 | ) 10 | 11 | setup(**d) 12 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2010, Willow Garage, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # * Redistributions in binary form must reproduce the above copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | # * Neither the name of the Willow Garage, Inc. nor the names of its 13 | # contributors may be used to endorse or promote products derived from 14 | # this software without specific prior written permission. 15 | # 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | 27 | # Define default logging macros 28 | 29 | ### Utilities 30 | from smach.log import\ 31 | set_loggers,\ 32 | loginfo,\ 33 | logwarn,\ 34 | logerr,\ 35 | logdebug 36 | 37 | from smach.exceptions import\ 38 | InvalidTransitionError,\ 39 | InvalidStateError,\ 40 | InvalidConstructionError,\ 41 | InvalidUserCodeError 42 | 43 | ### Core classes 44 | from smach.state import State, CBState 45 | from smach.user_data import UserData, Remapper 46 | from smach.container import Container 47 | 48 | from smach.util import\ 49 | is_shutdown, set_shutdown_check,\ 50 | has_smach_interface, cb_interface, CBInterface 51 | 52 | ### Containers 53 | from smach.state_machine import StateMachine 54 | from smach.sequence import Sequence 55 | from smach.concurrence import Concurrence 56 | from smach.iterator import Iterator 57 | 58 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/concurrence.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach/src/smach/concurrence.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/container.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach/src/smach/container.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/exceptions.py: -------------------------------------------------------------------------------- 1 | 2 | import smach 3 | 4 | __all__ = ['SmachError', 5 | 'InvalidTransitionError', 6 | 'InvalidStateError', 7 | 'InvalidConstructionError', 8 | 'InvalidUserCodeError'] 9 | 10 | 11 | class SmachError(Exception): 12 | """Exception printing to console on instantiation""" 13 | def __init__(self, message): 14 | smach.logerr(self.__class__.__name__ + ": " + message) 15 | Exception.__init__(self, message) 16 | 17 | 18 | class InvalidTransitionError(SmachError): 19 | def __init__(self, message): 20 | SmachError.__init__(self, message) 21 | 22 | class InvalidStateError(SmachError): 23 | def __init__(self, message): 24 | SmachError.__init__(self, message) 25 | 26 | class InvalidUserCodeError(SmachError): 27 | def __init__(self, message): 28 | SmachError.__init__(self, message) 29 | 30 | class InvalidConstructionError(SmachError): 31 | def __init__(self, message): 32 | SmachError.__init__(self, message) 33 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/exceptions.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach/src/smach/exceptions.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/iterator.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach/src/smach/iterator.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/log.py: -------------------------------------------------------------------------------- 1 | 2 | import smach 3 | 4 | __all__ = ['set_loggers','loginfo','logwarn','logerr','logdebug'] 5 | 6 | def loginfo(msg): 7 | print("[ INFO ] : "+str(msg)) 8 | 9 | def logwarn(msg): 10 | print("[ WARN ] : "+str(msg)) 11 | 12 | def logdebug(msg): 13 | print("[ DEBUG ] : "+str(msg)) 14 | 15 | def logerr(msg): 16 | print("[ ERROR ] : "+str(msg)) 17 | 18 | def set_loggers(info,warn,debug,error): 19 | """Override the SMACH logging functions.""" 20 | smach.loginfo = info 21 | smach.logwarn = warn 22 | smach.logdebug = debug 23 | smach.logerr = error 24 | 25 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/log.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach/src/smach/log.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/sequence.py: -------------------------------------------------------------------------------- 1 | 2 | import threading 3 | from contextlib import contextmanager 4 | 5 | import smach 6 | 7 | __all__ = ['Sequence'] 8 | 9 | class Sequence(smach.state_machine.StateMachine): 10 | """Sequence Container 11 | 12 | This container inherits functionality from L{smach.StateMachine} and adds 13 | some auto-generated transitions that create a sequence of states from the 14 | order in which said states are added to the container. 15 | """ 16 | def __init__(self, 17 | outcomes, 18 | connector_outcome, 19 | input_keys=[], 20 | output_keys=[]): 21 | """Constructor. 22 | 23 | @type outcomes: list of string 24 | @param outcomes: The potential outcomes of this container. 25 | 26 | @type connector_outcome: string 27 | @param connector_outcome: The outcome used to connect states in the 28 | sequence. 29 | """ 30 | smach.state_machine.StateMachine.__init__(self, outcomes, input_keys, output_keys) 31 | 32 | self._last_added_seq_label = None 33 | self._connector_outcome = connector_outcome 34 | 35 | ### Construction Methods 36 | @staticmethod 37 | def add(label, state, transitions = None, remapping = None): 38 | """Add a state to the sequence. 39 | Each state added will receive an additional transition from it to the 40 | state which is added after it. The transition will follow the outcome 41 | specified at construction of this container. 42 | 43 | @type label: string 44 | @param label: The label of the state being added. 45 | 46 | @param state: An instance of a class implementing the L{State} interface. 47 | 48 | @param transitions: A dictionary mapping state outcomes to other state 49 | labels. If one of these transitions follows the connector outcome 50 | specified in the constructor, the provided transition will override 51 | the automatically generated connector transition. 52 | """ 53 | # Get currently opened container 54 | self = Sequence._currently_opened_container() 55 | 56 | if transitions is None: 57 | transitions = {} 58 | 59 | # Perform sequence linking 60 | if self._last_added_seq_label is not None: 61 | #print self._transitions[self._last_added_seq_label] 62 | 63 | last_label = self._last_added_seq_label 64 | # Check if the connector outcome has been overriden 65 | if self._connector_outcome not in self._transitions[last_label]\ 66 | or self._transitions[last_label][self._connector_outcome] is None: 67 | self._transitions[last_label][self._connector_outcome] = label 68 | try: 69 | self.check_state_spec(last_label, self._states[last_label], self._transitions[last_label]) 70 | except: 71 | smach.logerr("Attempting to construct smach state sequence failed.") 72 | 73 | #print self._transitions[self._last_added_seq_label] 74 | 75 | # Store the last added state label 76 | self._last_added_seq_label = label 77 | 78 | return smach.StateMachine.add(label, state, transitions, remapping) 79 | 80 | 81 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/sequence.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach/src/smach/sequence.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/state.py: -------------------------------------------------------------------------------- 1 | 2 | import threading 3 | import traceback 4 | 5 | import smach 6 | 7 | __all__ = ['State','CBState'] 8 | 9 | class State(object): 10 | """Base class for SMACH states. 11 | 12 | A SMACH state interacts with SMACH containers in two ways. The first is its 13 | outcome identifier, and the second is the set of userdata variables which 14 | it reads from and writes to at runtime. Both of these interactions are 15 | declared before the state goes active (when its C{execute()} method is 16 | called) and are checked during construction. 17 | """ 18 | def __init__(self, outcomes=[], input_keys=[], output_keys=[], io_keys=[]): 19 | """State constructor 20 | @type outcomes: array of strings 21 | @param outcomes: Custom outcomes for this state. 22 | 23 | @type input_keys: array of strings 24 | @param input_keys: The userdata keys from which this state might read 25 | at runtime. 26 | 27 | @type output_keys: array of strings 28 | @param output_keys: The userdata keys to which this state might write 29 | at runtime. 30 | 31 | @type io_keys: array of strings 32 | @param io_keys: The userdata keys to which this state might write or 33 | from which it might read at runtime. 34 | """ 35 | # Store outcomes 36 | self._outcomes = set(outcomes) 37 | 38 | # Store userdata interface description 39 | self._input_keys = set(input_keys + io_keys) 40 | self._output_keys = set(output_keys + io_keys) 41 | 42 | # Declare preempt flag 43 | self._preempt_requested = False 44 | 45 | ### Meat 46 | def execute(self, ud): 47 | """Called when executing a state. 48 | In the base class this raises a NotImplementedError. 49 | 50 | @type ud: L{UserData} structure 51 | @param ud: Userdata for the scope in which this state is executing 52 | """ 53 | raise NotImplementedError() 54 | 55 | ### SMACH Interface API 56 | def register_outcomes(self, new_outcomes): 57 | """Add outcomes to the outcome set.""" 58 | self._outcomes = self._outcomes.union(new_outcomes) 59 | 60 | def get_registered_outcomes(self): 61 | """Get a list of registered outcomes. 62 | @rtype: tuple of string 63 | @return: Tuple of registered outcome strings. 64 | """ 65 | return tuple(self._outcomes) 66 | 67 | ### Userdata API 68 | def register_io_keys(self, keys): 69 | """Add keys to the set of keys from which this state may read and write. 70 | @type keys: list of strings 71 | @param keys: List of keys which may be read from and written to when this 72 | state is active. 73 | """ 74 | self._input_keys = self._input_keys.union(keys) 75 | self._output_keys = self._output_keys.union(keys) 76 | 77 | def register_input_keys(self, keys): 78 | """Add keys to the set of keys from which this state may read. 79 | @type keys: list of strings 80 | @param keys: List of keys which may be read from when this state is 81 | active. 82 | """ 83 | self._input_keys = self._input_keys.union(keys) 84 | 85 | def get_registered_input_keys(self): 86 | """Get a tuple of registered input keys.""" 87 | return tuple(self._input_keys) 88 | 89 | def register_output_keys(self, keys): 90 | """Add keys to the set of keys to which this state may write. 91 | @type keys: list of strings 92 | @param keys: List of keys which may be written to when this state is 93 | active. 94 | """ 95 | self._output_keys = self._output_keys.union(keys) 96 | 97 | def get_registered_output_keys(self): 98 | """Get a tuple of registered output keys.""" 99 | return tuple(self._output_keys) 100 | 101 | ### Preemption interface 102 | def request_preempt(self): 103 | """Sets preempt_requested to True""" 104 | self._preempt_requested = True 105 | 106 | def service_preempt(self): 107 | """Sets preempt_requested to False""" 108 | self._preempt_requested = False 109 | 110 | def recall_preempt(self): 111 | """Sets preempt_requested to False""" 112 | self._preempt_requested = False 113 | 114 | def preempt_requested(self): 115 | """True if a preempt has been requested.""" 116 | return self._preempt_requested 117 | 118 | class CBState(State): 119 | def __init__(self, cb, cb_args=[], cb_kwargs={}, outcomes=[], input_keys=[], output_keys=[], io_keys=[]): 120 | """Create s state from a single function. 121 | 122 | @type outcomes: array of strings 123 | @param outcomes: Custom outcomes for this state. 124 | 125 | @type input_keys: array of strings 126 | @param input_keys: The userdata keys from which this state might read 127 | at runtime. 128 | 129 | @type output_keys: array of strings 130 | @param output_keys: The userdata keys to which this state might write 131 | at runtime. 132 | 133 | @type io_keys: array of strings 134 | @param io_keys: The userdata keys to which this state might write or 135 | from which it might read at runtime. 136 | """ 137 | State.__init__(self, outcomes, input_keys, output_keys, io_keys) 138 | self._cb = cb 139 | self._cb_args = cb_args 140 | self._cb_kwargs = cb_kwargs 141 | 142 | if smach.util.has_smach_interface(cb): 143 | self._cb_input_keys = cb.get_registered_input_keys() 144 | self._cb_output_keys = cb.get_registered_output_keys() 145 | self._cb_outcomes = cb.get_registered_outcomes() 146 | 147 | self.register_input_keys(self._cb_input_keys) 148 | self.register_output_keys(self._cb_output_keys) 149 | self.register_outcomes(self._cb_outcomes) 150 | 151 | def execute(self, ud): 152 | return self._cb(ud, *self._cb_args, **self._cb_kwargs) 153 | 154 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/state.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach/src/smach/state.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/state_machine.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach/src/smach/state_machine.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/user_data.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach/src/smach/user_data.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/util.py: -------------------------------------------------------------------------------- 1 | 2 | import smach 3 | import threading 4 | 5 | 6 | __all__ = ['is_shutdown','set_shutdown_cb',\ 7 | 'cb_interface','has_smach_interface','CBInterface'] 8 | 9 | def is_shutdown(): 10 | return False 11 | 12 | def set_shutdown_check(cb): 13 | smach.is_shutdown = cb 14 | 15 | def has_smach_interface(obj): 16 | """Returns True if the object has SMACH interface accessors.""" 17 | return hasattr(obj,'get_registered_input_keys')\ 18 | and hasattr(obj,'get_registered_output_keys')\ 19 | and hasattr(obj,'get_registered_outcomes') 20 | 21 | # Callback decorator for describing userdata 22 | class cb_interface(object): 23 | def __init__(self, outcomes=[], input_keys=[], output_keys=[]): 24 | self._outcomes = outcomes 25 | self._input_keys = input_keys 26 | self._output_keys = output_keys 27 | 28 | def __call__(self, cb): 29 | return CBInterface(cb, self._outcomes, self._input_keys, self._output_keys) 30 | class CBInterface(object): 31 | """Decorator to describe the extension of a state's SMACH userdata and outcome interface. 32 | 33 | Some SMACH states can be extended with the use of user callbacks. Since 34 | the SMACH interface and SMACH userdata are strictly controlled, the ways in 35 | which these callbacks interact with SMACH must be delcared. This decorator 36 | allows this information to be attached to a given callback function. 37 | 38 | If a callback adds a potential outcome to a state, suppose 'critical_failure', 39 | then one could write this when defining the callback: 40 | 41 | >>> import smach 42 | >>> @smach.cb_interface(outcomes=['critical_failure']) 43 | >>> def my_cb(x,y,z): 44 | >>> # User code 45 | >>> return 'critical_failure' 46 | 47 | Suppose a state retrieves data that it passes into a callback. If the user 48 | wants to take that data and put some of all of it into userdata, this 49 | interface must be declared. In this case, the user could write: 50 | 51 | >>> import smach 52 | >>> @smach.cb_interface(output_keys=['processed_res']) 53 | >>> def my_cb(ud, data): 54 | >>> ud.processed_res = data 55 | 56 | """ 57 | def __init__(self, cb, outcomes=[], input_keys=[], output_keys=[], io_keys=[]): 58 | """Describe callback SMACH interface. 59 | 60 | @type outcomes: array of strings 61 | @param outcomes: Custom outcomes for this state. 62 | 63 | @type input_keys: array of strings 64 | @param input_keys: The userdata keys from which this state might read 65 | at runtime. 66 | 67 | @type output_keys: array of strings 68 | @param output_keys: The userdata keys to which this state might write 69 | at runtime. 70 | 71 | @type io_keys: array of strings 72 | @param io_keys: The userdata keys to which this state might write or 73 | from which it might read at runtime. 74 | """ 75 | 76 | self._input_keys = set(input_keys) 77 | self._input_keys.union(io_keys) 78 | 79 | self._output_keys = set(output_keys) 80 | self._output_keys.union(io_keys) 81 | 82 | self._outcomes = outcomes 83 | 84 | self._cb = cb 85 | 86 | def __call__(self, *args, **kwargs): 87 | return self._cb(*args, **kwargs) 88 | 89 | ### SMACH Interface API 90 | def get_registered_input_keys(self): 91 | """Get a tuple of registered input keys.""" 92 | return tuple(self._input_keys) 93 | def get_registered_output_keys(self): 94 | """Get a tuple of registered output keys.""" 95 | return tuple(self._output_keys) 96 | def get_registered_outcomes(self): 97 | """Get a list of registered outcomes. 98 | @rtype: tuple of string 99 | @return: Tuple of registered outcome strings. 100 | """ 101 | return tuple(self._outcomes) 102 | 103 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach/src/smach/util.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach/src/smach/util.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_msgs/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package smach_msgs 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 2.0.0 (2014-04-17) 6 | ------------------ 7 | * cleaning up and removing rosbuild support 8 | * merging groovy and hydro 9 | * Add explanations within message definitions 10 | * Contributors: Felix Kolbe, Jonathan Bohren 11 | 12 | 1.3.1 (2013-07-22) 13 | ------------------ 14 | * adding changelogs 15 | * Updating maintainer name 16 | 17 | * Updating maintainer name 18 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_msgs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | 3 | project(smach_msgs) 4 | 5 | find_package(catkin REQUIRED COMPONENTS 6 | message_generation std_msgs) 7 | 8 | add_message_files(FILES 9 | SmachContainerInitialStatusCmd.msg 10 | SmachContainerStructure.msg 11 | SmachContainerStatus.msg) 12 | 13 | generate_messages(DEPENDENCIES std_msgs) 14 | 15 | catkin_package(CATKIN_DEPENDS message_runtime) 16 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_msgs/msg/SmachContainerInitialStatusCmd.msg: -------------------------------------------------------------------------------- 1 | # The path to the node in the server 2 | string path 3 | 4 | # The desired initial state(s) 5 | string[] initial_states 6 | 7 | # Initial values for the local user data of the state machine 8 | # A pickled user data structure 9 | # i.e. the UserData's internal dictionary 10 | string local_data 11 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_msgs/msg/SmachContainerStatus.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | 3 | # The path to this node in the server 4 | string path 5 | 6 | # The initial state description 7 | # Effects an arc from the top state to each one 8 | string[] initial_states 9 | 10 | # The current state description 11 | string[] active_states 12 | 13 | # A pickled user data structure 14 | # i.e. the UserData's internal dictionary 15 | string local_data 16 | 17 | # Debugging info string 18 | string info 19 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_msgs/msg/SmachContainerStructure.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | 3 | # The path to this node in the server 4 | string path 5 | 6 | # The children of this node 7 | string[] children 8 | 9 | # The outcome edges 10 | # Each index across these arrays denote one edge 11 | string[] internal_outcomes 12 | string[] outcomes_from 13 | string[] outcomes_to 14 | 15 | # The potential outcomes from this container 16 | string[] container_outcomes 17 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_msgs/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | smach_msgs 4 | 2.0.0 5 | 6 | this package contains a set of messages that are used by the introspection 7 | interfaces for smach. 8 | 9 | 10 | Jonathan Bohren 11 | BSD 12 | 13 | Jonathan Bohren 14 | 15 | catkin 16 | 17 | std_msgs 18 | 19 | message_generation 20 | 21 | message_runtime 22 | message_runtime 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package smach_ros 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 2.0.0 (2014-04-17) 6 | ------------------ 7 | * smach_ros: Adding rostests to cmakelists 8 | * Merging changes, resolving conflicts, from strands-project (@cburbridge) 9 | * cleaning up and removing rosbuild support 10 | * merging groovy and hydro 11 | * Listing available goal slots in case of specifying wrong ones 12 | * Fix syntax errors, doc typos and indentations glitches 13 | * if monitor state prempted before executing, return. 14 | * Adding event for thread synchronization in concurrence and using event not condition in monitor state 15 | * Listing available goal slots in case of specifying wrong ones 16 | * [MonitorState] Make exception handler more verbose 17 | * edited monitor state to allow input and output keys 18 | * Contributors: Boris Gromov, Bruno Lacerda, Felix Kolbe, Hendrik Wiese, Jonathan Bohren, cburbridge 19 | 20 | 1.3.1 (2013-07-22) 21 | ------------------ 22 | * adding changelogs 23 | * added missing catkin_package() calls in CMakeLists.txt files of packages smach and smach_ros 24 | * Updating maintainer name 25 | 26 | * added missing catkin_package() calls in CMakeLists.txt files of packages smach and smach_ros 27 | * Updating maintainer name 28 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | 3 | project(smach_ros) 4 | 5 | find_package(catkin REQUIRED COMPONENTS rostest) 6 | 7 | catkin_python_setup() 8 | 9 | catkin_package( 10 | CATKIN_DEPENDS rospy rostopic std_msgs std_srvs actionlib actionlib_msgs smach smach_msgs 11 | ) 12 | 13 | if(CATKIN_ENABLE_TESTING) 14 | add_rostest(test/state_machine.test) 15 | add_rostest(test/sequence.test) 16 | add_rostest(test/concurrence.test) 17 | add_rostest(test/introspection.test) 18 | add_rostest(test/smach_actionlib.test) 19 | add_rostest(test/monitor.test) 20 | endif() 21 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/epydoc.cfg: -------------------------------------------------------------------------------- 1 | [epydoc] 2 | url: http://ros.org/wiki/smach_ros 3 | 4 | css: white 5 | frames: no 6 | 7 | imports: yes 8 | inheritance: grouped 9 | private: no 10 | 11 | parse: yes 12 | introspect: no 13 | 14 | verbosity: 10 15 | #debug: 1 16 | 17 | graph: all 18 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | smach_ros 4 | 2.0.0 5 | 6 | The smach_ros package contains extensions for the SMACH library to 7 | integrate it tightly with ROS. For example, SMACH-ROS can call 8 | ROS services, listen to ROS topics, and integrate 9 | with actionlib 10 | both as a client, and a provider of action servers. SMACH is a 11 | new library that takes advantage of very old concepts in order to 12 | quickly create robust robot behavior with maintainable and modular 13 | code. 14 | 15 | 16 | Jonathan Bohren 17 | BSD 18 | 19 | Jonathan Bohren 20 | 21 | catkin 22 | 23 | rostest 24 | 25 | rospy 26 | rostopic 27 | std_msgs 28 | std_srvs 29 | actionlib 30 | actionlib_msgs 31 | 32 | smach 33 | smach_msgs 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/rosdoc.yaml: -------------------------------------------------------------------------------- 1 | - builder: epydoc 2 | output_dir: python 3 | config: epydoc.cfg 4 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup 4 | from catkin_pkg.python_setup import generate_distutils_setup 5 | 6 | d = generate_distutils_setup( 7 | packages=['smach_ros'], 8 | package_dir={'': 'src'} 9 | ) 10 | 11 | setup(**d) 12 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2010, Willow Garage, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # * Redistributions in binary form must reproduce the above copyright 10 | # notice, this list of conditions and the following disclaimer in the 11 | # documentation and/or other materials provided with the distribution. 12 | # * Neither the name of the Willow Garage, Inc. nor the names of its 13 | # contributors may be used to endorse or promote products derived from 14 | # this software without specific prior written permission. 15 | # 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | 27 | # ROS imports 28 | import roslib; roslib.load_manifest('smach_ros') 29 | import rospy 30 | 31 | # SMACH 32 | import smach 33 | 34 | __all__ = ['set_preempt_handler', 35 | 'ActionServerWrapper', 36 | 'IntrospectionClient','IntrospectionServer', 37 | 'SimpleActionState', 38 | 'ServiceState', 39 | 'MonitorState', 40 | 'ConditionState'] 41 | 42 | # Setup smach-ros interface 43 | smach.set_loggers( 44 | rospy.loginfo, 45 | rospy.logwarn, 46 | rospy.logdebug, 47 | rospy.logerr) 48 | 49 | smach.set_shutdown_check(rospy.is_shutdown) 50 | 51 | ### Core classes 52 | from util import set_preempt_handler 53 | 54 | ### Top-level Containers / Wrappers 55 | from action_server_wrapper import ActionServerWrapper 56 | from introspection import IntrospectionClient, IntrospectionServer 57 | 58 | ### State Classes 59 | from simple_action_state import SimpleActionState 60 | from service_state import ServiceState 61 | from monitor_state import MonitorState 62 | from condition_state import ConditionState 63 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/action_server_wrapper.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/action_server_wrapper.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/condition_state.py: -------------------------------------------------------------------------------- 1 | 2 | import roslib; roslib.load_manifest('smach_ros') 3 | import rospy 4 | 5 | import threading 6 | import traceback 7 | 8 | import smach 9 | 10 | __all__ = ['ConditionState'] 11 | 12 | class ConditionState(smach.State): 13 | """A state that will check a condition function a number of times. 14 | 15 | If max_checks > 1, it will block while the condition is false and once it 16 | has checked max_checks times, it will return false. 17 | """ 18 | def __init__(self, 19 | cond_cb, 20 | input_keys = [], 21 | poll_rate = rospy.Duration(0.05), 22 | timeout = None, 23 | max_checks = 1): 24 | smach.State.__init__(self,outcomes = ['true', 'false','preempted'], input_keys = input_keys) 25 | 26 | self._cond_cb = cond_cb 27 | if hasattr(cond_cb,'get_registered_input_keys') and hasattr(cond_cb,'get_registered_output_keys'): 28 | self._cond_cb_input_keys = cond_cb.get_registered_input_keys() 29 | self._cond_cb_output_keys = cond_cb.get_registered_output_keys() 30 | self.register_input_keys(self._cond_cb_input_keys) 31 | self.register_output_keys(self._cond_cb_output_keys) 32 | self._poll_rate = poll_rate 33 | self._timeout = timeout 34 | self._max_checks = max_checks 35 | 36 | def execute(self, ud): 37 | start_time = rospy.Time.now() 38 | n_checks = 0 39 | 40 | while self._max_checks == -1 or n_checks <= self._max_checks: 41 | # Check for timeout 42 | if self._timeout and rospy.Time.now() - start_time > self._timeout: 43 | break 44 | # Check for preemption 45 | if self.preempt_requested(): 46 | self.service_preempt() 47 | return 'preempted' 48 | # Call the condition 49 | try: 50 | if self._cond_cb(ud): 51 | return 'true' 52 | except: 53 | raise smach.InvalidUserCodeError("Error thrown while executing condition callback %s: " % str(self._cond_cb) +traceback.format_exc()) 54 | n_checks += 1 55 | rospy.sleep(self._poll_rate) 56 | 57 | return 'false' 58 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/condition_state.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/condition_state.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/introspection.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/introspection.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/monitor_state.py: -------------------------------------------------------------------------------- 1 | 2 | import roslib; roslib.load_manifest('smach_ros') 3 | import rospy 4 | 5 | import threading 6 | import traceback 7 | 8 | import smach 9 | 10 | __all__ = ['MonitorState'] 11 | 12 | class MonitorState(smach.State): 13 | """ 14 | A state that will check a given ROS topic with a condition function. 15 | """ 16 | def __init__(self, topic, msg_type, cond_cb, max_checks=-1,input_keys = [],output_keys=[]): 17 | """State constructor 18 | @type topic string 19 | @param topic the topic to monitor 20 | 21 | @type msg_type a ROS message type 22 | @param msg_type determines the type of the monitored topic 23 | 24 | @type max_checks int 25 | @param max_checks the number of messages to receive and evaluate. If cond_cb returns False for any 26 | of them, the state will finish with outcome 'invalid'. If cond_cb returns True for 27 | all of them, the outcome will be 'valid' 28 | 29 | """ 30 | smach.State.__init__( 31 | self, 32 | outcomes=['valid','invalid','preempted'], 33 | input_keys = input_keys, 34 | output_keys = output_keys) 35 | 36 | self._topic = topic 37 | self._msg_type = msg_type 38 | self._cond_cb = cond_cb 39 | self._max_checks = max_checks 40 | self._n_checks = 0 41 | 42 | self._trigger_event = threading.Event() 43 | 44 | def execute(self, ud): 45 | # If prempted before even getting a chance, give up. 46 | if self.preempt_requested(): 47 | self.service_preempt() 48 | return 'preempted' 49 | 50 | self._n_checks = 0 51 | self._trigger_event.clear() 52 | 53 | self._sub = rospy.Subscriber(self._topic, self._msg_type, self._cb, callback_args=ud) 54 | 55 | self._trigger_event.wait() 56 | self._sub.unregister() 57 | 58 | if self.preempt_requested(): 59 | self.service_preempt() 60 | return 'preempted' 61 | 62 | if self._max_checks > 0 and self._n_checks >= self._max_checks: 63 | return 'valid' 64 | 65 | return 'invalid' 66 | 67 | def _cb(self,msg,ud) : 68 | try: 69 | if self._cond_cb(ud, msg): 70 | self._n_checks +=1 71 | else: 72 | self._trigger_event.set() 73 | except Exception as e: 74 | rospy.logerr("Error thrown while executing condition callback %s: %s" % (str(self._cond_cb), e)) 75 | self._trigger_event.set() 76 | 77 | if (self._max_checks > 0 and self._n_checks >= self._max_checks): 78 | self._trigger_event.set() 79 | 80 | def request_preempt(self): 81 | smach.State.request_preempt(self) 82 | self._trigger_event.set() 83 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/monitor_state.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/monitor_state.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/service_state.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/service_state.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/simple_action_state.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/simple_action_state.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/util.py: -------------------------------------------------------------------------------- 1 | 2 | import roslib; roslib.load_manifest('smach_ros') 3 | import rospy 4 | 5 | import threading 6 | import smach 7 | 8 | __all__ = ['set_preempt_handler'] 9 | 10 | # Signal handler 11 | def set_preempt_handler(sc): 12 | """Sets a ROS pre-shutdown handler to preempt a given SMACH container when 13 | ROS receives a shutdown request. 14 | 15 | This can be attached to multiple containers, but only needs to be used on 16 | the top-level containers. 17 | 18 | @type sc: L{smach.Container} 19 | @param sc: Container to preempt on ROS shutdown. 20 | """ 21 | ### Define handler 22 | def handler(sc): 23 | sc.request_preempt() 24 | 25 | while sc.is_running(): 26 | rospy.loginfo("Received shutdown request... sent preempt... waiting for state machine to terminate.") 27 | rospy.sleep(1.0) 28 | 29 | ### Add handler 30 | rospy.core.add_client_shutdown_hook(lambda: handler(sc)) 31 | 32 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/util.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/executive_smach/smach_ros/src/smach_ros/util.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/concurrence.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import roslib; roslib.load_manifest('smach_ros') 4 | import rospy 5 | import rostest 6 | 7 | import unittest 8 | 9 | from actionlib import * 10 | from actionlib.msg import * 11 | 12 | from smach import * 13 | from smach_ros import * 14 | 15 | from smach_msgs.msg import * 16 | 17 | # Static goals 18 | g1 = TestGoal(1) # This goal should succeed 19 | g2 = TestGoal(2) # This goal should abort 20 | g3 = TestGoal(3) # This goal should be rejected 21 | 22 | ### Custom tate classe 23 | class Setter(State): 24 | """State that sets the key 'a' in its userdata""" 25 | def __init__(self): 26 | State.__init__(self,['done'],[],['a']) 27 | def execute(self,ud): 28 | ud.a = 'A' 29 | rospy.loginfo("Added key 'a'.") 30 | return 'done' 31 | 32 | class Getter(State): 33 | """State that grabs the key 'a' from userdata, and sets 'b'""" 34 | def __init__(self): 35 | State.__init__(self,['done','preempted'],['a'],['b']) 36 | def execute(self,ud): 37 | while 'a' not in ud: 38 | rospy.loginfo("Waiting for key 'a' to appear. ") 39 | rospy.sleep(0.1) 40 | ud.b = ud.a 41 | rospy.sleep(1.0) 42 | if self.preempt_requested(): 43 | return 'preempted' 44 | return 'done' 45 | 46 | ### Test harness 47 | class TestStateMachine(unittest.TestCase): 48 | def test_concurrence(self): 49 | """Test concurrent container.""" 50 | sm = StateMachine(['done','succeeded']) 51 | with sm: 52 | cc = Concurrence(['succeeded','done'], 53 | default_outcome = 'done', 54 | outcome_map = {'succeeded':{'SETTER':'done'}}) 55 | sm.add('CONCURRENT',cc) 56 | with cc: 57 | Concurrence.add('SETTER', Setter()) 58 | Concurrence.add('GETTER', Getter()) 59 | 60 | outcome = sm.execute() 61 | 62 | assert outcome == 'succeeded' 63 | assert 'a' in cc.userdata 64 | assert 'b' in cc.userdata 65 | assert cc.userdata.a == 'A' 66 | assert cc.userdata.b == 'A' 67 | 68 | def test_preempt(self): 69 | """Test concurrent container that preempts siblings.""" 70 | cc = Concurrence(['succeeded','done'], 71 | default_outcome = 'done', 72 | child_termination_cb = lambda so: True, 73 | outcome_map = {'succeeded':{'SETTER':'done', 'GETTER':'preempted'}}) 74 | with cc: 75 | Concurrence.add('SETTER', Setter()) 76 | Concurrence.add('GETTER', Getter()) 77 | 78 | outcome = cc.execute() 79 | 80 | assert outcome == 'succeeded' 81 | assert 'a' in cc.userdata 82 | assert 'b' in cc.userdata 83 | assert cc.userdata.a == 'A' 84 | assert cc.userdata.b == 'A' 85 | 86 | def test_no_preempt(self): 87 | """Test concurrent container that doesnt preempt siblings.""" 88 | cc = Concurrence(['succeeded','done'], 89 | default_outcome = 'done', 90 | child_termination_cb = lambda so: False, 91 | outcome_map = { 92 | 'succeeded':{ 93 | 'SETTER':'done', 94 | 'GETTER':'done'}}) 95 | with cc: 96 | Concurrence.add('SETTER', Setter()) 97 | Concurrence.add('GETTER', Getter()) 98 | 99 | outcome = cc.execute() 100 | 101 | assert outcome == 'succeeded' 102 | assert 'a' in cc.userdata 103 | assert 'b' in cc.userdata 104 | assert cc.userdata.a == 'A' 105 | assert cc.userdata.b == 'A' 106 | 107 | def test_outcome_cb(self): 108 | """Test concurrent container that doesnt preempt siblings.""" 109 | cc = Concurrence(['succeeded','done'], 110 | default_outcome = 'done', 111 | child_termination_cb = lambda so: False, 112 | outcome_cb = lambda so: list(set(so.values()))[0]) 113 | with cc: 114 | Concurrence.add('SETTER', Setter()) 115 | Concurrence.add('GETTER', Getter()) 116 | 117 | outcome = cc.execute() 118 | 119 | assert outcome == 'done' 120 | assert 'a' in cc.userdata 121 | assert 'b' in cc.userdata 122 | assert cc.userdata.a == 'A' 123 | assert cc.userdata.b == 'A' 124 | 125 | def main(): 126 | rospy.init_node('concurrence_test',log_level=rospy.DEBUG) 127 | rostest.rosrun('smach', 'concurrence_test', TestStateMachine) 128 | 129 | if __name__=="__main__": 130 | main(); 131 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/concurrence.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/introspection.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import roslib; roslib.load_manifest('smach_ros') 4 | import rospy 5 | import rostest 6 | 7 | import threading 8 | 9 | import unittest 10 | 11 | from smach import * 12 | from smach_ros import * 13 | 14 | from smach_msgs.msg import * 15 | 16 | ### Custom state classe 17 | class Setter(State): 18 | """State that sets the key 'a' in its userdata""" 19 | def __init__(self): 20 | State.__init__(self,['done'],[],['a']) 21 | def execute(self,ud): 22 | ud.a = 'A' 23 | rospy.loginfo("Added key 'a'.") 24 | return 'done' 25 | 26 | class Getter(State): 27 | """State that grabs the key 'a' from userdata, and sets 'b'""" 28 | def __init__(self): 29 | State.__init__(self,['done'],['a'],['b']) 30 | def execute(self,ud): 31 | while 'a' not in ud and not rospy.is_shutdown(): 32 | #rospy.loginfo("Waiting for key 'a' to appear. ") 33 | rospy.sleep(0.1) 34 | ud.b = ud.a 35 | return 'done' 36 | 37 | ### Test harness 38 | class TestIntrospection(unittest.TestCase): 39 | 40 | def test_introspection(self): 41 | """Test introspection system.""" 42 | # Construct state machine 43 | sm = StateMachine(['done']) 44 | sm2 = StateMachine(['done']) 45 | sm3 = StateMachine(['done']) 46 | 47 | with sm: 48 | # Note: the following "Getter" state should fail 49 | StateMachine.add('GETTER1', Getter(), {}) 50 | StateMachine.add('SM2', sm2, {'done':'SM3'}) 51 | with sm2: 52 | StateMachine.add("SETTER", Setter(), {}) 53 | StateMachine.add('SM3', sm3, {'done':'done'}) 54 | with sm3: 55 | StateMachine.add("SETTER", Setter(), {}) 56 | StateMachine.add('GETTER2', Getter(), {'done':'SM2'}) 57 | 58 | sm.set_initial_state(['GETTER1']) 59 | sm2.set_initial_state(['SETTER']) 60 | sm3.set_initial_state(['SETTER']) 61 | 62 | # Run introspector 63 | intro_server = IntrospectionServer('intro_test',sm,'/intro_test') 64 | server_thread = threading.Thread(target=intro_server.start) 65 | server_thread.start() 66 | 67 | intro_client = IntrospectionClient() 68 | servers = intro_client.get_servers() 69 | while '/intro_test' not in servers and not rospy.is_shutdown(): 70 | servers = intro_client.get_servers() 71 | rospy.loginfo("Smach servers: "+str()) 72 | rospy.sleep(0.1) 73 | 74 | assert '/intro_test' in servers 75 | 76 | # Set initial state 77 | injected_ud = UserData() 78 | injected_ud.a = 'A' 79 | init_set = intro_client.set_initial_state('intro_test','/intro_test',['SM2'],injected_ud,timeout = rospy.Duration(10.0)) 80 | assert init_set 81 | 82 | outcome = sm.execute() 83 | 84 | assert outcome == 'done' 85 | 86 | 87 | def main(): 88 | rospy.init_node('introspection_test',log_level=rospy.DEBUG) 89 | rostest.rosrun('smach', 'introspection_test', TestIntrospection) 90 | 91 | if __name__=="__main__": 92 | main(); 93 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/introspection.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/monitor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import roslib; roslib.load_manifest('smach_ros') 4 | import rospy 5 | import rostest 6 | 7 | import unittest 8 | 9 | from actionlib import * 10 | from actionlib.msg import * 11 | 12 | from std_msgs.msg import Empty 13 | 14 | from smach import * 15 | from smach_ros import * 16 | 17 | from smach_msgs.msg import * 18 | 19 | def pinger(): 20 | pub = rospy.Publisher('/ping', Empty) 21 | msg = Empty() 22 | r = rospy.Rate(10.0) 23 | while not rospy.is_shutdown(): 24 | print "publish!" 25 | pub.publish(msg) 26 | r.sleep() 27 | 28 | 29 | def cond_cb(ud, msg): 30 | """monitor condition cb that modifies user data""" 31 | assert 'b' in ud 32 | ud.a = ud.b 33 | return False 34 | 35 | ### Test harness 36 | class TestStateMachine(unittest.TestCase): 37 | def test_userdata(self): 38 | """Test serial manipulation of userdata.""" 39 | 40 | pinger_thread = threading.Thread(target=pinger) 41 | pinger_thread.start() 42 | 43 | init_ud = UserData() 44 | init_ud.b = 'A' 45 | 46 | sm = StateMachine(['valid','invalid','preempted']) 47 | sm.set_initial_state(['MON'],userdata=init_ud) 48 | 49 | assert 'b' in sm.userdata 50 | assert sm.userdata.b == 'A' 51 | 52 | with sm: 53 | StateMachine.add( 54 | 'MON', 55 | MonitorState('/ping', Empty, cond_cb, input_keys=['b'], output_keys=['a'])) 56 | 57 | outcome = sm.execute() 58 | 59 | assert outcome == 'invalid' 60 | assert 'b' in sm.userdata 61 | assert sm.userdata.b == 'A' 62 | assert 'a' in sm.userdata 63 | assert sm.userdata.a == 'A' 64 | 65 | 66 | def main(): 67 | rospy.init_node('monitor_test',log_level=rospy.DEBUG) 68 | rostest.rosrun('smach', 'monitor_test', TestStateMachine) 69 | 70 | if __name__=="__main__": 71 | main(); 72 | 73 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/monitor.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/ref_server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Copyright (c) 2009, Willow Garage, Inc. 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are met: 7 | # 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of the Willow Garage, Inc. nor the names of its 14 | # contributors may be used to endorse or promote products derived from 15 | # this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | # POSSIBILITY OF SUCH DAMAGE. 28 | 29 | # Author: Alexander Sorokin. 30 | # Based on code from ref_server.cpp by Vijay Pradeep 31 | import roslib; roslib.load_manifest('smach_ros') 32 | import rospy 33 | 34 | import sys 35 | 36 | from actionlib.action_server import ActionServer 37 | from actionlib.msg import TestAction,TestFeedback,TestResult 38 | 39 | class RefServer (ActionServer): 40 | 41 | def __init__(self,name): 42 | action_spec=TestAction 43 | ActionServer.__init__(self,name,action_spec,self.goalCallback,self.cancelCallback, False); 44 | self.start() 45 | rospy.loginfo("Creating ActionServer [%s]\n", name); 46 | 47 | self.saved_goals=[] 48 | 49 | def goalCallback(self,gh): 50 | goal = gh.get_goal(); 51 | 52 | rospy.loginfo("Got goal %d", int(goal.goal)) 53 | if goal.goal == 1: 54 | gh.set_accepted(); 55 | gh.set_succeeded(None, "The ref server has succeeded"); 56 | elif goal.goal == 2: 57 | gh.set_accepted(); 58 | gh.set_aborted(None, "The ref server has aborted"); 59 | elif goal.goal == 3: 60 | gh.set_rejected(None, "The ref server has rejected"); 61 | 62 | 63 | elif goal.goal == 4: 64 | 65 | self.saved_goals.append(gh); 66 | gh.set_accepted(); 67 | 68 | elif goal.goal == 5: 69 | 70 | gh.set_accepted(); 71 | for g in self.saved_goals: 72 | g.set_succeeded(); 73 | self.saved_goals = []; 74 | gh.set_succeeded(); 75 | 76 | 77 | elif goal.goal == 6: 78 | gh.set_accepted(); 79 | for g in self.saved_goals: 80 | g.set_aborted(); 81 | self.saved_goals = []; 82 | gh.set_succeeded(); 83 | 84 | elif goal.goal == 7: 85 | gh.set_accepted(); 86 | n=len(self.saved_goals); 87 | for i,g in enumerate(self.saved_goals): 88 | g.publish_feedback(TestFeedback(n-i)); 89 | 90 | gh.set_succeeded(); 91 | 92 | elif goal.goal == 8: 93 | gh.set_accepted(); 94 | n=len(self.saved_goals); 95 | for i,g in enumerate(self.saved_goals): 96 | if i % 2 ==0: 97 | g.set_succeeded(TestResult(n-i), "The ref server has succeeded"); 98 | else: 99 | g.set_aborted(TestResult(n-i), "The ref server has aborted") 100 | self.saved_goals=[]; 101 | gh.set_succeeded(); 102 | 103 | 104 | else: 105 | pass 106 | 107 | def cancelCallback(self,gh): 108 | pass 109 | 110 | if __name__=="__main__": 111 | rospy.init_node("ref_server"); 112 | ref_server = RefServer("reference_action"); 113 | 114 | rospy.spin(); 115 | 116 | 117 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/sequence.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import roslib; roslib.load_manifest('smach_ros') 4 | import rospy 5 | import rostest 6 | 7 | import unittest 8 | 9 | from actionlib import * 10 | from actionlib.msg import * 11 | 12 | from smach import * 13 | from smach_ros import * 14 | 15 | from smach_msgs.msg import * 16 | 17 | # Static goals 18 | g1 = TestGoal(1) # This goal should succeed 19 | g2 = TestGoal(2) # This goal should abort 20 | g3 = TestGoal(3) # This goal should be rejected 21 | 22 | ### Custom tate classe 23 | class Setter(State): 24 | """State that sets the key 'a' in its userdata""" 25 | def __init__(self): 26 | State.__init__(self,['done'],[],['a']) 27 | def execute(self,ud): 28 | ud.a = 'A' 29 | rospy.loginfo("Added key 'a'.") 30 | return 'done' 31 | 32 | class Getter(State): 33 | """State that grabs the key 'a' from userdata, and sets 'b'""" 34 | def __init__(self): 35 | State.__init__(self,['done'],['a'],['b']) 36 | def execute(self,ud): 37 | while 'a' not in ud: 38 | #rospy.loginfo("Waiting for key 'a' to appear. ") 39 | rospy.sleep(0.1) 40 | ud.b = ud.a 41 | return 'done' 42 | 43 | ### Test harness 44 | class TestSequence(unittest.TestCase): 45 | def test_sequence(self): 46 | """Test adding a sequence of states.""" 47 | sq = Sequence(['succeeded','aborted','preempted','done'],connector_outcome='succeeded') 48 | with sq: 49 | Sequence.add('FIRST', SimpleActionState('reference_action',TestAction, goal = g1)) 50 | Sequence.add('SECOND', SimpleActionState('reference_action',TestAction, goal = g1)) 51 | Sequence.add('THIRD', SimpleActionState('reference_action',TestAction, goal = g1),{'succeeded':'done'}) 52 | outcome = sq.execute() 53 | 54 | assert outcome == 'done' 55 | 56 | 57 | def main(): 58 | rospy.init_node('sequence_test',log_level=rospy.DEBUG) 59 | rostest.rosrun('smach', 'sequence_test', TestSequence) 60 | 61 | if __name__=="__main__": 62 | main(); 63 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/sequence.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/services.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import roslib; roslib.load_manifest('smach_ros') 4 | import rospy 5 | import rostest 6 | 7 | import unittest 8 | 9 | import std_srvs.srv as std_srvs 10 | 11 | from smach import * 12 | from smach_ros import * 13 | 14 | from smach_msgs.msg import * 15 | 16 | def empty_server(req): 17 | rospy.loginfo("Service called!") 18 | return std_srvs.EmptyResponse() 19 | 20 | ### Test harness 21 | class TestServices(unittest.TestCase): 22 | def test_service_cb(self): 23 | """Test calling a service with a callback.""" 24 | 25 | srv = rospy.Service('/empty', std_srvs.Empty, empty_server) 26 | 27 | sm = StateMachine(['succeeded','aborted','preempted','done']) 28 | with sm: 29 | def foo_response_cb(userdata, response): 30 | userdata.foo_var_out = 'foo!' 31 | return 'succeeded' 32 | 33 | StateMachine.add('FOO', 34 | ServiceState('/empty', 35 | std_srvs.Empty, 36 | response_cb=foo_response_cb, 37 | output_keys=['foo_var_out']), 38 | remapping={'foo_var_out':'sm_var'}, 39 | transitions={'succeeded':'done'}) 40 | 41 | outcome = sm.execute() 42 | 43 | rospy.logwarn("OUTCOME: "+outcome) 44 | 45 | assert outcome == 'done' 46 | 47 | def main(): 48 | rospy.init_node('services_test',log_level=rospy.DEBUG) 49 | rostest.rosrun('smach', 'services_test', TestServices) 50 | 51 | if __name__=="__main__": 52 | main(); 53 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/services.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/smach_actionlib.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/executive_smach/smach_ros/test/state_machine.test: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(smach_tutorials) 3 | 4 | find_package(catkin REQUIRED COMPONENTS actionlib_msgs) 5 | 6 | ## Generate actions in the 'action' folder 7 | add_action_files( 8 | FILES 9 | Test.action 10 | ) 11 | ## Generate added messages and services with any dependencies listed here 12 | generate_messages( 13 | DEPENDENCIES 14 | actionlib_msgs # Or other packages containing msgs 15 | ) 16 | 17 | ################################### 18 | ## catkin specific configuration ## 19 | ################################### 20 | ## The catkin_package macro generates cmake config files for your package 21 | ## Declare things to be passed to dependent projects 22 | ## INCLUDE_DIRS: uncomment this if you package contains header files 23 | ## LIBRARIES: libraries you create in this project that dependent projects also need 24 | ## CATKIN_DEPENDS: catkin_packages dependent projects also need 25 | ## DEPENDS: system dependencies of this project that dependent projects also need 26 | catkin_package( 27 | # INCLUDE_DIRS include 28 | # LIBRARIES lib 29 | # CATKIN_DEPENDS packages 30 | # DEPENDS system_lib 31 | ) 32 | 33 | ## mark examples for installation 34 | install(DIRECTORY examples 35 | DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} 36 | USE_SOURCE_PERMISSIONS 37 | FILES_MATCHING PATTERN "*.py" 38 | PATTERN ".svn" EXCLUDE 39 | ) -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/Makefile: -------------------------------------------------------------------------------- 1 | include $(shell rospack find mk)/cmake.mk -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/action/Test.action: -------------------------------------------------------------------------------- 1 | float64 goal 2 | --- 3 | --- 4 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/examples/actionlib_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import rospy 4 | import smach 5 | import smach_ros 6 | 7 | from smach_tutorials.msg import TestAction, TestGoal 8 | from actionlib import * 9 | from actionlib_msgs.msg import * 10 | 11 | 12 | # Create a trivial action server 13 | class TestServer: 14 | def __init__(self,name): 15 | self._sas = SimpleActionServer(name, 16 | TestAction, 17 | execute_cb=self.execute_cb) 18 | 19 | def execute_cb(self, msg): 20 | if msg.goal == 0: 21 | self._sas.set_succeeded() 22 | elif msg.goal == 1: 23 | self._sas.set_aborted() 24 | elif msg.goal == 2: 25 | self._sas.set_preempted() 26 | 27 | def main(): 28 | rospy.init_node('smach_example_actionlib') 29 | 30 | # Start an action server 31 | server = TestServer('test_action') 32 | 33 | # Create a SMACH state machine 34 | sm0 = smach.StateMachine(outcomes=['succeeded','aborted','preempted']) 35 | 36 | # Open the container 37 | with sm0: 38 | # Add states to the container 39 | 40 | # Add a simple action state. This will use an empty, default goal 41 | # As seen in TestServer above, an empty goal will always return with 42 | # GoalStatus.SUCCEEDED, causing this simple action state to return 43 | # the outcome 'succeeded' 44 | smach.StateMachine.add('GOAL_DEFAULT', 45 | smach_ros.SimpleActionState('test_action', TestAction), 46 | {'succeeded':'GOAL_STATIC'}) 47 | 48 | # Add another simple action state. This will give a goal 49 | # that should abort the action state when it is received, so we 50 | # map 'aborted' for this state onto 'succeeded' for the state machine. 51 | smach.StateMachine.add('GOAL_STATIC', 52 | smach_ros.SimpleActionState('test_action', TestAction, 53 | goal = TestGoal(goal=1)), 54 | {'aborted':'GOAL_CB'}) 55 | 56 | 57 | # Add another simple action state. This will give a goal 58 | # that should abort the action state when it is received, so we 59 | # map 'aborted' for this state onto 'succeeded' for the state machine. 60 | def goal_callback(userdata, default_goal): 61 | goal = TestGoal() 62 | goal.goal = 2 63 | return goal 64 | 65 | smach.StateMachine.add('GOAL_CB', 66 | smach_ros.SimpleActionState('test_action', TestAction, 67 | goal_cb = goal_callback), 68 | {'aborted':'succeeded'}) 69 | 70 | # For more examples on how to set goals and process results, see 71 | # executive_smach/smach_ros/tests/smach_actionlib.py 72 | 73 | # Execute SMACH plan 74 | outcome = sm0.execute() 75 | 76 | rospy.signal_shutdown('All done.') 77 | 78 | 79 | if __name__ == '__main__': 80 | main() 81 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/examples/concurrence.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import rospy 4 | import smach 5 | import smach_ros 6 | 7 | # define state Fas 8 | class Fas(smach.State): 9 | def __init__(self): 10 | smach.State.__init__(self, outcomes=['outcome1','outcome2']) 11 | self.counter = 0 12 | 13 | def execute(self, userdata): 14 | rospy.loginfo('Executing state Fas') 15 | if self.counter < 3: 16 | self.counter += 1 17 | return 'outcome1' 18 | else: 19 | return 'outcome2' 20 | 21 | 22 | # define state Ser 23 | class Ser(smach.State): 24 | def __init__(self): 25 | smach.State.__init__(self, outcomes=['outcome1']) 26 | 27 | def execute(self, userdata): 28 | rospy.loginfo('Executing state Ser') 29 | return 'outcome1' 30 | 31 | 32 | 33 | # define state Maler 34 | class Maler(smach.State): 35 | def __init__(self): 36 | smach.State.__init__(self, outcomes=['outcome3']) 37 | 38 | def execute(self, userdata): 39 | rospy.loginfo('Executing state Maler') 40 | return 'outcome3' 41 | 42 | 43 | 44 | 45 | def main(): 46 | rospy.init_node('smach_example_state_machine') 47 | 48 | # Create the top level SMACH state machine 49 | sm_top = smach.StateMachine(outcomes=['outcome6']) 50 | 51 | # Open the container 52 | with sm_top: 53 | 54 | smach.StateMachine.add('Maler', Maler(), 55 | transitions={'outcome3':'CON'}) 56 | 57 | # Create the sub SMACH state machine 58 | sm_con = smach.Concurrence(outcomes=['outcome4','outcome5'], 59 | default_outcome='outcome4', 60 | outcome_map={'outcome5': 61 | { 'Fas':'outcome2', 62 | 'Ser':'outcome1'}}) 63 | 64 | # Open the container 65 | with sm_con: 66 | # Add states to the container 67 | smach.Concurrence.add('Fas', Fas()) 68 | smach.Concurrence.add('Ser', Ser()) 69 | 70 | smach.StateMachine.add('CON', sm_con, 71 | transitions={'outcome4':'CON', 72 | 'outcome5':'outcome6'}) 73 | 74 | # Execute SMACH plan 75 | outcome = sm_top.execute() 76 | 77 | 78 | if __name__ == '__main__': 79 | main() 80 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/examples/iterator_tutorial.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | ## %Tag(FULLTEXT)% 3 | 4 | 5 | import roslib; roslib.load_manifest('smach') 6 | roslib.load_manifest('smach_ros') 7 | import rospy 8 | 9 | import smach 10 | from smach import Iterator, StateMachine, CBState 11 | from smach_ros import ConditionState, IntrospectionServer 12 | 13 | def construct_sm(): 14 | sm = StateMachine(outcomes = ['succeeded','aborted','preempted']) 15 | sm.userdata.nums = range(25, 88, 3) 16 | sm.userdata.even_nums = [] 17 | sm.userdata.odd_nums = [] 18 | with sm: 19 | ## %Tag(ITERATOR)% 20 | tutorial_it = Iterator(outcomes = ['succeeded','preempted','aborted'], 21 | input_keys = ['nums', 'even_nums', 'odd_nums'], 22 | it = lambda: range(0, len(sm.userdata.nums)), 23 | output_keys = ['even_nums', 'odd_nums'], 24 | it_label = 'index', 25 | exhausted_outcome = 'succeeded') 26 | ## %EndTag(ITERATOR)% 27 | ## %Tag(CONTAINER)% 28 | with tutorial_it: 29 | container_sm = StateMachine(outcomes = ['succeeded','preempted','aborted','continue'], 30 | input_keys = ['nums', 'index', 'even_nums', 'odd_nums'], 31 | output_keys = ['even_nums', 'odd_nums']) 32 | with container_sm: 33 | #test wether even or odd 34 | StateMachine.add('EVEN_OR_ODD', 35 | ConditionState(cond_cb = lambda ud:ud.nums[ud.index]%2, 36 | input_keys=['nums', 'index']), 37 | {'true':'ODD', 38 | 'false':'EVEN' }) 39 | #add even state 40 | @smach.cb_interface(input_keys=['nums', 'index', 'even_nums'], 41 | output_keys=['odd_nums'], 42 | outcomes=['succeeded']) 43 | def even_cb(ud): 44 | ud.even_nums.append(ud.nums[ud.index]) 45 | return 'succeeded' 46 | StateMachine.add('EVEN', CBState(even_cb), 47 | {'succeeded':'continue'}) 48 | #add odd state 49 | @smach.cb_interface(input_keys=['nums', 'index', 'odd_nums'], 50 | output_keys=['odd_nums'], 51 | outcomes=['succeeded']) 52 | def odd_cb(ud): 53 | ud.odd_nums.append(ud.nums[ud.index]) 54 | return 'succeeded' 55 | StateMachine.add('ODD', CBState(odd_cb), 56 | {'succeeded':'continue'}) 57 | ## %EndTag(CONTAINER)% 58 | ## %Tag(ADDCONTAINER)% 59 | #close container_sm 60 | Iterator.set_contained_state('CONTAINER_STATE', 61 | container_sm, 62 | loop_outcomes=['continue']) 63 | ## %EndTag(ADDCONTAINER)% 64 | ## %Tag(ADDITERATOR)% 65 | #close the tutorial_it 66 | StateMachine.add('TUTORIAL_IT',tutorial_it, 67 | {'succeeded':'succeeded', 68 | 'aborted':'aborted'}) 69 | ## %EndTag(ADDITERATOR)% 70 | return sm 71 | 72 | def main(): 73 | rospy.init_node("iterator_tutorial") 74 | sm_iterator = construct_sm() 75 | 76 | # Run state machine introspection server for smach viewer 77 | intro_server = IntrospectionServer('iterator_tutorial',sm_iterator,'/ITERATOR_TUTORIAL') 78 | intro_server.start() 79 | 80 | 81 | outcome = sm_iterator.execute() 82 | 83 | rospy.spin() 84 | intro_server.stop() 85 | 86 | if __name__ == "__main__": 87 | main() 88 | ## %EndTag(FULLTEXT)% 89 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/examples/recovery.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import rospy 4 | import smach 5 | import smach_ros 6 | 7 | # define the main state 1 8 | class main_state_1(smach.State): 9 | def __init__(self): 10 | smach.State.__init__(self, outcomes=['FAILED','COMPLETED_ACTION']) 11 | self.counter = 0 12 | 13 | def execute(self, userdata): 14 | rospy.loginfo('Executing main state 1') 15 | if self.counter < 4: 16 | self.counter += 1 17 | return 'FAILED' 18 | else: 19 | return 'COMPLETED_ACTION' 20 | 21 | # define main state 2 22 | class main_state_2(smach.State): 23 | def __init__(self): 24 | smach.State.__init__(self, outcomes=['COMPLETED_ACTION']) 25 | 26 | def execute(self, userdata): 27 | rospy.loginfo('Executing main state 2') 28 | return 'COMPLETED_ACTION' 29 | 30 | 31 | 32 | # define recovery state 33 | class recovery_state(smach.State): 34 | def __init__(self): 35 | smach.State.__init__(self, outcomes=['COMPLETED_ACTION']) 36 | 37 | def execute(self, userdata): 38 | rospy.loginfo('Executing recovery state 1') 39 | return 'COMPLETED_ACTION' 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | def main(): 48 | rospy.init_node('smach_example_state_machine') 49 | # Create the main SMACH state machine 50 | sm_main = smach.StateMachine(outcomes=['ERROR', 'EXIT']) 51 | 52 | # Open the container 53 | with sm_main: 54 | 55 | # Add states to the container 56 | smach.StateMachine.add('STATE1', main_state_1(), 57 | transitions={'FAILED':'ERROR', 58 | 'COMPLETED_ACTION':'STATE2'}) 59 | smach.StateMachine.add('STATE2', main_state_2(), 60 | transitions={'COMPLETED_ACTION':'EXIT'}) 61 | 62 | 63 | # Create the recovery SMACH state machine 64 | sm_recv = smach.StateMachine(outcomes=['COMPLETE']) 65 | 66 | # Open the container 67 | with sm_recv: 68 | 69 | # Add states to the container 70 | smach.StateMachine.add('RECOVERY_STATE', recovery_state(), 71 | transitions={'COMPLETED_ACTION':'COMPLETE'}) 72 | 73 | 74 | 75 | # Create the top level SMACH state machine 76 | sm_top = smach.StateMachine(outcomes=['EXIT_TOP']) 77 | 78 | # Open the container 79 | with sm_top: 80 | 81 | smach.StateMachine.add('RECOVERY', sm_recv, 82 | transitions={'COMPLETE':'MAIN'}) 83 | 84 | 85 | 86 | smach.StateMachine.add('MAIN', sm_main, 87 | transitions={'EXIT':'EXIT_TOP', 88 | 'ERROR':'RECOVERY'}) 89 | 90 | # Execute SMACH plan 91 | outcome = sm_top.execute() 92 | 93 | 94 | 95 | if __name__ == '__main__': 96 | main() 97 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/examples/sequence.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Description: 4 | Create a simple 3-state state sequence. A Sequence is a StateMachine 5 | that just assumes that states added in some sequence should be 6 | executed in the order in which they were added, but only if they 7 | return the "connector outcome" given in the Sequence constructor. 8 | 9 | Usage: 10 | $> ./sequence.py 11 | 12 | Output: 13 | [INFO] : State machine starting in initial state 'FOO' with userdata: 14 | [] 15 | [INFO] : State machine transitioning 'FOO':'done'-->'BAR' 16 | [INFO] : State machine transitioning 'BAR':'done'-->'BAZ' 17 | [INFO] : State machine terminating 'BAZ':'done':'succeeded' 18 | """ 19 | 20 | import rospy 21 | import smach 22 | import smach_ros 23 | 24 | class ExampleState(smach.State): 25 | def __init__(self): 26 | smach.State.__init__(self, outcomes = ['done']) 27 | def execute(self, ud): 28 | return 'done' 29 | 30 | def main(): 31 | rospy.init_node('smach_example_sequence') 32 | 33 | # Create a SMACH state machine 34 | sq = smach.Sequence( 35 | outcomes = ['succeeded'], 36 | connector_outcome = 'done') 37 | 38 | # Open the container 39 | with sq: 40 | # Add states to the container 41 | smach.Sequence.add('Fas', ExampleState()) 42 | smach.Sequence.add('Ser', ExampleState()) 43 | smach.Sequence.add('Maler', ExampleState(), {'done':'succeeded'}) 44 | 45 | # Execute SMACH plan 46 | outcome = sq.execute() 47 | 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/examples/state_machine.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Description: 4 | Create a simple 3-state state machine. 5 | 6 | Usage: 7 | $> ./state_machine.py 8 | 9 | Output: 10 | [INFO] : State machine starting in initial state 'FOO' with userdata: 11 | [] 12 | [INFO] : State machine transitioning 'FOO':'done'-->'BAR' 13 | [INFO] : State machine transitioning 'BAR':'done'-->'BAZ' 14 | [INFO] : State machine terminating 'BAZ':'done':'succeeded' 15 | 16 | """ 17 | 18 | import smach 19 | 20 | class ExampleState(smach.State): 21 | def __init__(self): 22 | smach.State.__init__(self, outcomes = ['done']) 23 | def execute(self, ud): 24 | return 'done' 25 | 26 | def main(): 27 | # Create a SMACH state machine 28 | sm = smach.StateMachine(outcomes=['succeeded','aborted']) 29 | 30 | # Open the container 31 | with sm: 32 | # Add states to the container 33 | smach.StateMachine.add('State1', ExampleState(), {'done':'State2'}) 34 | smach.StateMachine.add('State2', ExampleState(), {'done':'State3'}) 35 | smach.StateMachine.add('State3', 36 | ExampleState(), 37 | {'done':'succeeded'}) 38 | 39 | # Execute SMACH plan 40 | outcome = sm.execute() 41 | 42 | if __name__ == '__main__': 43 | main() 44 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/examples/state_machine_nesting.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import rospy 4 | import smach 5 | import smach_ros 6 | 7 | # define state Fas 8 | class Fas(smach.State): 9 | def __init__(self): 10 | smach.State.__init__(self, outcomes=['outcome1','outcome2']) 11 | self.counter = 0 12 | 13 | def execute(self, userdata): 14 | rospy.loginfo('Executing state Fas') 15 | if self.counter < 3: 16 | self.counter += 1 17 | return 'outcome1' 18 | else: 19 | return 'outcome2' 20 | 21 | 22 | # define state Ser 23 | class Ser(smach.State): 24 | def __init__(self): 25 | smach.State.__init__(self, outcomes=['outcome1']) 26 | 27 | def execute(self, userdata): 28 | rospy.loginfo('Executing state Ser') 29 | return 'outcome1' 30 | 31 | 32 | 33 | # define state Maler 34 | class Maler(smach.State): 35 | def __init__(self): 36 | smach.State.__init__(self, outcomes=['outcome3']) 37 | 38 | def execute(self, userdata): 39 | rospy.loginfo('Executing state Maler') 40 | return 'outcome3' 41 | 42 | 43 | 44 | 45 | def main(): 46 | rospy.init_node('smach_example_state_machine') 47 | 48 | # Create the top level SMACH state machine 49 | sm_top = smach.StateMachine(outcomes=['EXIT_TOP']) 50 | 51 | # Open the container 52 | with sm_top: 53 | 54 | smach.StateMachine.add('Maler', Maler(), 55 | transitions={'outcome3':'SUB'}) 56 | 57 | # Create the sub SMACH state machine 58 | sm_sub = smach.StateMachine(outcomes=['EXIT_SUB']) 59 | 60 | # Open the container 61 | with sm_sub: 62 | 63 | # Add states to the container 64 | smach.StateMachine.add('Fas', Fas(), 65 | transitions={'outcome1':'Ser', 66 | 'outcome2':'EXIT_SUB'}) 67 | smach.StateMachine.add('Ser', Ser(), 68 | transitions={'outcome1':'Fas'}) 69 | 70 | smach.StateMachine.add('SUB', sm_sub, 71 | transitions={'EXIT_SUB':'EXIT_TOP'}) 72 | 73 | # Execute SMACH plan 74 | outcome = sm_top.execute() 75 | 76 | 77 | 78 | if __name__ == '__main__': 79 | main() 80 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/examples/state_machine_simple_introspection.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import rospy 4 | import smach 5 | import smach_ros 6 | 7 | # define state Faser 8 | class Faser(smach.State): 9 | def __init__(self): 10 | smach.State.__init__(self, outcomes=['outcome1','outcome2']) 11 | self.counter = 0 12 | 13 | def execute(self, userdata): 14 | rospy.loginfo('Executing state Faser') 15 | if self.counter < 3: 16 | self.counter += 1 17 | return 'outcome1' 18 | else: 19 | return 'outcome2' 20 | 21 | 22 | # define state Maler 23 | class Maler(smach.State): 24 | def __init__(self): 25 | smach.State.__init__(self, outcomes=['outcome2']) 26 | 27 | def execute(self, userdata): 28 | rospy.loginfo('Executing state Maler') 29 | return 'outcome2' 30 | 31 | 32 | 33 | 34 | # main 35 | def main(): 36 | rospy.init_node('smach_example_state_machine') 37 | 38 | # Create a SMACH state machine 39 | sm = smach.StateMachine(outcomes=['EXIT', 'outcome5']) 40 | 41 | # Open the container 42 | with sm: 43 | # Add states to the container 44 | smach.StateMachine.add('Faser', Faser(), 45 | transitions={'outcome1':'Faser', 46 | 'outcome2':'EXIT'}) 47 | smach.StateMachine.add('Maler', Maler(), 48 | transitions={'outcome2':'Faser'}) 49 | 50 | # Create and start the introspection server 51 | sis = smach_ros.IntrospectionServer('my_smach_introspection_server', sm, '/SM_ROOT') 52 | sis.start() 53 | 54 | # Execute SMACH plan 55 | outcome = sm.execute() 56 | 57 | # Wait for ctrl-c to stop the application 58 | rospy.spin() 59 | sis.stop() 60 | 61 | if __name__ == '__main__': 62 | main() 63 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/examples/user_data.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import rospy 4 | import smach 5 | import smach_ros 6 | 7 | # define state Faser 8 | class Faser(smach.State): 9 | def __init__(self): 10 | smach.State.__init__(self, 11 | outcomes=['outcome1','outcome2'], 12 | input_keys=['faser_counter_in'], 13 | output_keys=['faser_counter_out']) 14 | 15 | def execute(self, userdata): 16 | rospy.loginfo('Executing state Faser') 17 | if userdata.faser_counter_in < 3: 18 | userdata.faser_counter_out = userdata.faser_counter_in + 1 19 | return 'outcome1' 20 | else: 21 | return 'outcome2' 22 | 23 | 24 | # define state Maler 25 | class Maler(smach.State): 26 | def __init__(self): 27 | smach.State.__init__(self, 28 | outcomes=['outcome1'], 29 | input_keys=['maler_counter_in']) 30 | 31 | def execute(self, userdata): 32 | rospy.loginfo('Executing state BAR') 33 | rospy.loginfo('Counter = %f'%userdata.maler_counter_in) 34 | return 'outcome1' 35 | 36 | 37 | 38 | 39 | 40 | def main(): 41 | rospy.init_node('smach_example_state_machine') 42 | 43 | # Create a SMACH state machine 44 | sm = smach.StateMachine(outcomes=['EXIT']) 45 | sm.userdata.sm_counter = 0 46 | 47 | # Open the container 48 | with sm: 49 | # Add states to the container 50 | smach.StateMachine.add('Faser', Faser(), 51 | transitions={'outcome1':'Maler', 52 | 'outcome2':'EXIT'}, 53 | remapping={'faser_counter_in':'sm_counter', 54 | 'faser_counter_out':'sm_counter'}) 55 | smach.StateMachine.add('Maler', Maler(), 56 | transitions={'outcome1':'Faser'}, 57 | remapping={'maler_counter_in':'sm_counter'}) 58 | 59 | 60 | # Execute SMACH plan 61 | outcome = sm.execute() 62 | 63 | 64 | if __name__ == '__main__': 65 | main() 66 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/mainpage.dox: -------------------------------------------------------------------------------- 1 | /** 2 | \mainpage 3 | \htmlinclude manifest.html 4 | 5 | \b smach_tutorials is ... 6 | 7 | 10 | 11 | 12 | \section codeapi Code API 13 | 14 | 24 | 25 | 26 | */ 27 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/package.xml: -------------------------------------------------------------------------------- 1 | 2 | smach_tutorials 3 | 0.1.0 4 | 5 | This package containes numerous examples of how to use SMACH. See the examples directory. It is modified from the rhaschke repo. 6 | 7 | Fasermaler 8 | fasermaler 9 | BSD 10 | 11 | https://github.com/Fasermaler 12 | 13 | catkin 14 | 15 | rospy 16 | smach 17 | smach_ros 18 | 19 | turtlesim 20 | 21 | 22 | actionlib 23 | actionlib_msgs 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/smach_examples/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup 4 | from catkin_pkg.python_setup import generate_distutils_setup 5 | 6 | d = generate_distutils_setup( 7 | ## don't do this unless you want a globally visible script 8 | # scripts=['bin/myscript'], 9 | packages=['xdot'], 10 | package_dir={'': 'src'} 11 | ) 12 | 13 | setup(**d) 14 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/README.md: -------------------------------------------------------------------------------- 1 | If you came here randomly please read [Running rqt_smach (smach_viewer) with ROS Kinetic](https://gist.github.com/matt3o/88bced95dba37a8932a51904d0734dff) first! 2 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(rqt_smach) 3 | 4 | find_package(catkin REQUIRED) 5 | 6 | catkin_python_setup() 7 | 8 | catkin_package() 9 | 10 | catkin_install_python( 11 | PROGRAMS scripts/rqt_smach 12 | DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} 13 | ) 14 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/README.md: -------------------------------------------------------------------------------- 1 | rqt smach 2 | ========== 3 | 4 | ![](doc/rqt_conman.png) 5 | 6 | This is an RQT-based GUI for controlling a smach state machine. 7 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach.md: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | 4 | [Rqt\_smach] [rqt] is a Qt based user interface for the robotics state machine 5 | software [SMACH] [smach]. Rqt\_Smach displays the structure of the [SMACH] [smach] 6 | state machine, the current state, and user data. In addition, it also 7 | provides a few different graph display options, a tree view, and the 8 | ability to set the initial state in a server. 9 | 10 | [rqt]: https://github.com/jbohren/executive_smach_visualization 11 | [smach]: http://wiki.ros.org/smach 12 | 13 | ![alt text](rqt_smach_1.png) 14 | 15 | Running Rqt\_Smach 16 | ------------------ 17 | 18 | To run rqt\_smach, you must have [executive\_smach\_visulization] [1], [xdot] [2], 19 | and [executive\_smach] [3] in your [catkin workspace] [4]. Then build those 20 | packages using [catkin build] [5] or [catkin\_make] [6]. 21 | 22 | [1]: https://github.com/jbohren/executive_smach_visualization 23 | [2]: https://github.com/jbohren/xdot 24 | [3]: https://github.com/jbohren/executive_smach 25 | [4]: http://wiki.ros.org/catkin/Tutorials/create_a_workspace 26 | [5]: http://catkin-tools.readthedocs.org/en/latest/verbs/catkin_build.html 27 | [6]: http://wiki.ros.org/catkin/commands/catkin_make 28 | 29 | Once the packages are built, make sure you have a [roscore] [7] running, 30 | source your environment, and then execute the following command: 31 | 32 | rosrun rqt_smach rqt_smach 33 | 34 | [7]: http://wiki.ros.org/roscore 35 | 36 | The executive\_smach\_viewer package contains two slightly different 37 | test servers you can use to see how rqt\_smach works. If you open and 38 | source two new terminals, you can run the tests servers with these 39 | commands: 40 | 41 | rosrun smach_viewer test/server.py 42 | 43 | rosrun smach_viewer test/server2.py 44 | 45 | Features 46 | -------- 47 | 48 | Rqt\_Smach contains many features to help customize the way the state 49 | machine is displayed and to provide the user with relevant information. 50 | 51 | To begin, with the main combo box at the top of the page, you can 52 | choose to view all or part of the state machine. When '\' is selected, 53 | all servers are shown. 54 | 55 | ![alt text](rqt_smach_2_input_path.png) 56 | 57 | When you hover over a node of the graph, the border color will change 58 | and the node's path will be shown in the bottom status bar. 59 | 60 | ![alt text](rqt_smach_3_hover.png) 61 | 62 | When you click on a node, that node will be selected which means the 63 | border color will change until you select a different node, and it's 64 | user data (if any) will be shown in the right hand box. 65 | 66 | ![alt text](rqt_smach_4_click.png) 67 | 68 | Once a node is selected, you can set it as the initial state of a 69 | server by using the button in the lower right corner of the window. 70 | Once this change is made, you can see the server label move to point 71 | at the new initial state. Initial states are outlined in black rather 72 | than red. 73 | 74 | ![alt text](rqt_smach_5_set_initial.png) 75 | 76 | You can use the depth spinner to expand or collapse sub state machines 77 | and the label width spinner to limit the label width. 78 | 79 | ![alt text](rqt_smach_6_depth.png) 80 | 81 | If you selected the Show Implicit button, all transitions will be 82 | shown. 83 | 84 | ![alt text](rqt_smach_7_implicit.png) 85 | 86 | You can zoom and pan the graph using keyboard shortcuts explained when 87 | you press the'?' button. 88 | 89 | ![alt text](rqt_smach_8_keyboard.png) 90 | 91 | With Auto Zoom set, when you select a different path of the graph to 92 | view, it will automatically zoom to fit. 93 | 94 | ![alt text](rqt_smach_9_autozoom.png) 95 | 96 | However you can disable that feature by deselecting that button. 97 | 98 | ![alt text](rqt_smach_10_nozoom.png) 99 | 100 | Rqt_smach also come with a tree view which you can use to view the 101 | state machine structure. 102 | 103 | ![alt text](rqt_smach_11_tree.png) 104 | 105 | With the tree view you are also able to select nodes, view their user 106 | data, and set them as the initial state. 107 | 108 | ![alt text](rqt_smach_12_treeclick.png) 109 | 110 | When a state machine is running, the color of the nodes reflect which 111 | states are currently active. 112 | 113 | ![alt text](rqt_smach_running_1.png) 114 | 115 | ![alt text](rqt_smach_running_2.png) 116 | 117 | ![alt text](rqt_smach_running_3.png) 118 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_1.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_10_nozoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_10_nozoom.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_11_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_11_tree.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_12_treeclick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_12_treeclick.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_13_treeinitial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_13_treeinitial.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_2_input_path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_2_input_path.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_3_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_3_hover.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_4_click.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_4_click.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_5_set_initial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_5_set_initial.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_6_depth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_6_depth.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_7_implicit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_7_implicit.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_8_keyboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_8_keyboard.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_9_autozoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_9_autozoom.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_running_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_running_1.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_running_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_running_2.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_running_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/doc/rqt_smach_running_3.png -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | rqt_smach 4 | 0.0.0 5 | 6 | This is a smple rqt-based GUI for smach. It shows the state of 7 | hierarchical SMACH state machines. It can visualize the possible 8 | transitions between states, as well as the currently active state 9 | and the values of user data that is passed around between states. 10 | The smach viewer uses the SMACH debugging interface based on 11 | the smach 12 | messages to gather information from running state machines. 13 | 14 | 15 | Jonathan Bohren 16 | 17 | BSD 18 | 19 | catkin 20 | rostest 21 | 22 | xdot 23 | rospy 24 | rqt_gui 25 | rqt_gui_py 26 | rqt_dot 27 | smach_msgs 28 | smach_ros 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | An RQT plugin for interacting with the smach. 5 | 6 | 7 | 8 | 9 | 10 | 11 | system-help 12 | Use to visualize dot graphs over ROS. 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/scripts/rqt_smach: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | 5 | from rqt_gui.main import Main 6 | from rqt_smach.rqt_smach import Smach 7 | 8 | plugin = 'rqt_smach' 9 | main = Main(filename=plugin) 10 | sys.exit(main.main(standalone=plugin))#, plugin_argument_provider=Dot.add_arguments)) 11 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup 4 | from catkin_pkg.python_setup import generate_distutils_setup 5 | 6 | d = generate_distutils_setup( 7 | ## don't do this unless you want a globally visible script 8 | # scripts=['bin/myscript'], 9 | packages=['rqt_smach'], 10 | package_dir={'': 'src'}, 11 | scripts=['scripts/rqt_smach'] 12 | ) 13 | 14 | setup(**d) 15 | 16 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/src/rqt_smach/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/src/rqt_smach/__init__.py -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/src/rqt_smach/container_node.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/src/rqt_smach/container_node.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/rqt_smach/src/rqt_smach/rqt_smach.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/rqt_smach/src/rqt_smach/rqt_smach.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/smach_viewer/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package smach_viewer 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 2.0.0 (2014-04-17) 6 | ------------------ 7 | * Removing rosbuild support and old useless test 8 | * Fix lost information in package.xml 9 | That was dropped while catkinizing 10 | * Contributors: Felix Kolbe, Jonathan Bohren 11 | 12 | 1.1.0 (2013-06-29) 13 | ------------------ 14 | * Putting cmake required version call inside the rosbuild/catkin switch 15 | * Catkinizng (hybrid) 16 | * Removing old, unused dependency 17 | * Adding documentation, cleaning up some parts of the wx smach viewer 18 | * Fix for `#5122 `_: Multi-line name states aren't in activate color by smach_viewer 19 | * doc review for smach_msgs and smach_viewer 20 | * smach viewer is doc reviewed 21 | * add description for smach viewer 22 | * remove reference to executive python 23 | * smach viewer runs again 24 | * smach viewer needs rospy 25 | * use smach messages instead of executive python messages 26 | * import from https://code.ros.org/svn/wg-ros-pkg/branches/jbohren/executive_smach, which is the restructured code from the executive_python stack 27 | * Contributors: Jonathan Bohren, Wim Meeussen, wim 28 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/smach_viewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | 3 | project(smach_viewer) 4 | 5 | find_package(catkin REQUIRED COMPONENTS rostest) 6 | 7 | catkin_package( 8 | CATKIN_DEPENDS smach_ros xdot smach_msgs 9 | ) 10 | 11 | # Install targets 12 | install(PROGRAMS scripts/smach_viewer.py 13 | DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}) 14 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/smach_viewer/package.xml: -------------------------------------------------------------------------------- 1 | 2 | smach_viewer 3 | 2.0.0 4 | 5 | The smach viewer is a GUI that shows the state of hierarchical 6 | SMACH state machines. It can visualize the possible transitions 7 | between states, as well as the currently active state and the 8 | values of user data that is passed around between states. The 9 | smach viewer uses the SMACH debugging interface based on 10 | the smach 11 | messages to gather information from running state machines. 12 | 13 | Jonathan Bohren 14 | 15 | BSD 16 | 17 | http://ros.org/wiki/smach_viewer 18 | 19 | 20 | Jonathan Bohren 21 | 22 | catkin 23 | 24 | rostest 25 | 26 | smach_ros 27 | xdot 28 | smach_msgs 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/smach_viewer/src/smach_viewer/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/visualization/smach_viewer/src/smach_viewer/__init__.py -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/smach_viewer/test/server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import rospy 4 | import rostest 5 | 6 | import threading 7 | 8 | import unittest 9 | 10 | from smach import * 11 | from smach_ros import * 12 | 13 | from smach_msgs.msg import * 14 | 15 | ### Custom state classe 16 | class Setter(State): 17 | """State that sets the key 'a' in its userdata""" 18 | def __init__(self): 19 | State.__init__(self,['done', 'preempted'],[],['a','a1','a2']) 20 | def execute(self,ud): 21 | rospy.sleep(1.0) 22 | ud.a = 'A' 23 | ud.a1 = 'A1' 24 | ud.a2 = 'A2' 25 | rospy.loginfo("Added 'a' keys.") 26 | return 'done' 27 | 28 | class Getter(State): 29 | """State that grabs the key 'a' from userdata, and sets 'b'""" 30 | def __init__(self): 31 | State.__init__(self,['done', 'preempted'],['a'],['b']) 32 | def execute(self,ud): 33 | while 'a' not in ud and not rospy.is_shutdown(): 34 | #rospy.loginfo("Waiting for key 'a' to appear. ") 35 | rospy.sleep(0.1) 36 | ud.b = ud.a 37 | return 'done' 38 | 39 | def main(): 40 | """Test introspection system.""" 41 | 42 | rospy.init_node('viewer_test',log_level=rospy.DEBUG) 43 | 44 | # Construct state machine 45 | sm = StateMachine(['done','preempted']) 46 | sm2 = StateMachine(['done','preempted']) 47 | sm3 = StateMachine(['done','preempted']) 48 | 49 | with sm: 50 | # Note: the following "Getter" state should fail 51 | StateMachine.add('GETTER1', Getter(), {}) 52 | StateMachine.add('SM2', sm2, {'done':'SM3'}) 53 | with sm2: 54 | StateMachine.add("SETTER", Setter(), {}) 55 | StateMachine.add('SM3', sm3, {'done':'GETTER1'}) 56 | with sm3: 57 | StateMachine.add("SETTER", Setter(), {}) 58 | StateMachine.add('SETTER_ROOT', Setter(), {'done':'SM2'}) 59 | 60 | sm.set_initial_state(['SETTER_ROOT']) 61 | sm2.set_initial_state(['SETTER']) 62 | sm3.set_initial_state(['SETTER']) 63 | 64 | # Run introspector 65 | server = IntrospectionServer('viewer_test',sm,'/viewer_test') 66 | server_thread = threading.Thread(target=server.start) 67 | server_thread.start() 68 | 69 | sm.execute() 70 | 71 | rospy.spin() 72 | 73 | 74 | if __name__=="__main__": 75 | main(); 76 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/smach_viewer/test/server2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import rospy 4 | import rostest 5 | 6 | import threading 7 | 8 | import unittest 9 | 10 | from smach import * 11 | from smach_ros import * 12 | 13 | from smach_msgs.msg import * 14 | 15 | ### Custom state classe 16 | class Setter(State): 17 | """State that sets the key 'a' in its userdata""" 18 | def __init__(self): 19 | State.__init__(self,['done'],[],['a']) 20 | def execute(self,ud): 21 | rospy.sleep(1.0) 22 | ud.a = 'A' 23 | rospy.loginfo("Added key 'a'.") 24 | return 'done' 25 | 26 | class Getter(State): 27 | """State that grabs the key 'a' from userdata, and sets 'b'""" 28 | def __init__(self): 29 | State.__init__(self,['done'],['a'],['b']) 30 | def execute(self,ud): 31 | while 'a' not in ud and not rospy.is_shutdown(): 32 | #rospy.loginfo("Waiting for key 'a' to appear. ") 33 | rospy.sleep(0.1) 34 | ud.b = ud.a 35 | return 'done' 36 | 37 | def main(): 38 | """Test introspection system.""" 39 | 40 | rospy.init_node('viewer_test2',log_level=rospy.DEBUG) 41 | 42 | # Construct state machine 43 | sm = StateMachine(['done']) 44 | sm2 = StateMachine(['done']) 45 | sm3 = StateMachine(['done']) 46 | 47 | with sm: 48 | # Note: the following "Getter" state should fail 49 | StateMachine.add('2GETTER1', Getter(), {}) 50 | StateMachine.add('2SM2', sm2, {'done':'2SM3'}) 51 | with sm2: 52 | StateMachine.add("2SETTER", Setter(), {}) 53 | StateMachine.add('2SM3', sm3, {'done':'done'}) 54 | with sm3: 55 | StateMachine.add("2SETTER", Setter(), {}) 56 | StateMachine.add('2GETTER2', Getter(), {'done':'2SM2'}) 57 | 58 | sm.set_initial_state(['2GETTER1']) 59 | sm2.set_initial_state(['2SETTER']) 60 | sm3.set_initial_state(['2SETTER']) 61 | 62 | # Run introspector 63 | server = IntrospectionServer('viewer_test2',sm,'/viewer_test2') 64 | server_thread = threading.Thread(target=server.start) 65 | server_thread.start() 66 | 67 | rospy.spin() 68 | 69 | 70 | if __name__=="__main__": 71 | main(); 72 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/visualization/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package executive_smach_visualization 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 2.0.0 (2014-04-17) 6 | ------------------ 7 | * Adding metapackage 8 | * Contributors: Jonathan Bohren 9 | 10 | 1.1.0 (2013-06-29) 11 | ------------------ 12 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/visualization/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(executive_smach_visualization) 3 | find_package(catkin REQUIRED) 4 | catkin_metapackage() 5 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/visualization/visualization/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | executive_smach_visualization 4 | 2.0.0 5 | 6 | This metapackage depends on the SMACH visualization tools. 7 | 8 | Jonathan Bohren 9 | BSD 10 | 11 | http://ros.org/wiki/smach 12 | Jonathan Bohren 13 | Wim Meeussen 14 | 15 | catkin 16 | smach_viewer 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package xdot 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 2.0.1 (2014-04-17) 6 | ------------------ 7 | 8 | 2.0.0 (2014-04-17) 9 | ------------------ 10 | * Removing garbage from package.xml 11 | * Removing rosbuild support 12 | * Contributors: Jonathan Bohren 13 | 14 | 1.10.0 (2013-06-28) 15 | ------------------- 16 | * Merging experimental qt support, hybrid buildsystem 17 | * updating version 18 | * Catkinizing (hybrid), and adding experimental xdot support import 19 | * Adding beginning of xdot qt conversion by Alex Bravo 20 | * Moving this into a scripts dir 21 | * removing empty space 22 | * Making this into a unary stack 23 | * modified dep type of catkin 24 | * update setup() to use generate_distutils_setup 25 | * updated to latest catkin 26 | * updated cmake min version to 2.8.3 27 | * updated catkin variables 28 | * use install destination variables, removed manual installation of manifests 29 | * removed obsolete catkin tag from manifest files 30 | * added missing catkin tag to manifests 31 | * converting rxtools, rxgraph, and rxbag to catkin/setup.py 32 | * removing unused doxygen 33 | * staging to new rx stack 34 | * Contributors: Jonathan Bohren, dthomas, kwc 35 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(xdot) 3 | 4 | # Load catkin and all dependencies required for this package 5 | find_package(catkin REQUIRED) 6 | 7 | catkin_package( 8 | DEPENDS wxpython graphviz 9 | ) 10 | 11 | catkin_python_setup() 12 | 13 | install(PROGRAMS scripts/dot_viewer.py 14 | DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}) 15 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/README.md: -------------------------------------------------------------------------------- 1 | If you came here randomly please read [Running rqt_smach (smach_viewer) with ROS Kinetic](https://gist.github.com/matt3o/88bced95dba37a8932a51904d0734dff) first! 2 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/package.xml: -------------------------------------------------------------------------------- 1 | 2 | xdot 3 | 2.0.1 4 | 5 | XDot.py, by Jose Fonseca, is an interactive viewer for graphs written in 6 | Graphviz's dot language. 7 | 8 | This package adds front-end capabilities to XDot including WX Widget 9 | support and experimental Qt support and a mechanism for receiving callbacks 10 | when nodes are clicked. This extension is provided as BSD. 11 | 12 | Jonathan Bohren 13 | 14 | LGPL/BSD 15 | 16 | https://github.com/jrfonseca/xdot.py 17 | 18 | 19 | Jose Fonseca 20 | 21 | Jonathan Bohren 22 | 23 | Alex Bravo 24 | 25 | wxpython 26 | graphviz 27 | 28 | catkin 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/scripts/dot_viewer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (c) 2010, Willow Garage, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # 9 | # * Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in the 13 | # documentation and/or other materials provided with the distribution. 14 | # * Neither the name of the Willow Garage, Inc. nor the names of its 15 | # contributors may be used to endorse or promote products derived from 16 | # this software without specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | # POSSIBILITY OF SUCH DAMAGE. 29 | # 30 | # Author: Jonathan Bohren 31 | 32 | import sys 33 | import xdot 34 | import wx 35 | 36 | def main(): 37 | import optparse 38 | 39 | parser = optparse.OptionParser( 40 | usage='\n\t%prog [file]') 41 | parser.add_option( 42 | '-f', '--filter', 43 | type='choice', choices=('dot', 'neato', 'twopi', 'circo', 'fdp'), 44 | dest='filter', default='dot', 45 | help='graphviz filter: dot, neato, twopi, circo, or fdp [default: %default]') 46 | 47 | (options, args) = parser.parse_args(sys.argv[1:]) 48 | if len(args) > 1: 49 | parser.error('incorrect number of arguments') 50 | 51 | app = wx.App() 52 | 53 | frame = xdot.wxxdot.WxDotFrame() 54 | frame.set_filter(options.filter) 55 | 56 | """Sample mouse event.""" 57 | #def print_cb(item,event): 58 | # print "MOUSE_EVENT: "+str(item) 59 | #frame.widget.register_select_callback(print_cb) 60 | 61 | frame.Show() 62 | if len(args) >= 1: 63 | if args[0] == '-': 64 | frame.set_dotcode(sys.stdin.read()) 65 | else: 66 | frame.open_file(args[0]) 67 | 68 | app.MainLoop() 69 | 70 | if __name__ == '__main__': 71 | main() 72 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup 4 | from catkin_pkg.python_setup import generate_distutils_setup 5 | 6 | d = generate_distutils_setup( 7 | ## don't do this unless you want a globally visible script 8 | # scripts=['bin/myscript'], 9 | packages=['xdot'], 10 | package_dir={'': 'src'} 11 | ) 12 | 13 | setup(**d) 14 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/src/xdot/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/xdot/src/xdot/__init__.py -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/src/xdot/xdot_qt.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fasermaler/coding-notes/04e633dbeade96a17d806a7c63a9a9d6e597dfd3/ros_smach/example_ws/src/xdot/src/xdot/xdot_qt.pyc -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/test/dot_files/clusters.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | 3 | subgraph cluster_0 { 4 | style=filled; 5 | color=lightgrey; 6 | node [style=filled,color=white]; 7 | a0 -> a1 -> a2 -> a3; 8 | label = "process #1"; 9 | } 10 | 11 | subgraph cluster_1 { 12 | node [style=filled]; 13 | b0 -> b1 -> b2 -> b3; 14 | label = "process #2"; 15 | color=blue 16 | } 17 | start -> a0; 18 | start -> b0; 19 | a1 -> b3; 20 | b2 -> a3; 21 | a3 -> a0; 22 | a3 -> end; 23 | b3 -> end; 24 | 25 | start [shape=Mdiamond]; 26 | end [shape=Msquare]; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/test/dot_files/datastruct.gv.dot: -------------------------------------------------------------------------------- 1 | digraph g { 2 | graph [ 3 | rankdir = "LR" 4 | ]; 5 | node [ 6 | fontsize = "16" 7 | shape = "ellipse" 8 | ]; 9 | edge [ 10 | ]; 11 | "node0" [ 12 | label = " 0x10ba8| " 13 | shape = "record" 14 | ]; 15 | "node1" [ 16 | label = " 0xf7fc4380| | |-1" 17 | shape = "record" 18 | ]; 19 | "node2" [ 20 | label = " 0xf7fc44b8| | |2" 21 | shape = "record" 22 | ]; 23 | "node3" [ 24 | label = " 3.43322790286038071e-06|44.79998779296875|0" 25 | shape = "record" 26 | ]; 27 | "node4" [ 28 | label = " 0xf7fc4380| | |2" 29 | shape = "record" 30 | ]; 31 | "node5" [ 32 | label = " (nil)| | |-1" 33 | shape = "record" 34 | ]; 35 | "node6" [ 36 | label = " 0xf7fc4380| | |1" 37 | shape = "record" 38 | ]; 39 | "node7" [ 40 | label = " 0xf7fc4380| | |2" 41 | shape = "record" 42 | ]; 43 | "node8" [ 44 | label = " (nil)| | |-1" 45 | shape = "record" 46 | ]; 47 | "node9" [ 48 | label = " (nil)| | |-1" 49 | shape = "record" 50 | ]; 51 | "node10" [ 52 | label = " (nil)| | |-1" 53 | shape = "record" 54 | ]; 55 | "node11" [ 56 | label = " (nil)| | |-1" 57 | shape = "record" 58 | ]; 59 | "node12" [ 60 | label = " 0xf7fc43e0| | |1" 61 | shape = "record" 62 | ]; 63 | "node0":f0 -> "node1":f0 [ 64 | id = 0 65 | ]; 66 | "node0":f1 -> "node2":f0 [ 67 | id = 1 68 | ]; 69 | "node1":f0 -> "node3":f0 [ 70 | id = 2 71 | ]; 72 | "node1":f1 -> "node4":f0 [ 73 | id = 3 74 | ]; 75 | "node1":f2 -> "node5":f0 [ 76 | id = 4 77 | ]; 78 | "node4":f0 -> "node3":f0 [ 79 | id = 5 80 | ]; 81 | "node4":f1 -> "node6":f0 [ 82 | id = 6 83 | ]; 84 | "node4":f2 -> "node10":f0 [ 85 | id = 7 86 | ]; 87 | "node6":f0 -> "node3":f0 [ 88 | id = 8 89 | ]; 90 | "node6":f1 -> "node7":f0 [ 91 | id = 9 92 | ]; 93 | "node6":f2 -> "node9":f0 [ 94 | id = 10 95 | ]; 96 | "node7":f0 -> "node3":f0 [ 97 | id = 11 98 | ]; 99 | "node7":f1 -> "node1":f0 [ 100 | id = 12 101 | ]; 102 | "node7":f2 -> "node8":f0 [ 103 | id = 13 104 | ]; 105 | "node10":f1 -> "node11":f0 [ 106 | id = 14 107 | ]; 108 | "node10":f2 -> "node12":f0 [ 109 | id = 15 110 | ]; 111 | "node11":f2 -> "node1":f0 [ 112 | id = 16 113 | ]; 114 | } 115 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/test/dot_files/fdpclust.dot: -------------------------------------------------------------------------------- 1 | graph G { 2 | e 3 | subgraph clusterA { 4 | a -- b; 5 | subgraph clusterC { 6 | C -- D; 7 | } 8 | } 9 | subgraph clusterB { 10 | d -- f 11 | } 12 | d -- D 13 | e -- clusterB 14 | clusterC -- clusterB 15 | } 16 | 17 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/test/dot_files/hello.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | Hello [URL="http://en.wikipedia.org/wiki/Hello"] 3 | World [URL="http://en.wikipedia.org/wiki/World"] 4 | Hello -> World 5 | } 6 | 7 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/test/dot_files/process.gv.dot: -------------------------------------------------------------------------------- 1 | graph G { 2 | run -- intr; 3 | intr -- runbl; 4 | runbl -- run; 5 | run -- kernel; 6 | kernel -- zombie; 7 | kernel -- sleep; 8 | kernel -- runmem; 9 | sleep -- swap; 10 | swap -- runswap; 11 | runswap -- new; 12 | runswap -- runmem; 13 | new -- runmem; 14 | sleep -- runmem; 15 | } 16 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/test/dot_files/psg.gv.dot: -------------------------------------------------------------------------------- 1 | ##"I made a program to generate dot files representing the LR(0) state graph along with computed LALR(1) lookahead for an arbitrary context-free grammar, to make the diagrams I used in this article: http://blog.lab49.com/archives/2471. The program also highlights errant nodes in red if the grammar would produce a shift/reduce or reduce/reduce conflict -- you may be able to go to http://kthielen.dnsalias.com:8082/ to produce a graph more to your liking". Contributed by Kalani Thielen. 2 | 3 | ##Command to get the layout: "dot -Gsize=10,15 -Tpng thisfile > thisfile.png" 4 | 5 | digraph g { 6 | graph [fontsize=30 labelloc="t" label="" splines=true overlap=false rankdir = "LR"]; 7 | ratio = auto; 8 | "state0" [ style = "filled, bold" penwidth = 5 fillcolor = "white" fontname = "Courier New" shape = "Mrecord" label =<
State #0
(0) s -> •e $
(1) e -> •l '=' r
(2) e -> •r
(3) l -> •'*' r
(4) l -> •'n'
(5) r -> •l
> ]; 9 | "state1" [ style = "filled" penwidth = 1 fillcolor = "white" fontname = "Courier New" shape = "Mrecord" label =<
State #1
(3) l -> •'*' r
(3) l -> '*' •r
(4) l -> •'n'
(5) r -> •l
> ]; 10 | "state2" [ style = "filled" penwidth = 1 fillcolor = "white" fontname = "Courier New" shape = "Mrecord" label =<
State #2
(4) l -> 'n' •=$
> ]; 11 | "state3" [ style = "filled" penwidth = 1 fillcolor = "white" fontname = "Courier New" shape = "Mrecord" label =<
State #3
(5) r -> l •=$
> ]; 12 | "state4" [ style = "filled" penwidth = 1 fillcolor = "white" fontname = "Courier New" shape = "Mrecord" label =<
State #4
(3) l -> '*' r •=$
> ]; 13 | "state5" [ style = "filled" penwidth = 1 fillcolor = "black" fontname = "Courier New" shape = "Mrecord" label =<
State #5
(0) s -> e •$
> ]; 14 | "state6" [ style = "filled" penwidth = 1 fillcolor = "white" fontname = "Courier New" shape = "Mrecord" label =<
State #6
(1) e -> l •'=' r
(5) r -> l •$
> ]; 15 | "state7" [ style = "filled" penwidth = 1 fillcolor = "white" fontname = "Courier New" shape = "Mrecord" label =<
State #7
(1) e -> l '=' •r
(3) l -> •'*' r
(4) l -> •'n'
(5) r -> •l
> ]; 16 | "state8" [ style = "filled" penwidth = 1 fillcolor = "white" fontname = "Courier New" shape = "Mrecord" label =<
State #8
(1) e -> l '=' r •$
> ]; 17 | "state9" [ style = "filled" penwidth = 1 fillcolor = "white" fontname = "Courier New" shape = "Mrecord" label =<
State #9
(2) e -> r •$
> ]; 18 | state0 -> state5 [ penwidth = 5 fontsize = 28 fontcolor = "black" label = "e" ]; 19 | state0 -> state6 [ penwidth = 5 fontsize = 28 fontcolor = "black" label = "l" ]; 20 | state0 -> state9 [ penwidth = 5 fontsize = 28 fontcolor = "black" label = "r" ]; 21 | state0 -> state1 [ penwidth = 1 fontsize = 14 fontcolor = "grey28" label = "'*'" ]; 22 | state0 -> state2 [ penwidth = 1 fontsize = 14 fontcolor = "grey28" label = "'n'" ]; 23 | state1 -> state1 [ penwidth = 1 fontsize = 14 fontcolor = "grey28" label = "'*'" ]; 24 | state1 -> state4 [ penwidth = 5 fontsize = 28 fontcolor = "black" label = "r" ]; 25 | state1 -> state2 [ penwidth = 1 fontsize = 14 fontcolor = "grey28" label = "'n'" ]; 26 | state1 -> state3 [ penwidth = 5 fontsize = 28 fontcolor = "black" label = "l" ]; 27 | state6 -> state7 [ penwidth = 1 fontsize = 14 fontcolor = "grey28" label = "'='" ]; 28 | state7 -> state8 [ penwidth = 5 fontsize = 28 fontcolor = "black" label = "r" ]; 29 | state7 -> state1 [ penwidth = 1 fontsize = 14 fontcolor = "grey28" label = "'*'" ]; 30 | state7 -> state2 [ penwidth = 1 fontsize = 14 fontcolor = "grey28" label = "'n'" ]; 31 | state7 -> state3 [ penwidth = 5 fontsize = 28 fontcolor = "black" label = "l" ]; 32 | } 33 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/test/dot_files/unix.gv.dot: -------------------------------------------------------------------------------- 1 | /* courtesy Ian Darwin and Geoff Collyer, Softquad Inc. */ 2 | digraph unix { 3 | size="6,6"; 4 | node [color=lightblue2, style=filled]; 5 | "5th Edition" -> "6th Edition"; 6 | "5th Edition" -> "PWB 1.0"; 7 | "6th Edition" -> "LSX"; 8 | "6th Edition" -> "1 BSD"; 9 | "6th Edition" -> "Mini Unix"; 10 | "6th Edition" -> "Wollongong"; 11 | "6th Edition" -> "Interdata"; 12 | "Interdata" -> "Unix/TS 3.0"; 13 | "Interdata" -> "PWB 2.0"; 14 | "Interdata" -> "7th Edition"; 15 | "7th Edition" -> "8th Edition"; 16 | "7th Edition" -> "32V"; 17 | "7th Edition" -> "V7M"; 18 | "7th Edition" -> "Ultrix-11"; 19 | "7th Edition" -> "Xenix"; 20 | "7th Edition" -> "UniPlus+"; 21 | "V7M" -> "Ultrix-11"; 22 | "8th Edition" -> "9th Edition"; 23 | "1 BSD" -> "2 BSD"; 24 | "2 BSD" -> "2.8 BSD"; 25 | "2.8 BSD" -> "Ultrix-11"; 26 | "2.8 BSD" -> "2.9 BSD"; 27 | "32V" -> "3 BSD"; 28 | "3 BSD" -> "4 BSD"; 29 | "4 BSD" -> "4.1 BSD"; 30 | "4.1 BSD" -> "4.2 BSD"; 31 | "4.1 BSD" -> "2.8 BSD"; 32 | "4.1 BSD" -> "8th Edition"; 33 | "4.2 BSD" -> "4.3 BSD"; 34 | "4.2 BSD" -> "Ultrix-32"; 35 | "PWB 1.0" -> "PWB 1.2"; 36 | "PWB 1.0" -> "USG 1.0"; 37 | "PWB 1.2" -> "PWB 2.0"; 38 | "USG 1.0" -> "CB Unix 1"; 39 | "USG 1.0" -> "USG 2.0"; 40 | "CB Unix 1" -> "CB Unix 2"; 41 | "CB Unix 2" -> "CB Unix 3"; 42 | "CB Unix 3" -> "Unix/TS++"; 43 | "CB Unix 3" -> "PDP-11 Sys V"; 44 | "USG 2.0" -> "USG 3.0"; 45 | "USG 3.0" -> "Unix/TS 3.0"; 46 | "PWB 2.0" -> "Unix/TS 3.0"; 47 | "Unix/TS 1.0" -> "Unix/TS 3.0"; 48 | "Unix/TS 3.0" -> "TS 4.0"; 49 | "Unix/TS++" -> "TS 4.0"; 50 | "CB Unix 3" -> "TS 4.0"; 51 | "TS 4.0" -> "System V.0"; 52 | "System V.0" -> "System V.2"; 53 | "System V.2" -> "System V.3"; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /ros_smach/example_ws/src/xdot/test/dot_files/world.gv.dot: -------------------------------------------------------------------------------- 1 | digraph world { 2 | size="7,7"; 3 | {rank=same; S8 S24 S1 S35 S30;} 4 | {rank=same; T8 T24 T1 T35 T30;} 5 | {rank=same; 43 37 36 10 2;} 6 | {rank=same; 25 9 38 40 13 17 12 18;} 7 | {rank=same; 26 42 11 3 33 19 39 14 16;} 8 | {rank=same; 4 31 34 21 41 28 20;} 9 | {rank=same; 27 5 22 32 29 15;} 10 | {rank=same; 6 23;} 11 | {rank=same; 7;} 12 | 13 | S8 -> 9; 14 | S24 -> 25; 15 | S24 -> 27; 16 | S1 -> 2; 17 | S1 -> 10; 18 | S35 -> 43; 19 | S35 -> 36; 20 | S30 -> 31; 21 | S30 -> 33; 22 | 9 -> 42; 23 | 9 -> T1; 24 | 25 -> T1; 25 | 25 -> 26; 26 | 27 -> T24; 27 | 2 -> {3 ; 16 ; 17 ; T1 ; 18} 28 | 10 -> { 11 ; 14 ; T1 ; 13; 12;} 29 | 31 -> T1; 30 | 31 -> 32; 31 | 33 -> T30; 32 | 33 -> 34; 33 | 42 -> 4; 34 | 26 -> 4; 35 | 3 -> 4; 36 | 16 -> 15; 37 | 17 -> 19; 38 | 18 -> 29; 39 | 11 -> 4; 40 | 14 -> 15; 41 | 37 -> {39 ; 41 ; 38 ; 40;} 42 | 13 -> 19; 43 | 12 -> 29; 44 | 43 -> 38; 45 | 43 -> 40; 46 | 36 -> 19; 47 | 32 -> 23; 48 | 34 -> 29; 49 | 39 -> 15; 50 | 41 -> 29; 51 | 38 -> 4; 52 | 40 -> 19; 53 | 4 -> 5; 54 | 19 -> {21 ; 20 ; 28;} 55 | 5 -> {6 ; T35 ; 23;} 56 | 21 -> 22; 57 | 20 -> 15; 58 | 28 -> 29; 59 | 6 -> 7; 60 | 15 -> T1; 61 | 22 -> T35; 62 | 22 -> 23; 63 | 29 -> T30; 64 | 7 -> T8; 65 | 23 -> T24; 66 | 23 -> T1; 67 | } 68 | --------------------------------------------------------------------------------