├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README ├── bot2-core ├── CMakeLists.txt ├── Doxyfile ├── Makefile ├── README ├── cmake │ ├── lcmtypes.cmake │ └── pods.cmake ├── java │ ├── CMakeLists.txt │ └── src │ │ └── bot2_spy │ │ ├── ImagePlugin.java │ │ └── PlanarLidarPlugin.java ├── lcmtypes │ ├── bot_core_image_metadata_t.lcm │ ├── bot_core_image_sync_t.lcm │ ├── bot_core_image_t.lcm │ ├── bot_core_planar_lidar_t.lcm │ ├── bot_core_pose_t.lcm │ ├── bot_core_raw_t.lcm │ ├── bot_core_rigid_transform_t.lcm │ └── bot_core_sensor_status_t.lcm └── src │ └── bot_core │ ├── CMakeLists.txt │ ├── bot_core.h │ ├── camtrans.c │ ├── camtrans.h │ ├── circular.c │ ├── circular.h │ ├── color_util.c │ ├── color_util.h │ ├── ctrans.c │ ├── ctrans.h │ ├── fasttrig.c │ ├── fasttrig.h │ ├── fileutils.c │ ├── fileutils.h │ ├── glib_util.c │ ├── glib_util.h │ ├── gps_linearize.c │ ├── gps_linearize.h │ ├── lcm_util.c │ ├── lcm_util.h │ ├── math_util.h │ ├── minheap.c │ ├── minheap.h │ ├── ppm.c │ ├── ppm.h │ ├── ptr_circular.c │ ├── ptr_circular.h │ ├── rand_util.c │ ├── rand_util.h │ ├── ringbuf.c │ ├── ringbuf.h │ ├── rotations.c │ ├── rotations.h │ ├── serial.c │ ├── serial.h │ ├── set.c │ ├── set.h │ ├── signal_pipe.c │ ├── signal_pipe.h │ ├── small_linalg.c │ ├── small_linalg.h │ ├── ssocket.c │ ├── ssocket.h │ ├── tictoc.c │ ├── tictoc.h │ ├── timespec.c │ ├── timespec.h │ ├── timestamp.c │ ├── timestamp.h │ ├── trans.c │ └── trans.h ├── bot2-frames ├── CMakeLists.txt ├── Makefile ├── README ├── cmake │ ├── lcmtypes.cmake │ └── pods.cmake ├── lcmtypes │ └── bot_frames_update_t.lcm └── src │ ├── CMakeLists.txt │ ├── bot_frames.c │ ├── bot_frames.h │ ├── renderer │ ├── CMakeLists.txt │ ├── articulated_body_renderer.c │ ├── bot_frames_renderers.h │ ├── coord_frames_renderer.c │ ├── frame_modifier_renderer.c │ └── test_viewer.c │ └── test │ ├── CMakeLists.txt │ ├── coord_frames_test.c │ └── test_params.cfg ├── bot2-lcm-utils ├── CMakeLists.txt ├── Makefile ├── README ├── cmake │ └── pods.cmake ├── python │ ├── CMakeLists.txt │ └── src │ │ └── bot_log2mat │ │ ├── __init__.py │ │ ├── log_to_mat.py │ │ └── scan_for_lcmtypes.py └── src │ ├── logfilter │ ├── CMakeLists.txt │ └── lcm-logfilter.c │ ├── logsplice │ ├── CMakeLists.txt │ └── lcm-logsplice.c │ ├── tunnel │ ├── CMakeLists.txt │ ├── introspect.c │ ├── introspect.h │ ├── lcm_tunnel.cpp │ ├── lcm_tunnel.h │ ├── lcm_tunnel_disconnect_msg_t.c │ ├── lcm_tunnel_disconnect_msg_t.h │ ├── lcm_tunnel_disconnect_msg_t.lcm │ ├── lcm_tunnel_params_t.c │ ├── lcm_tunnel_params_t.h │ ├── lcm_tunnel_params_t.lcm │ ├── lcm_tunnel_server.cpp │ ├── lcm_tunnel_server.h │ ├── lcm_tunnel_sub_msg_t.c │ ├── lcm_tunnel_sub_msg_t.h │ ├── lcm_tunnel_sub_msg_t.lcm │ ├── lcm_tunnel_udp_msg_t.c │ ├── lcm_tunnel_udp_msg_t.h │ ├── lcm_tunnel_udp_msg_t.lcm │ ├── lcm_util.c │ ├── lcm_util.h │ ├── ldpc │ │ ├── README │ │ ├── getopt.cpp │ │ ├── getopt.h │ │ ├── ldpc_create_pchk.cpp │ │ ├── ldpc_create_pchk.h │ │ ├── ldpc_fec.cpp │ │ ├── ldpc_fec.h │ │ ├── ldpc_fec_iterative_decoding.cpp │ │ ├── ldpc_matrix_sparse.cpp │ │ ├── ldpc_matrix_sparse.h │ │ ├── ldpc_profile.h │ │ ├── ldpc_rand.cpp │ │ ├── ldpc_rand.h │ │ ├── ldpc_scheme.cpp │ │ ├── ldpc_scheme.h │ │ ├── ldpc_types.h │ │ ├── ldpc_wrapper.cpp │ │ ├── ldpc_wrapper.h │ │ ├── ldpc_wrapper_test.cpp │ │ ├── macros.h │ │ ├── tools.cpp │ │ └── tools.h │ ├── signal_pipe.c │ ├── signal_pipe.h │ ├── ssocket.c │ └── ssocket.h │ └── who │ ├── CMakeLists.txt │ ├── lcm-who.c │ ├── signal_pipe.c │ └── signal_pipe.h ├── bot2-lcmgl ├── CMakeLists.txt ├── Makefile ├── README ├── cmake │ ├── lcmtypes.cmake │ └── pods.cmake ├── java │ ├── CMakeLists.txt │ └── src │ │ └── bot_lcmgl │ │ └── LCMGL.java ├── lcmtypes │ └── bot_lcmgl_data_t.lcm ├── python │ ├── CMakeLists.txt │ └── src │ │ └── bot_lcmgl │ │ ├── __init__.py │ │ └── lcmgl.py └── src │ ├── bot_lcmgl_client │ ├── CMakeLists.txt │ ├── lcmgl.c │ └── lcmgl.h │ ├── bot_lcmgl_render │ ├── CMakeLists.txt │ ├── lcmgl_bot_renderer.c │ ├── lcmgl_bot_renderer.h │ ├── lcmgl_decode.c │ └── lcmgl_decode.h │ └── lcmgl-viewer │ ├── CMakeLists.txt │ ├── main.c │ ├── udp_util.c │ ├── udp_util.h │ ├── view_menu.c │ └── view_menu.h ├── bot2-param ├── CMakeLists.txt ├── Makefile ├── README ├── cmake │ ├── lcmtypes.cmake │ └── pods.cmake ├── lcmtypes │ ├── README.txt │ ├── bot_param_entry_t.lcm │ ├── bot_param_request_t.lcm │ ├── bot_param_set_t.lcm │ └── bot_param_update_t.lcm └── src │ ├── param_client │ ├── CMakeLists.txt │ ├── misc_utils.h │ ├── param_client.h │ ├── param_internal.c │ ├── param_internal.h │ ├── param_util.c │ └── param_util.h │ ├── param_server │ ├── CMakeLists.txt │ ├── lcm_util.c │ ├── lcm_util.h │ ├── param_server.c │ └── param_tool.c │ └── param_tester │ ├── CMakeLists.txt │ ├── param_dump.c │ └── param_tester.c ├── bot2-procman ├── CMakeLists.txt ├── Makefile ├── README ├── cmake │ ├── lcmtypes.cmake │ └── pods.cmake ├── doc │ ├── Doxyfile │ ├── DoxygenLayout.xml │ ├── content │ │ ├── comms.md │ │ ├── config_file.md │ │ ├── design.md │ │ ├── main.md │ │ └── tutorial.md │ ├── footer.html │ └── images │ │ ├── procman-sheriff-screenshot.png │ │ ├── sheriff-gui-add-command-menu.png │ │ ├── sheriff-gui-add-command.png │ │ ├── sheriff-gui-command-running.png │ │ ├── sheriff-gui-empty.png │ │ ├── sheriff-gui-start-command-menu.png │ │ └── sheriff-gui-with-xterm-stopped.png ├── lcmtypes │ ├── bot_procman_command2_t.lcm │ ├── bot_procman_deputy_cmd2_t.lcm │ ├── bot_procman_deputy_cmd_t.lcm │ ├── bot_procman_discovery_t.lcm │ ├── bot_procman_info2_t.lcm │ ├── bot_procman_info_t.lcm │ ├── bot_procman_orders2_t.lcm │ ├── bot_procman_orders_t.lcm │ ├── bot_procman_printf_t.lcm │ ├── bot_procman_sheriff_cmd2_t.lcm │ └── bot_procman_sheriff_cmd_t.lcm ├── python │ ├── CMakeLists.txt │ ├── procman-sheriff.glade │ ├── scripts │ │ └── bot-procman-sheriff │ ├── setup.py │ └── src │ │ └── bot_procman │ │ ├── __init__.py │ │ ├── command2_t.py │ │ ├── deputy_cmd2_t.py │ │ ├── deputy_cmd_t.py │ │ ├── discovery_t.py │ │ ├── info2_t.py │ │ ├── info_t.py │ │ ├── orders2_t.py │ │ ├── orders_t.py │ │ ├── printf_t.py │ │ ├── sheriff.py │ │ ├── sheriff_cmd2_t.py │ │ ├── sheriff_cmd_t.py │ │ ├── sheriff_config.py │ │ ├── sheriff_gtk │ │ ├── __init__.py │ │ ├── command_console.py │ │ ├── command_model.py │ │ ├── command_treeview.py │ │ ├── hosts_treeview.py │ │ ├── sheriff_dialogs.py │ │ └── sheriff_gtk.py │ │ ├── sheriff_script.py │ │ └── signal_slot.py └── src │ └── deputy │ ├── CMakeLists.txt │ ├── lcm_util.c │ ├── lcm_util.h │ ├── procinfo.c │ ├── procinfo.h │ ├── procman.c │ ├── procman.h │ ├── procman_deputy.c │ ├── signal_pipe.c │ └── signal_pipe.h ├── bot2-vis ├── CMakeLists.txt ├── Makefile ├── README ├── bot-ppmsgz ├── cmake │ └── pods.cmake └── src │ ├── bot_vis │ ├── CMakeLists.txt │ ├── batch_gl.c │ ├── batch_gl.h │ ├── bot_vis.h │ ├── console.c │ ├── console.h │ ├── default_view_handler.c │ ├── default_view_handler.h │ ├── fbgl_drawing_area.c │ ├── fbgl_drawing_area.h │ ├── gl_drawing_area.c │ ├── gl_drawing_area.h │ ├── gl_image_area.c │ ├── gl_image_area.h │ ├── gl_util.c │ ├── gl_util.h │ ├── glm.c │ ├── glm.h │ ├── glm_util.c │ ├── glmimg.c │ ├── glmimg_jpg.c │ ├── glmimg_png.c │ ├── glmint.h │ ├── gtk_util.c │ ├── gtk_util.h │ ├── param_widget.c │ ├── param_widget.h │ ├── rwx.c │ ├── rwx.h │ ├── scrollplot2d.c │ ├── scrollplot2d.h │ ├── stock_renderer_grid.c │ ├── texture.c │ ├── texture.h │ ├── tokenize.c │ ├── tokenize.h │ ├── view.c │ ├── view.h │ ├── viewer.c │ ├── viewer.h │ ├── wavefront.c │ └── wavefront.h │ ├── rwx-viewer │ ├── CMakeLists.txt │ ├── main.c │ └── renderer_rwx.c │ ├── testers │ ├── CMakeLists.txt │ ├── gl_drawing_area_tester.c │ ├── gl_image_area_tester.c │ └── param_widget_tester.c │ └── wavefront-viewer │ ├── CMakeLists.txt │ ├── main.c │ └── renderer_wavefront.c ├── doc └── Doxyfile ├── install_prereqs.sh └── tobuild.txt /.gitignore: -------------------------------------------------------------------------------- 1 | */lcmtypes/c 2 | */lcmtypes/cpp 3 | */lcmtypes/java/* 4 | */lcmtypes/python/* 5 | */pod-build 6 | bot2-lcmgl/java/src/bot_lcmgl/data_t.java 7 | bot2-lcmgl/python/src/bot_lcmgl/data_t.py 8 | bot2-procman/python/src/bot_procman/build_prefix.py 9 | pod-build 10 | bot2-lcmgl/python/src/bot_lcmgl/__init__.py 11 | bot2-procman/python/src/bot_procman/__init__.py 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | # support only a few flags that might be passed through: 3 | # BUILD_PREFIX, BUILD_TYPE, CMAKE_FLAGS* 4 | CMAKE_FLAGS+=$(strip $(CMAKE_FLAGS1) $(CMAKE_FLAGS2) $(CMAKE_FLAGS3) $(CMAKE_FLAGS4) $(CMAKE_FLAGS5) $(CMAKE_FLAGS6) $(CMAKE_FLAGS7) $(CMAKE_FLAGS8) $(CMAKE_FLAGS9) $(CMAKE_FLAGS10) $(CMAKE_FLAGS11) $(CMAKE_FLAGS12) $(CMAKE_FLAGS13) $(CMAKE_FLAGS14) $(CMAKE_FLAGS15) $(CMAKE_FLAGS16) $(CMAKE_FLAGS17) $(CMAKE_FLAGS18) $(CMAKE_FLAGS19) $(CMAKE_FLAGS20)) 5 | ifneq "$(BUILD_PREFIX)" "" 6 | CMAKE_FLAGS+=-DCMAKE_INSTALL_PREFIX="$(BUILD_PREFIX)" 7 | endif 8 | ifeq "$(BUILD_TYPE)" "" 9 | BUILD_TYPE="Release" 10 | endif 11 | CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) 12 | CMAKE_CONFIG=--config $(BUILD_TYPE) 13 | 14 | .PHONY: all 15 | all: configure 16 | cmake --build pod-build $(CMAKE_CONFIG) --target all 17 | 18 | pod-build: 19 | cmake -E make_directory pod-build 20 | 21 | .PHONY: configure 22 | configure: pod-build 23 | @echo Configuring with CMAKE_FLAGS: $(CMAKE_FLAGS) 24 | @cd pod-build && cmake $(CMAKE_FLAGS) .. 25 | 26 | .PHONY: options 27 | options: configure 28 | ifeq ($(OS),Windows_NT) 29 | cmake-gui pod-build 30 | else 31 | ccmake pod-build 32 | endif 33 | 34 | .PHONY: clean 35 | clean: 36 | cmake --build pod-build --target clean 37 | cmake -E remove_directory pod-build 38 | cmake -E remove_directory build 39 | 40 | # other (custom) targets are passed through to the cmake-generated Makefile 41 | %:: 42 | cmake --build pod-build $(CMAKE_CONFIG) --target $@ 43 | 44 | # Default to a less-verbose build. If you want all the gory compiler output, 45 | # run "make VERBOSE=1" 46 | $(VERBOSE).SILENT: 47 | 48 | 49 | ### rules specific to this project (everything above is the generic pods makefile wrapper of a cmake project) 50 | -------------------------------------------------------------------------------- /bot2-core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6.0) 2 | 3 | set(POD_NAME bot2-core) 4 | 5 | include(cmake/pods.cmake) 6 | 7 | include(cmake/lcmtypes.cmake) 8 | lcmtypes_build(C_AGGREGATE_HEADER bot_core.h CPP_AGGREGATE_HEADER bot_core.hpp) 9 | 10 | add_subdirectory(src/bot_core) 11 | add_subdirectory(java) 12 | -------------------------------------------------------------------------------- /bot2-core/Makefile: -------------------------------------------------------------------------------- 1 | # Default pod makefile distributed with pods version: 12.09.21 2 | 3 | default_target: all 4 | 5 | # Default to a less-verbose build. If you want all the gory compiler output, 6 | # run "make VERBOSE=1" 7 | $(VERBOSE).SILENT: 8 | 9 | # Figure out where to build the software. 10 | # Use BUILD_PREFIX if it was passed in. 11 | # If not, search up to four parent directories for a 'build' directory. 12 | # Otherwise, use ./build. 13 | ifeq "$(BUILD_PREFIX)" "" 14 | BUILD_PREFIX:=$(shell for pfx in ./ .. ../.. ../../.. ../../../..; do d=`pwd`/$$pfx/build;\ 15 | if [ -d $$d ]; then echo $$d; exit 0; fi; done; echo `pwd`/build) 16 | endif 17 | # create the build directory if needed, and normalize its path name 18 | BUILD_PREFIX:=$(shell mkdir -p $(BUILD_PREFIX) && cd $(BUILD_PREFIX) && echo `pwd`) 19 | 20 | # Default to a release build. If you want to enable debugging flags, run 21 | # "make BUILD_TYPE=Debug" 22 | ifeq "$(BUILD_TYPE)" "" 23 | BUILD_TYPE="Release" 24 | endif 25 | 26 | all: pod-build/Makefile 27 | $(MAKE) -C pod-build all install 28 | 29 | pod-build/Makefile: 30 | $(MAKE) configure 31 | 32 | .PHONY: configure 33 | configure: 34 | @echo "\nBUILD_PREFIX: $(BUILD_PREFIX)\n\n" 35 | 36 | # create the temporary build directory if needed 37 | @mkdir -p pod-build 38 | 39 | # run CMake to generate and configure the build scripts 40 | @cd pod-build && cmake -DCMAKE_INSTALL_PREFIX=$(BUILD_PREFIX) \ 41 | -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) .. 42 | 43 | clean: 44 | -if [ -e pod-build/install_manifest.txt ]; then rm -f `cat pod-build/install_manifest.txt`; fi 45 | -if [ -d pod-build ]; then $(MAKE) -C pod-build clean; rm -rf pod-build; fi 46 | 47 | # other (custom) targets are passed through to the cmake-generated Makefile 48 | %:: 49 | $(MAKE) -C pod-build $@ -------------------------------------------------------------------------------- /bot2-core/README: -------------------------------------------------------------------------------- 1 | This software is constructed according to the Pods software policies and 2 | templates. The policies and templates can be found at: 3 | 4 | http://sourceforge.net/projects/pods 5 | 6 | ==== 7 | 8 | Name: bot2-core 9 | Maintainers: 10 | Summary: A library of handy functions and data structures, and some LCM types. 11 | Description: 12 | bot2-core provides a number of functions and data structures that are 13 | useful to a variety of robotics platforms. 14 | 15 | Requirements: 16 | GLib (>= 2.0) 17 | LCM (http://lcm.googlecode.com) 18 | -------------------------------------------------------------------------------- /bot2-core/java/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Java) 2 | if(JAVA_COMPILE STREQUAL JAVA_COMPILE-NOTFOUND OR 3 | JAVA_ARCHIVE STREQUAL JAVA_ARCHIVE-NOTFOUND OR 4 | JAVA_COMPILE STREQUAL Java_JAVAC_EXECUTABLE-NOTFOUND OR 5 | JAVA_ARCHIVE STREQUAL Java_JAR_EXECUTABLE-NOTFOUND) 6 | message(STATUS "Not building Java LCM-SPY plugins (Can't find Java)") 7 | return() 8 | endif() 9 | 10 | message(STATUS "Found java, building Java LCM-SPY plugins") 11 | message(STATUS "JAVA_COMPILE: ${JAVA_COMPILE}") 12 | message(STATUS "JAVA_ARCHIVE: ${JAVA_ARCHIVE}") 13 | message(STATUS "Found java, building Java LCM-SPY plugins") 14 | 15 | set(src_dir ${CMAKE_CURRENT_SOURCE_DIR}/src) 16 | set(jar_fname lcmspy_plugins_bot2.jar) 17 | 18 | # where is lcm.jar? 19 | execute_process(COMMAND pkg-config --variable=classpath lcm-java OUTPUT_VARIABLE LCM_JAR) 20 | if (NOT LCM_JAR) 21 | message(STATUS "\n\n----- ERROR: lcm-java not found. Not building bot-spy plugins") 22 | return() 23 | endif() 24 | 25 | string(STRIP ${LCM_JAR} LCM_JAR) 26 | 27 | # where is lcmtypes_bot2-core.jar? 28 | #set(bot2_core_jar ${CMAKE_INSTALL_PREFIX}/share/java/lcmtypes_bot2-core.jar) 29 | 30 | set(classpath ${src_dir}:${LCM_JAR}:${LCMTYPES_JAR}) 31 | 32 | 33 | # ============= 34 | 35 | # get a list of all .java files 36 | file(GLOB_RECURSE java_files ${src_dir}/*.java) 37 | 38 | # where do we build .class files to? 39 | set(class_dir ${CMAKE_CURRENT_BINARY_DIR}/java-build) 40 | 41 | # convert the list of .java filenames to a list of .class filenames 42 | foreach(javafile ${java_files}) 43 | string(REPLACE .java .class tmp_fname ${javafile}) 44 | string(REPLACE ${src_dir} ${class_dir} tmp_fname ${tmp_fname}) 45 | list(APPEND class_files ${tmp_fname}) 46 | endforeach() 47 | 48 | # create the java build directory if needed 49 | if(NOT IS_DIRECTORY ${class_dir}) 50 | file(MAKE_DIRECTORY ${class_dir}) 51 | endif() 52 | 53 | # add a rule to build the .class files from from the .java files 54 | add_custom_command(OUTPUT ${class_files} COMMAND 55 | ${JAVA_COMPILE} -source 6 -target 6 -cp ${classpath} -d ${class_dir} ${java_files} 56 | DEPENDS ${java_files} ${LCMTYPES_JAR}) 57 | 58 | # add a rule to build a .jar file from the .class files 59 | add_custom_command(OUTPUT ${jar_fname} COMMAND 60 | ${JAVA_ARCHIVE} cf ${jar_fname} -C ${class_dir} . 61 | DEPENDS ${class_files}) 62 | add_custom_target(jar ALL DEPENDS ${jar_fname}) 63 | add_dependencies(jar lcmtypes_${POD_NAME}_jar) #the jar depends on the lcmtypes being already built. 64 | 65 | 66 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${jar_fname} DESTINATION share/java) 67 | -------------------------------------------------------------------------------- /bot2-core/lcmtypes/bot_core_image_metadata_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_core; 2 | 3 | struct image_metadata_t { 4 | string key; 5 | int32_t n; 6 | byte value[n]; 7 | } 8 | -------------------------------------------------------------------------------- /bot2-core/lcmtypes/bot_core_image_sync_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_core; 2 | 3 | // image_sync_t is used by libcam plugins to synchronize playback of a libcam 4 | // log file with playback of an LCM log file. 5 | // 6 | // The expected usage scenario is when an image stream is recorded to a libcam 7 | // log file, and a lcm-syncpub unit is in the libcam chain that publishes 8 | // image_sync_t messages to an LCM network, where they may be logged to the 9 | // an LCM logfile. 10 | // 11 | // Later, when playing back an LCM log file, the image_sync_t messages can be 12 | // used by a libcam log playback unit to synchronize its playback of the 13 | // libcam log file with the LCM log file. 14 | // 15 | // The existence of this message type is largely predicated on the notion that 16 | // we may not always want full resolution image data in an LCM log file, and 17 | // may instead store it in a dedicated libcam log file. 18 | 19 | struct image_sync_t 20 | { 21 | int64_t utime; 22 | } 23 | -------------------------------------------------------------------------------- /bot2-core/lcmtypes/bot_core_planar_lidar_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_core; 2 | 3 | struct planar_lidar_t 4 | { 5 | int64_t utime; 6 | 7 | // range data (meters) 8 | int32_t nranges; 9 | float ranges[nranges]; 10 | 11 | // intensity data, in sensor-specific units 12 | int32_t nintensities; 13 | float intensities[nintensities]; 14 | 15 | // the angle (in radians) to the first point in nranges, 16 | // relative to the laser scanner's own coordinate frame. 17 | float rad0; 18 | 19 | // the number of radians between each successive sample 20 | float radstep; 21 | } 22 | -------------------------------------------------------------------------------- /bot2-core/lcmtypes/bot_core_pose_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_core; 2 | 3 | struct pose_t 4 | { 5 | int64_t utime; // utime that the actual measurement took place 6 | 7 | double pos[3]; // position x,y,z in meters in local frame 8 | double vel[3]; // velocity in m/s, expressed in local frame, 9 | // _NOT_ body frame 10 | 11 | double orientation[4]; // rotate vector in body coordinate frame 12 | // (X-forward, Z-up) by this to get that vector 13 | // in local frame 14 | 15 | double rotation_rate[3]; // angular velocity vector of the vehicle 16 | // in rad/s. This is expressed in the local 17 | // frame. 18 | 19 | double accel[3]; // Acceleration vector in the local frame in 20 | // m/s/s. Does not include the gravity vector. 21 | } 22 | -------------------------------------------------------------------------------- /bot2-core/lcmtypes/bot_core_raw_t.lcm: -------------------------------------------------------------------------------- 1 | // The raw_t message encapsulates opaque binary data. Expected use cases 2 | // are to transmit raw sensor data via LCM. 3 | 4 | package bot_core; 5 | 6 | struct raw_t 7 | { 8 | int64_t utime; 9 | 10 | int32_t length; 11 | byte data[length]; 12 | } 13 | -------------------------------------------------------------------------------- /bot2-core/lcmtypes/bot_core_rigid_transform_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_core; 2 | 3 | struct rigid_transform_t 4 | { 5 | int64_t utime; // utime that the actual measurement took place 6 | 7 | double trans[3]; // translation vector component (x,y,z) 8 | 9 | double quat[4]; // rotation quaternion component (w,x,y,z) 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /bot2-core/lcmtypes/bot_core_sensor_status_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_core; 2 | 3 | struct sensor_status_t 4 | { 5 | int64_t utime; 6 | string sensor_name; 7 | double rate; 8 | int16_t type; 9 | const int16_t VELODYNE_32 = 0; 10 | const int16_t VELODYNE_64 = 1; 11 | const int16_t SICK_LASER = 2; 12 | const int16_t HOKUYO_LASER = 3; 13 | const int16_t KINECT = 4; 14 | const int16_t IMU = 5; 15 | const int16_t ORC = 6; 16 | const int16_t DYNAMIXEL_SERVO = 7; 17 | } -------------------------------------------------------------------------------- /bot2-core/src/bot_core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | file(GLOB c_files *.c) 4 | file(GLOB h_files *.h) 5 | 6 | add_library(bot2-core SHARED ${c_files}) 7 | 8 | # set the library API version. Increment this every time the public API 9 | # changes. 10 | set_target_properties(bot2-core PROPERTIES SOVERSION 1) 11 | 12 | set(REQUIRED_LIBS glib-2.0 lcm) 13 | pods_use_pkg_config_packages(bot2-core ${REQUIRED_LIBS}) 14 | target_link_libraries(bot2-core m lcmtypes_bot2-core) 15 | list(APPEND REQUIRED_LIBS lcmtypes_bot2-core) 16 | 17 | pods_install_libraries(bot2-core) 18 | 19 | pods_install_headers(${h_files} DESTINATION bot_core) 20 | 21 | pods_install_pkg_config_file(${PROJECT_NAME} 22 | LIBS -lbot2-core -lm 23 | REQUIRES ${REQUIRED_LIBS} 24 | VERSION 0.0.1) 25 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/bot_core.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot2_core_h__ 2 | #define __bot2_core_h__ 3 | 4 | #include "math_util.h" 5 | #include "small_linalg.h" 6 | #include "camtrans.h" 7 | #include "circular.h" 8 | #include "ctrans.h" 9 | #include "fasttrig.h" 10 | #include "fileutils.h" 11 | #include "glib_util.h" 12 | #include "gps_linearize.h" 13 | #include "lcm_util.h" 14 | #include "minheap.h" 15 | #include "ppm.h" 16 | #include "ptr_circular.h" 17 | #include "rotations.h" 18 | #include "serial.h" 19 | #include "set.h" 20 | #include "signal_pipe.h" 21 | #include "ssocket.h" 22 | #include "tictoc.h" 23 | #include "timespec.h" 24 | #include "timestamp.h" 25 | #include "trans.h" 26 | #include "color_util.h" 27 | #include "rand_util.h" 28 | #include "ringbuf.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | /** 38 | * @defgroup BotCore Bot Core 39 | * @brief Core data structures and functions 40 | */ 41 | 42 | /** 43 | * @defgroup BotCoreMathGeom Math / Geometry 44 | * @ingroup BotCore 45 | * @brief Functions and data structures for math and geometry 46 | */ 47 | 48 | /** 49 | * @defgroup BotCoreDataStructures Data Structures 50 | * @ingroup BotCore 51 | * @brief General purpose data structures 52 | */ 53 | 54 | /** 55 | * @defgroup BotCoreIO I/O 56 | * @ingroup BotCore 57 | * @brief I/O routines (files, sockets, etc.) and reading/writing certain file formats. 58 | */ 59 | 60 | /** 61 | * @defgroup BotCoreTime Time 62 | * @ingroup BotCore 63 | * @brief Time keeping 64 | */ 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/circular.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "circular.h" 6 | 7 | BotCircular * 8 | bot_circular_new (int capacity, int element_size) 9 | { 10 | BotCircular * circular = malloc (sizeof (BotCircular)); 11 | if (!circular) 12 | return NULL; 13 | memset (circular, 0, sizeof (BotCircular)); 14 | 15 | circular->array = calloc (capacity, element_size); 16 | if (!circular->array) { 17 | free (circular); 18 | return NULL; 19 | } 20 | circular->capacity = capacity; 21 | circular->element_size = element_size; 22 | return circular; 23 | } 24 | 25 | void 26 | bot_circular_free (BotCircular * circular) 27 | { 28 | free (circular->array); 29 | memset (circular, 0, sizeof (BotCircular)); 30 | free (circular); 31 | } 32 | 33 | void 34 | bot_circular_clear (BotCircular * circular) 35 | { 36 | circular->head = 0; 37 | circular->len = 0; 38 | } 39 | 40 | int 41 | bot_circular_push_head (BotCircular * circular, const void * data) 42 | { 43 | circular->head--; 44 | if (circular->head < 0) 45 | circular->head = circular->capacity - 1; 46 | 47 | if (circular->len < circular->capacity) 48 | circular->len++; 49 | 50 | memcpy (bot_circular_peek_nth (circular, 0), data, circular->element_size); 51 | 52 | return 0; 53 | } 54 | 55 | int 56 | bot_circular_pop_tail (BotCircular * circular, void * data) 57 | { 58 | if (bot_circular_is_empty (circular)) 59 | return -1; 60 | 61 | if (data) 62 | memcpy (data, bot_circular_peek_nth (circular, circular->len - 1), 63 | circular->element_size); 64 | 65 | circular->len--; 66 | 67 | return 0; 68 | } 69 | 70 | int 71 | bot_circular_pop_head (BotCircular * circular, void * data) 72 | { 73 | if (bot_circular_is_empty (circular)) 74 | return -1; 75 | 76 | if (data) 77 | memcpy (data, bot_circular_peek_nth (circular, 0), 78 | circular->element_size); 79 | 80 | circular->len--; 81 | circular->head = (circular->head + 1) % circular->capacity; 82 | 83 | return 0; 84 | } 85 | 86 | int 87 | bot_circular_size(BotCircular *circular) 88 | { 89 | return circular->len; 90 | } 91 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/circular.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_circular_h__ 2 | #define __bot_circular_h__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /** 9 | * @defgroup BotCoreCircular Circular Array 10 | * @brief Fixed-capacity circular array 11 | * @ingroup BotCoreDataStructures 12 | * @include: bot_core/bot_core.h 13 | * 14 | * BotCircular is a hybrid of the glib types GArray and GQueue. BotCircular 15 | * acts like a GQueue in the sense that you can push on one end and pop 16 | * from the other. It acts like a GArray in the sense that its contents 17 | * are statically allocated rather than pointers to user-allocated buffers. 18 | * For this reason, its size is fixed and allocated when the BotCircular 19 | * is created (TODO: set_size function). If a new element is pushed 20 | * when the BotCircular is already full, the last element on the tail is 21 | * automatically overwritten. 22 | * 23 | * Linking: `pkg-config --libs bot2-core` 24 | * 25 | * @{ 26 | */ 27 | typedef struct _BotCircular BotCircular; 28 | 29 | struct _BotCircular { 30 | int len; 31 | int capacity; 32 | int element_size; 33 | int head; 34 | void * array; 35 | }; 36 | 37 | BotCircular * 38 | bot_circular_new (int capacity, int element_size); 39 | void 40 | bot_circular_free (BotCircular * circular); 41 | void 42 | bot_circular_clear (BotCircular * circular); 43 | int 44 | bot_circular_push_head (BotCircular * circular, const void * data); 45 | int 46 | bot_circular_pop_tail (BotCircular * circular, void * data); 47 | int 48 | bot_circular_pop_head (BotCircular * circular, void * data); 49 | 50 | /** 51 | * bot_circular_size: 52 | * Returns: the number of valid elements. 53 | */ 54 | int bot_circular_size(BotCircular *circular); 55 | 56 | #define bot_circular_is_empty(a) ((a)->len == 0) 57 | 58 | #define bot_circular_is_full(a) ((a)->len >= (a)->capacity) 59 | 60 | #define bot_circular_peek_nth(a,i) \ 61 | ((void*)((char*)(a)->array + (((a)->head + (i)) % (a)->capacity) * (a)->element_size)) 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/color_util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "color_util.h" 6 | 7 | // random number between [0, 1) 8 | static inline float _randf() 9 | { 10 | return ((float) rand()) / (RAND_MAX + 1.0); 11 | } 12 | 13 | 14 | void bot_color_util_rand_color(float f[4], double alpha, double min_intensity) 15 | { 16 | f[3] = alpha; 17 | 18 | again: 19 | f[0] = _randf(); 20 | f[1] = _randf(); 21 | f[2] = _randf(); 22 | 23 | float v = f[0] + f[1] + f[2]; 24 | 25 | // reject colors that are too dark 26 | if (v < min_intensity) 27 | goto again; 28 | } 29 | 30 | /** Given an array of colors, a palette is created that linearly interpolates through all the colors. **/ 31 | static void color_util_build_color_table(double color_palette[][3], int palette_size, float lut[][3], int lut_size) 32 | { 33 | for (int idx = 0; idx < lut_size; idx++) { 34 | double znorm = ((double) idx) / lut_size; 35 | 36 | int color_index = (palette_size - 1) * znorm; 37 | double alpha = (palette_size - 1) * znorm - color_index; 38 | 39 | for (int i = 0; i < 3; i++) { 40 | lut[idx][i] = color_palette[color_index][i] * (1.0 - alpha) + color_palette[color_index+1][i]*alpha; 41 | } 42 | } 43 | } 44 | 45 | #define JET_COLORS_LUT_SIZE 1024 46 | static float jet_colors[JET_COLORS_LUT_SIZE][3]; 47 | static int jet_colors_initialized = 0; 48 | 49 | static void init_color_table_jet() 50 | { 51 | double jet[][3] = {{ 0, 0, 1 }, 52 | { 0, .5, .5 }, 53 | { .8, .8, 0 }, 54 | { 1, 0, 0 }}; 55 | 56 | color_util_build_color_table(jet, sizeof(jet)/(sizeof(double)*3), jet_colors, JET_COLORS_LUT_SIZE); 57 | jet_colors_initialized = 1; 58 | } 59 | 60 | float *bot_color_util_jet(double v) 61 | { 62 | if (!jet_colors_initialized) 63 | init_color_table_jet(); 64 | 65 | v = fmax(0, v); 66 | v = fmin(1, v); 67 | 68 | int idx = (JET_COLORS_LUT_SIZE - 1) * v; 69 | return jet_colors[idx]; 70 | } 71 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/color_util.h: -------------------------------------------------------------------------------- 1 | #ifndef BOT_COLOR_UTIL 2 | #define BOT_COLOR_UTIL 3 | /** 4 | * @defgroup BotColorUtil Color Utilities 5 | * @brief utilities for making color schemes 6 | * @include: bot_core/bot_core.h 7 | * 8 | * Linking: `pkg-config --libs bot2-core` 9 | * 10 | * @{ 11 | */ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | /* 18 | * Get a random color 19 | */ 20 | void bot_color_util_rand_color(float f[4], double alpha, double min_intensity); 21 | 22 | /* 23 | * Get the color in the JET color space associated with value v [0,1] 24 | */ 25 | float *bot_color_util_jet(double v); 26 | 27 | 28 | /* 29 | * convenience arrays for commonly used colors 30 | */ 31 | static const float bot_color_util_red[3] = {1,0,0}; 32 | static const float bot_color_util_green[3] = {0,1,0}; 33 | static const float bot_color_util_blue[3] = {0,0,1}; 34 | static const float bot_color_util_cyan[3] = {0,1,1}; 35 | static const float bot_color_util_magenta[3] = {1,0,1}; 36 | static const float bot_color_util_yellow[3] = {1,1,0}; 37 | static const float bot_color_util_black[3] = {0,0,0}; 38 | static const float bot_color_util_white[3] = {1,1,1}; 39 | 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | /** 46 | * @} 47 | */ 48 | #endif 49 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/fasttrig.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_fasttrig_h__ 2 | #define __bot_fasttrig_h__ 3 | 4 | /** 5 | * @defgroup BotCoreFastTrig Fast Trigonometry 6 | * @ingroup BotCoreMathGeom 7 | * @brief Very fast, but approximate trigonometry 8 | * @include: bot_core/bot_core.h 9 | * 10 | * Linking: `pkg-config --libs bot2-core` 11 | * 12 | * @{ 13 | */ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | void bot_fasttrig_init(void); 20 | void bot_fasttrig_sincos(double theta, double *s, double *c); 21 | double bot_fasttrig_atan2(double y, double x); 22 | 23 | /** 24 | * @} 25 | */ 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/fileutils.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_fileutils_h__ 2 | #define __bot_fileutils_h__ 3 | 4 | #include 5 | 6 | /** 7 | * @defgroup BotCoreFileUtils File Utilities 8 | * @brief Convenience functions for reading/writing files 9 | * @ingroup BotCoreIO 10 | * @include: bot_core/bot_core.h 11 | * 12 | * Linking: `pkg-config --libs bot2-core` 13 | * 14 | * @{ 15 | */ 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /** 22 | * bot_fileutils_get_unique_filename: 23 | * 24 | * Returns an unused filename that can be used for writing without fear 25 | * of overwriting another file. The returned string must be freed with 26 | * free() when no longer needed. The new file is not opened. The 27 | * filename is constructed as path/[date-]basename.XX.extension where 28 | * XX is an integer chosen to make it unique. date- is only included 29 | * if @time_prefix is 1. 30 | * 31 | * @path: The path to the directory where the file should be stored. 32 | * Pass NULL to use the current working directory or if the path 33 | * is already included in @basename. 34 | * @basename: The desired name of the file without any trailing extension. 35 | * This may include a leading path, but only if @time_prefix is zero. 36 | * @time_prefix: Set to 1 if the basename should be prefixed with the 37 | * current date in the format YYYY-MM-DD-. 38 | * @extension: Filename extension to be used. Use NULL if no extension 39 | * is desired. 40 | */ 41 | char * 42 | bot_fileutils_get_unique_filename (const char * path, const char * basename, 43 | uint8_t time_prefix, const char * extension); 44 | 45 | int bot_fileutils_write_fully(int fd, const void *b, int len); 46 | int bot_fileutils_read_fully(int fd, void *b, int len); 47 | int bot_fileutils_read_timeout(int fd, void *buf, int maxlen, int msTimeout); 48 | int bot_fileutils_read_fully_timeout(int fd, void *bufin, int len, int msTimeout); 49 | int bot_fileutils_read_line_timeout(int fd, void *buf, int maxlen, int msTimeout); 50 | int bot_fileutils_read_line_timeout_ex(int fd, void *buf_in, int maxlen, int msTimeout, int *timed_out); 51 | int bot_fileutils_read_available(int fd); 52 | void bot_fileutils_read_flush(int fd); 53 | 54 | int bot_fileutils_fwrite32(FILE *f, int32_t v); 55 | int bot_fileutils_fwrite64(FILE *f, int64_t v64); 56 | int bot_fileutils_fread32(FILE *f, int32_t *v32); 57 | int bot_fileutils_fread64(FILE *f, int64_t *v64); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/glib_util.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_glib_util_h__ 2 | #define __bot_glib_util_h__ 3 | 4 | #include 5 | 6 | /** 7 | * SECTION:glib_util 8 | * @title:GLib Utilities 9 | * @short_description: useful functions missing from GLib 10 | * @include: bot_core/bot_core.h 11 | * 12 | * Linking: `pkg-config --libs bot2-core` 13 | */ 14 | 15 | #include 16 | //#include "gu_circular.h" 17 | //#include "gu_ptr_circular.h" 18 | //#include "gu_minheap.h" 19 | //#include "gu_set.h" 20 | //#include "gu_disjoint_set_forest.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | // calls func on every element of the specified list, and then 27 | // frees the list 28 | void bot_g_list_free_with_func (GList *list, GDestroyNotify func); 29 | 30 | // calls func on every element of the specified queue, and then 31 | // frees the queue 32 | void bot_g_queue_free_with_func (GQueue *queue, GDestroyNotify func); 33 | 34 | // calls func on every element of the specified pointer array, and then 35 | // frees the pointer array. 36 | void bot_g_ptr_array_free_with_func (GPtrArray *a, GDestroyNotify func); 37 | 38 | // creates a newly allocated copy of a GPtrArray 39 | GPtrArray * bot_g_ptr_array_new_copy (const GPtrArray *a); 40 | 41 | /** 42 | * Returns: 1 if time1 is after time2 43 | * 0 if time1 and time2 are equal 44 | * -1 if time1 is before time2 45 | */ 46 | int bot_g_time_val_compare (const GTimeVal *time1, const GTimeVal *time2); 47 | 48 | GList * bot_g_hash_table_get_keys (GHashTable *hash_table); 49 | 50 | GList * bot_g_hash_table_get_vals (GHashTable *hash_table); 51 | 52 | GPtrArray * bot_g_hash_table_get_vals_array (GHashTable *hash_table); 53 | 54 | #ifndef bot_g_ptr_array_size 55 | #define bot_g_ptr_array_size(ptrarray) ((ptrarray)->len) 56 | #endif 57 | 58 | // 59 | //#ifndef g_ptr_array_set 60 | //#define g_ptr_array_set(ptrarray, idx, val) (ptrarray)->pdata[(idx)] = (val); 61 | //#endif 62 | // 63 | int bot_g_ptr_array_find_index(GPtrArray *a, gconstpointer v); 64 | //#define gu_ptr_array_find_index g_ptr_array_find_index 65 | // 66 | guint bot_pint64_hash(gconstpointer _key); 67 | gboolean bot_pint64_equal(gconstpointer _a, gconstpointer _b); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/gps_linearize.c: -------------------------------------------------------------------------------- 1 | /* gps_linearize.c: 2 | * 3 | * Functions for projecting GPS coordinates into a planar coordinate system 4 | * centered at a particular GPS point. This is suitable for geometry 5 | * computations using GPS in local neighborhoods of a few kilometers. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "gps_linearize.h" 13 | 14 | #define REQ 6378135.0 15 | #define RPO 6356750.0 16 | 17 | /* Useful links: 18 | http://www.movable-type.co.uk/scripts/LatLongVincenty.html 19 | http://en.wikipedia.org/wiki/Earth_radius 20 | */ 21 | 22 | #define TO_RAD(x) ((x)*M_PI/180.0) 23 | #define TO_DEG(x) ((x)*180.0/M_PI) 24 | #define SQ(x) ((x)*(x)) 25 | 26 | void bot_gps_linearize_init(BotGPSLinearize *gl, const double ll_deg[2]) 27 | { 28 | gl->lat0_deg = ll_deg[0]; 29 | gl->lon0_deg = ll_deg[1]; 30 | 31 | double lat_rad = TO_RAD(ll_deg[0]); 32 | 33 | // this is the best radius approximation, agnostic of direction 34 | // we don't use this anymore. 35 | // gl->radius = REQ*REQ*RPO / (SQ(REQ*cos(lat_rad)) + SQ(RPO*sin(lat_rad))); 36 | 37 | // best radius approximation in ns and ew direction. 38 | gl->radius_ns = SQ(REQ*RPO) / pow((SQ(REQ*cos(lat_rad))) + SQ(RPO*sin(lat_rad)), 1.5); 39 | gl->radius_ew = REQ*REQ / sqrt(SQ(REQ*cos(lat_rad)) + SQ(RPO*sin(lat_rad))); 40 | } 41 | 42 | int bot_gps_linearize_to_xy(BotGPSLinearize *gl, const double ll_deg[2], double xy[2]) 43 | { 44 | double dlat = TO_RAD(ll_deg[0] - gl->lat0_deg); 45 | double dlon = TO_RAD(ll_deg[1] - gl->lon0_deg); 46 | 47 | xy[0] = sin(dlon) * gl->radius_ew * cos(TO_RAD(gl->lat0_deg)); 48 | xy[1] = sin(dlat) * gl->radius_ns; 49 | 50 | return 0; 51 | } 52 | 53 | int bot_gps_linearize_to_lat_lon(BotGPSLinearize *gl, const double xy[2], double ll_deg[2]) 54 | { 55 | double dlat = asin(xy[1] / gl->radius_ns); 56 | ll_deg[0] = TO_DEG(dlat) + gl->lat0_deg; 57 | 58 | double dlon = asin(xy[0] / gl->radius_ew / cos(TO_RAD(gl->lat0_deg))); 59 | ll_deg[1] = TO_DEG(dlon) + gl->lon0_deg; 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/gps_linearize.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_gps_linearize_h__ 2 | #define __bot_gps_linearize_h__ 3 | 4 | /** 5 | * @defgroup BotCoreGPSLinearize GPS Linearization 6 | * @ingroup BotCoreMathGeom 7 | * @brief Linearizing GPS coordinates 8 | * @include: bot_core/bot_core.h 9 | * 10 | * Linking: `pkg-config --libs bot2-core` 11 | * 12 | * @{ 13 | */ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct _BotGPSLinearize BotGPSLinearize; 20 | struct _BotGPSLinearize 21 | { 22 | double lon0_deg, lat0_deg; 23 | double radius_ns, radius_ew; 24 | }; 25 | 26 | void bot_gps_linearize_init(BotGPSLinearize *gl, const double ll_deg[2]); 27 | int bot_gps_linearize_to_xy(BotGPSLinearize *gl, const double ll_deg[2], double xy[2]); 28 | int bot_gps_linearize_to_lat_lon(BotGPSLinearize *gl, const double xy[2], double ll_deg[2]); 29 | 30 | /** 31 | * @} 32 | */ 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/math_util.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_mathutil_h__ 2 | #define __bot_mathutil_h__ 3 | 4 | /** 5 | * @defgroup BotCoreMathUtil Math Utilities 6 | * @ingroup BotCoreMathGeom 7 | * @brief Miscellaneous math utility functions 8 | * @include: bot_core/bot_core.h 9 | * 10 | * Linking: `pkg-config --libs bot2-core` 11 | * 12 | * @{ 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | 25 | /** valid only for v > 0 **/ 26 | static inline double bot_mod2pi_positive(double vin) 27 | { 28 | double q = vin / (2*M_PI) + 0.5; 29 | int qi = (int) q; 30 | 31 | return vin - qi*2*M_PI; 32 | } 33 | 34 | /** Map v to [-PI, PI] **/ 35 | static inline double bot_mod2pi(double vin) 36 | { 37 | if (vin < 0) 38 | return -bot_mod2pi_positive(-vin); 39 | else 40 | return bot_mod2pi_positive(vin); 41 | } 42 | 43 | /** Return vin such that it is within PI degrees of ref **/ 44 | static inline double bot_mod2pi_ref(double ref, double vin) 45 | { 46 | return ref + bot_mod2pi(vin - ref); 47 | } 48 | 49 | static inline int bot_theta_to_int(double theta, int max) 50 | { 51 | theta = bot_mod2pi_ref(M_PI, theta); 52 | int v = (int) (theta / ( 2 * M_PI ) * max); 53 | 54 | if (v==max) 55 | v = 0; 56 | 57 | assert (v >= 0 && v < max); 58 | 59 | return v; 60 | } 61 | 62 | /** Convenience function for systems without the sincos GNU extension **/ 63 | static inline void bot_sincos(double theta, double *s, double *c) 64 | { 65 | *s = sin(theta); 66 | *c = cos(theta); 67 | } 68 | 69 | #define bot_to_radians(deg) ((deg)*M_PI/180) 70 | 71 | #define bot_to_degrees(rad) ((rad)*180/M_PI) 72 | 73 | #define bot_sq(a) ((a)*(a)) 74 | 75 | #define bot_clamp(x,min,max) (x < min ? min : (x > max ? max : x)) 76 | 77 | #define bot_sgn(v)((v>=0) ? 1 : -1) 78 | 79 | #define bot_min(a,b)((a < b) ? a : b) 80 | #define bot_max(a,b)((a > b) ? a : b) 81 | 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/minheap.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_minheap_h__ 2 | #define __bot_minheap_h__ 3 | 4 | #include 5 | 6 | /** 7 | * @defgroup BotCoreMinHeap Minheap 8 | * @brief Heap data structure 9 | * @ingroup BotCoreDataStructures 10 | * @include: bot_core/bot_core.h 11 | * 12 | * Linking: `pkg-config --libs bot2-core` 13 | * 14 | * @{ 15 | */ 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | typedef struct _BotMinheap BotMinheap; 22 | typedef struct _BotMinheapNode BotMinheapNode; 23 | 24 | 25 | BotMinheap *bot_minheap_new(void); 26 | 27 | BotMinheap *bot_minheap_sized_new(int capacity); 28 | 29 | void bot_minheap_free(BotMinheap *mh); 30 | 31 | BotMinheapNode *bot_minheap_add (BotMinheap *mh, void *data, double score); 32 | 33 | void bot_minheap_decrease_score (BotMinheap *mh, BotMinheapNode *node, 34 | double score); 35 | 36 | void *bot_minheap_remove_min (BotMinheap *mh, double *score); 37 | 38 | int bot_minheap_size (BotMinheap *mh); 39 | 40 | gboolean bot_minheap_is_empty (BotMinheap *mh); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/ppm.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_ppm_h__ 2 | #define __bot_ppm_h__ 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * @defgroup BotCorePPM PPM/PGM 9 | * @brief Reading and writing PPM/PGM files 10 | * @ingroup BotCoreIO 11 | * @include: bot_core/bot_core.h 12 | * 13 | * TODO 14 | * 15 | * Linking: `pkg-config --libs bot2-core` 16 | * 17 | * @{ 18 | */ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | int bot_ppm_read (FILE *fp, uint8_t **pixels, 25 | int *width, int *height, int *rowstride); 26 | 27 | int bot_ppm_read_fname(const char* fname, uint8_t** pixels, 28 | int* width, int* height, int* rowstride); 29 | 30 | int bot_ppm_write (FILE *fp, const uint8_t *pixels, 31 | int width, int height, int rowstride); 32 | 33 | int bot_ppm_write_fname(const char* fname, const uint8_t* pixels, 34 | int width, int height, int rowstride); 35 | 36 | int bot_ppm_write_bottom_up (FILE *fp, uint8_t *pixels, 37 | int width, int height, int rowstride); 38 | 39 | int bot_pgm_read (FILE *fp, uint8_t **pixels, 40 | int *width, int *height, int *rowstride); 41 | 42 | int bot_pgm_read_fname(const char *fname, uint8_t **pixels, 43 | int *width, int *height, int *rowstrde); 44 | 45 | int bot_pgm_write (FILE *fp, const uint8_t *pixels, 46 | int width, int height, int rowstride); 47 | 48 | int bot_pgm_write_fname(const char *fname, const uint8_t * pixels, 49 | int width, int height, int rowstrde); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/ptr_circular.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_ptr_circular_h__ 2 | #define __bot_ptr_circular_h__ 3 | 4 | /** 5 | * @defgroup BotCorePtrCircular Circular Pointer Array 6 | * @brief Circular array of pointers 7 | * @ingroup BotCoreDataStructures 8 | * @include: bot_core/bot_core.h 9 | * 10 | * Linking: `pkg-config --libs bot2-core` 11 | * 12 | * @{ 13 | */ 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef void (*BotPtrCircularDestroy)(void *user, void *p); 20 | 21 | /** A circular Buffer, implemented with a PtrArray **/ 22 | typedef struct gcircular BotPtrCircular; 23 | struct gcircular 24 | { 25 | void **p; // storage 26 | unsigned int size; // number of valid elements in the buffer 27 | unsigned int next; // where the next add will go 28 | unsigned int capacity; // maximum allowed capacity 29 | 30 | void *user; 31 | BotPtrCircularDestroy handler; 32 | }; 33 | 34 | // create a new circular buffer; the destroy handler will be called 35 | // whenever an element is evicted. (NULL means no handler). 36 | BotPtrCircular *bot_ptr_circular_new(unsigned int capacity, BotPtrCircularDestroy handler, void *user); 37 | 38 | // call destroy() on any elements, then deallocate the circular buffer 39 | void bot_ptr_circular_destroy(BotPtrCircular *circ); 40 | 41 | // adds a new element to the buffer, possibly evicting the oldest 42 | void bot_ptr_circular_add(BotPtrCircular *circ, void *p); 43 | 44 | // return the number of valid elements in the buffer 45 | unsigned int bot_ptr_circular_size(BotPtrCircular *circ); 46 | 47 | // An index of zero corresponds to the most recently added item. 48 | void *bot_ptr_circular_index(BotPtrCircular *circ, unsigned int idx); 49 | 50 | // resize the circular buffer, freeing elements as required 51 | void bot_ptr_circular_resize(BotPtrCircular *circ, unsigned int capacity); 52 | 53 | // remove all elements from the buffer. 54 | void bot_ptr_circular_clear(BotPtrCircular *circ); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/rand_util.h: -------------------------------------------------------------------------------- 1 | #ifndef BOT_RAND_UTILS_H_ 2 | #define BOT_RAND_UTILS_H_ 3 | /** 4 | * @defgroup BotCoreRandUtil Rand Utilities 5 | * @ingroup BotCoreMathGeom 6 | * @brief Miscellaneous random number utility functions 7 | * @include: bot_core/bot_core.h 8 | * 9 | * Linking: `pkg-config --libs bot2-core` 10 | * 11 | * @{ 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /* random number between [0, 1) */ 24 | static inline float bot_randf() 25 | { 26 | return ((float) rand()) / (RAND_MAX + 1.0); 27 | } 28 | 29 | /* random number between (-1, 1) */ 30 | static inline float bot_signed_randf() 31 | { 32 | return bot_randf()*2.0 - 1.0; 33 | } 34 | /* random number between [mi, ma ] */ 35 | static inline float bot_randf_in_range(float mi, float ma) 36 | { 37 | return bot_randf()*(ma-mi) + mi; 38 | } 39 | 40 | 41 | /* return a random integer between [0, bound) */ 42 | static inline int bot_irand(int bound) 43 | { 44 | int v = (int) (bot_randf()*bound); 45 | assert(v >= 0); 46 | assert(v < bound); 47 | return v; 48 | } 49 | 50 | /*seed bot_gauss_rand (defaults to 13 if bot_gauss_rand() called before bot_gauss_rand_init()*/ 51 | void bot_gauss_rand_init(uint32_t seed); 52 | 53 | /*return a normally distributed random number */ 54 | double bot_gauss_rand(double mu, double sigma); 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* BOT_RAND_UTILS_H_ */ 65 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/ringbuf.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_ringbuf_h__ 2 | #define __bot_ringbuf_h__ 3 | #include 4 | 5 | /** 6 | * @defgroup BotCoreRingbuf A simple ring buffer 7 | * @brief A fixed capacity ring buffer 8 | * @ingroup BotCoreDataStructures 9 | * @include: bot_core/bot_core.h 10 | * 11 | * TODO 12 | * 13 | * Linking: `pkg-config --libs bot2-core` 14 | * 15 | * @{ 16 | */ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * 24 | * 25 | */ 26 | typedef struct _BotRingBuf BotRingBuf; 27 | 28 | /* 29 | * Create buffer, and allocate space for size bytes 30 | */ 31 | BotRingBuf * bot_ringbuf_create(int size); 32 | 33 | /* 34 | * Destroy it 35 | */ 36 | void bot_ringbuf_destroy(BotRingBuf * cbuf); 37 | 38 | /* 39 | * Copy numBytes from the head of the buffer, and move read pointers 40 | */ 41 | int bot_ringbuf_read(BotRingBuf * cbuf, int numBytes, uint8_t * buf); 42 | 43 | /* 44 | * Copy numBytes from buf to end of buffer 45 | */ 46 | int bot_ringbuf_write(BotRingBuf * cbuf, int numBytes, uint8_t * buf); 47 | 48 | 49 | /* 50 | * Fill the ringbuff with data from the file descriptor. 51 | * Either read numBytes from the fd, 52 | * or if numBytes<0, get all available bytes 53 | */ 54 | int bot_ringbuf_fill_from_fd(BotRingBuf * cbuf, int fd, int numBytes); 55 | 56 | 57 | /* 58 | * Copy numBytes from the head of the buffer, but DON'T move read pointers 59 | */ 60 | int bot_ringbuf_peek(BotRingBuf * cbuf, int numBytes, uint8_t * buf); //read numBytes from start of buffer, but don't move readPtr 61 | 62 | 63 | /** 64 | * Return a pointer to a contiguous buffer with the next numBytes of data to be read 65 | */ 66 | const uint8_t * bot_ringbuf_peek_buf(BotRingBuf * cbuf, int numBytes); 67 | 68 | /* 69 | * flush numBytes from the buffer. 70 | * pass in -1 to empy buffer completely! 71 | */ 72 | int bot_ringbuf_flush(BotRingBuf * cbuf, int numBytes); 73 | /* 74 | * Get the amount of data currently stored in the buffer (not the allocated size) 75 | */ 76 | int bot_ringbuf_available(BotRingBuf * cbuf); 77 | 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/serial.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_serial_h__ 2 | #define __bot_serial_h__ 3 | 4 | /** 5 | * @defgroup BotCoreSerial Serial ports 6 | * @brief Reading and writing from serial ports 7 | * @ingroup BotCoreIO 8 | * @include: bot_core/bot_core.h 9 | * 10 | * TODO 11 | * 12 | * Linking: `pkg-config --libs bot2-core` 13 | * 14 | * @{ 15 | */ 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /** Creates a basic fd, setting baud to 9600, raw data i/o (no flow 22 | control, no fancy character handling. Configures it for blocking 23 | reads. 8 data bits, 1 stop bit, no parity. 24 | 25 | Returns the fd, -1 on error 26 | **/ 27 | int bot_serial_open(const char *port, int baud, int blocking); 28 | 29 | /** Set the baud rate, where the baudrate is just the integer value 30 | desired. 31 | 32 | Returns non-zero on error. 33 | **/ 34 | int bot_serial_setbaud(int fd, int baudrate); 35 | 36 | /** Enable cts/rts flow control. 37 | Returns non-zero on error. 38 | **/ 39 | int bot_serial_enablectsrts(int fd); 40 | /** Enable xon/xoff flow control. 41 | Returns non-zero on error. 42 | **/ 43 | int bot_serial_enablexon(int fd); 44 | 45 | /** Set the port to 8 data bits, 2 stop bits, no parity. 46 | Returns non-zero on error. 47 | **/ 48 | int bot_serial_set_N82 (int fd); 49 | 50 | int bot_serial_close(int fd); 51 | 52 | /** 53 | * Get the number of bytes waiting to be read 54 | */ 55 | int bot_serial_bytes_available(int fd); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/set.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_set_h__ 2 | #define __bot_set_h__ 3 | 4 | #include 5 | 6 | /** 7 | * @defgroup BotCoreSet Set 8 | * @brief Set data structure for hashable objects 9 | * @ingroup BotCoreDataStructures 10 | * @include: bot_core/bot_core.h 11 | * 12 | * TODO 13 | * 14 | * Linking: `pkg-config --libs bot2-core` 15 | * 16 | * @{ 17 | */ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef struct _BotSet BotSet; 24 | 25 | BotSet * bot_set_new (GHashFunc hash_func, GEqualFunc equal_func); 26 | 27 | BotSet * bot_set_new_full (GHashFunc hash_func, GEqualFunc equal_func, 28 | GDestroyNotify element_destroy_func); 29 | 30 | BotSet * bot_set_new_union (const BotSet *set1, const BotSet *set2); 31 | 32 | BotSet * bot_set_new_intersection (const BotSet *set1, const BotSet *set2); 33 | 34 | BotSet * bot_set_new_copy (const BotSet *set); 35 | 36 | /** 37 | * bot_set_subtract: 38 | * removes elements from set1 that are also in set2 39 | */ 40 | void bot_set_subtract (BotSet *set1, const BotSet *set2); 41 | 42 | void bot_set_destroy (BotSet *set); 43 | 44 | void bot_set_add (BotSet *set, gpointer element); 45 | 46 | void bot_set_add_list (BotSet *set, GList *list); 47 | 48 | void bot_set_remove (BotSet *set, gpointer element); 49 | 50 | void bot_set_remove_all (BotSet *set); 51 | 52 | int bot_set_size (const BotSet *set); 53 | 54 | gboolean bot_set_contains (const BotSet *set, gpointer element); 55 | 56 | typedef void (*BotSetForeachFunc) (gpointer element, gpointer user_data); 57 | void bot_set_foreach (BotSet *set, BotSetForeachFunc func, gpointer user_data); 58 | 59 | GPtrArray *bot_set_get_elements (BotSet *set); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/signal_pipe.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_signal_pipe_h__ 2 | #define __bot_signal_pipe_h__ 3 | 4 | /** 5 | * @defgroup BotCoreSignalPipe Signals to pipes 6 | * @brief Receive UNIX signal notifications via pipes 7 | * @ingroup BotCoreIO 8 | * @include: bot_core/bot_core.h 9 | * 10 | * signal_pipe provides convenience wrappers to convert unix signals into glib 11 | * events. 12 | * 13 | * e.g. to catch SIGINT in a gtk callback function, you might do: 14 | * 15 | * 16 | * void handle_sigint (int signal, void *user) { 17 | * printf("caught SIGINT\n"); 18 | * gtk_main_quit(); 19 | * } 20 | * 21 | * int main(int argc, char **argv) { 22 | * gtk_init(); 23 | * bot_signal_pipe_init(); 24 | * bot_signal_pipe_add_signal (SIGINT); 25 | * bot_signal_pipe_attach_glib (handle_sigint, NULL); 26 | * 27 | * gtk_main(); 28 | * 29 | * bot_signal_pipe_destroy(); 30 | * } 31 | * 32 | * 33 | * @{ 34 | */ 35 | 36 | #include 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | typedef void (*bot_signal_pipe_glib_handler_t) (int signal, void *user_data); 43 | 44 | // initializes signal_pipe. call this once per process. 45 | int bot_signal_pipe_init (void); 46 | 47 | // cleans up resources used by the signal_pipe 48 | int bot_signal_pipe_cleanup (void); 49 | 50 | // specifies that signal should be caught by signal_pipe and converted to a 51 | // glib event 52 | void bot_signal_pipe_add_signal (int signal); 53 | 54 | // sets a handler function that is called when a signal is caught by 55 | // signal_pipe. The first argument to the user_func function is the number of 56 | // the signal caught. The second is the user_data parameter passed in here. 57 | int bot_signal_pipe_attach_glib (bot_signal_pipe_glib_handler_t user_func, 58 | gpointer user_data); 59 | 60 | // convenience function to setup a signal handler that calls 61 | // signal_pipe_init, and adds a signal handler that automatically call 62 | // g_main_loop_quit (mainloop) on receiving SIGTERM, SIGINT, or SIGHUP. 63 | // also invokes signal_pipe_cleanup() on receiving these signals. 64 | int bot_signal_pipe_glib_quit_on_kill (GMainLoop *mainloop); 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/ssocket.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_ssocket_h__ 2 | #define __bot_ssocket_h__ 3 | 4 | /** 5 | * @defgroup BotCoreSSocket TCP Sockets 6 | * @brief Convenience data structure for using a TCP socket 7 | * @ingroup BotCoreIO 8 | * @include: bot_core/bot_core.h 9 | * 10 | * TODO 11 | * 12 | * Linking: `pkg-config --libs bot2-core` 13 | * 14 | * @{ 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | typedef struct bot_ssocket bot_ssocket_t; 26 | 27 | struct bot_ssocket 28 | { 29 | int type; 30 | int socket; 31 | 32 | struct sockaddr addr; 33 | socklen_t addrlen; 34 | 35 | }; 36 | 37 | bot_ssocket_t *bot_ssocket_create(void); 38 | void bot_ssocket_destroy(bot_ssocket_t *s); 39 | int bot_ssocket_connect(bot_ssocket_t *s, const char *hostname, int port); 40 | int bot_ssocket_disable_nagle(bot_ssocket_t *s); 41 | int bot_ssocket_listen(bot_ssocket_t *s, int port, int listenqueue, int localhostOnly); 42 | bot_ssocket_t *bot_ssocket_accept(bot_ssocket_t *s); 43 | void bot_ssocket_get_remote_ip(bot_ssocket_t *s, int *ip); 44 | int bot_ssocket_get_fd(bot_ssocket_t *s); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/tictoc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tictoc.h 3 | * 4 | * Created on: May 29, 2009 5 | * Author: abachrac 6 | */ 7 | 8 | #ifndef __bot_tictoch_h__ 9 | #define __bot_tictoch_h__ 10 | 11 | /** 12 | * @defgroup BotCoreTicToc TicToc 13 | * @brief quick and dirty profiling tool. 14 | * @ingroup BotCoreTime 15 | * @include: bot_core/bot_core.h 16 | * 17 | * inspired by the matlab tic/toc command 18 | * 19 | * call bot_tictoc("description") to set the timer going 20 | * call it again with the same description to stop the timer 21 | * 22 | * Note: To get output, set the "BOT_TICTOC" environment variable to something 23 | * 24 | * @{ 25 | */ 26 | 27 | #define BOT_TICTOC_ENV "BOT_TICTOC" 28 | 29 | #ifdef __cplusplus 30 | extern "C" 31 | { 32 | #endif 33 | 34 | /** 35 | * bot_tictoc: 36 | * 37 | * basic invocation, the second time its called, it returns the time difference in microseconds 38 | **/ 39 | int64_t 40 | bot_tictoc(const char *description); 41 | 42 | /** 43 | * bot_tictoc_full: 44 | * 45 | * full invocation, allows you to specify an 46 | * exponential moving average rate, and the current EMA value is returned in the ema argument 47 | */ 48 | int64_t 49 | bot_tictoc_full(const char *description, double ema_alpha, int64_t * ema); 50 | 51 | /** 52 | * bot_tictoc_sort_type_t: 53 | * 54 | * Different Options for sorting the printed results 55 | */ 56 | typedef enum 57 | { 58 | BOT_TICTOC_AVG, 59 | BOT_TICTOC_TOTAL, 60 | BOT_TICTOC_MIN, 61 | BOT_TICTOC_MAX, 62 | BOT_TICTOC_EMA, 63 | BOT_TICTOC_ALPHABETICAL 64 | } bot_tictoc_sort_type_t; 65 | 66 | /** 67 | * bot_tictoc_print_stats: 68 | * 69 | * Print Out the stats from tictoc 70 | */ 71 | void 72 | bot_tictoc_print_stats(bot_tictoc_sort_type_t sortType); 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | #endif /* TICTOC_H_ */ 82 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/timespec.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "timespec.h" 6 | 7 | void bot_timespec_to_timeval(struct timespec *ts, struct timeval *tv) 8 | { 9 | tv->tv_sec = ts->tv_sec; 10 | tv->tv_usec = ts->tv_nsec / 1000; 11 | } 12 | 13 | void bot_timespec_now(struct timespec *ts) 14 | { 15 | struct timeval tv; 16 | 17 | // get the current time 18 | gettimeofday(&tv, NULL); 19 | ts->tv_sec = tv.tv_sec; 20 | ts->tv_nsec = tv.tv_usec*1000; 21 | } 22 | 23 | void bot_timespec_addms(struct timespec *ts, long ms) 24 | { 25 | int sec=ms/1000; 26 | ms=ms-sec*1000; 27 | 28 | // perform the addition 29 | ts->tv_nsec+=ms*1000000; 30 | 31 | // adjust the time 32 | ts->tv_sec+=ts->tv_nsec/1000000000 + sec; 33 | ts->tv_nsec=ts->tv_nsec%1000000000; 34 | } 35 | 36 | void bot_timespec_addns(struct timespec *ts, long ns) 37 | { 38 | int sec=ns/1000000000; 39 | ns=ns - sec*1000000000; 40 | 41 | // perform the addition 42 | ts->tv_nsec+=ns; 43 | 44 | // adjust the time 45 | ts->tv_sec+=ts->tv_nsec/1000000000 + sec; 46 | ts->tv_nsec=ts->tv_nsec%1000000000; 47 | 48 | } 49 | 50 | void bot_timeval_set(struct timeval *tv, double dt) 51 | { 52 | long us = dt*1000000; 53 | 54 | tv->tv_sec = us / 1000000; 55 | tv->tv_usec = us - tv->tv_sec*1000000; 56 | } 57 | 58 | void bot_timespec_adjust(struct timespec *ts, double dt) 59 | { 60 | int sec; 61 | long ns; 62 | 63 | sec = (int) dt; 64 | ns = (dt - sec) * 1000000000; 65 | 66 | while (ns < 0) { 67 | ns += 1000000000; 68 | sec--; 69 | } 70 | 71 | // perform the addition 72 | ts->tv_nsec+=ns; 73 | 74 | // adjust the time 75 | ts->tv_sec+=ts->tv_nsec/1000000000 + sec; 76 | ts->tv_nsec=ts->tv_nsec%1000000000; 77 | 78 | } 79 | 80 | int bot_timespec_compare(struct timespec *a, struct timespec *b) 81 | { 82 | if (a->tv_sec!=b->tv_sec) 83 | return a->tv_sec-b->tv_sec; 84 | 85 | return a->tv_nsec-b->tv_nsec; 86 | } 87 | 88 | // computes a = a-b 89 | void bot_timespec_subtract(struct timespec *a, struct timespec *b) 90 | { 91 | a->tv_nsec = a->tv_nsec - b->tv_nsec; 92 | if (a->tv_nsec < 0) { 93 | // borrow. 94 | a->tv_nsec += 1000000000; 95 | a->tv_sec --; 96 | } 97 | 98 | a->tv_sec = a->tv_sec - b->tv_sec; 99 | } 100 | 101 | // convert the timespec into milliseconds (may overflow) 102 | int bot_timespec_milliseconds(struct timespec *a) 103 | { 104 | return a->tv_sec*1000 + a->tv_nsec/1000000; 105 | } 106 | 107 | void bot_timespec_print(struct timespec *a) 108 | { 109 | printf("%li.%09li\n",a->tv_sec, a->tv_nsec); 110 | } 111 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/timespec.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_timespec_h__ 2 | #define __bot_timespec_h__ 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * @defgroup BotCoreTimeSpec Timespec 9 | * @brief Convenience functions for struct timespec 10 | * @ingroup BotCoreTime 11 | * @include: bot_core/bot_core.h 12 | * 13 | * TODO 14 | * 15 | * Linking: `pkg-config --libs bot2-core` 16 | * 17 | * @{ 18 | */ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | // get the current time 25 | void bot_timespec_now(struct timespec *ts); 26 | 27 | // add ms milliseconds to the timespec (ms > 0) 28 | void bot_timespec_addms(struct timespec *ts, long ms); 29 | 30 | // add ns nanoseconds to the timespec (ns > 0) 31 | void bot_timespec_addns(struct timespec *ts, long ns); 32 | 33 | void bot_timespec_adjust(struct timespec *ts, double dt); 34 | 35 | // compare a and b 36 | int bot_timespec_compare(struct timespec *a, struct timespec *b); 37 | 38 | // display the timespec 39 | void bot_timespec_print(struct timespec *a); 40 | 41 | // computes a = a-b 42 | void bot_timespec_subtract(struct timespec *a, struct timespec *b); 43 | 44 | // convert the timespec into milliseconds (may overflow) 45 | int bot_timespec_milliseconds(struct timespec *a); 46 | 47 | void bot_timeval_set(struct timeval *tv, double dt); 48 | 49 | void bot_timespec_to_timeval(struct timespec *ts, struct timeval *tv); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /bot2-core/src/bot_core/timestamp.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_timestamp_h__ 2 | #define __bot_timestamp_h__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /** 9 | * @defgroup BotCoreTimestamp Timestamp 10 | * @brief Retrieving the current time, synchronizing clocks 11 | * @ingroup BotCoreTime 12 | * @include: bot_core/bot_core.h 13 | * 14 | * TODO 15 | * 16 | * Linking: `pkg-config --libs bot2-core` 17 | * 18 | * @{ 19 | */ 20 | 21 | typedef struct bot_timestamp_sync_state bot_timestamp_sync_state_t; 22 | 23 | struct bot_timestamp_sync_state { 24 | double dev_ticks_per_second; // how fast does device clock count? (nominal) 25 | int64_t dev_ticks_wraparound; // device clock counts modulo what? 26 | double max_rate_error; // how fast do we need to count to ensure we're counting faster than device? 27 | 28 | int64_t sync_host_time; // when we last synced, what time was it for the host? 29 | int64_t dev_ticks_since_sync; // how many device ticks have elapsed since the last sync? 30 | 31 | int64_t last_dev_ticks; // what device time was it when we were last called? 32 | 33 | uint8_t is_valid; // have we ever synced? 34 | }; 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | int64_t bot_timestamp_now(void); 41 | int64_t bot_timestamp_seconds(int64_t v); 42 | int64_t bot_timestamp_useconds(int64_t v); 43 | void bot_timestamp_to_timeval(int64_t v, struct timeval *tv); 44 | void bot_timestamp_to_timespec(int64_t v, struct timespec *ts); 45 | 46 | /** Create a new time synchronizer. 47 | @param dev_ticks_per_second The nominal rate at which the device time increments 48 | @param dev_ticks_wraparound Assume that dev_ticks wraps around every wraparound ticks 49 | @param rate An upper bound on the rate error 50 | 51 | The syncronization algorithm is described in: 52 | @inproceedings{olson2010, 53 | TITLE = {A Passive Solution to the Sensor Synchronization Problem}, 54 | AUTHOR = { Edwin Olson}, 55 | BOOKTITLE = {Proceedings of the {IEEE/RSJ} International Conference on Intelligent 56 | Robots and Systems {(IROS)}}, 57 | YEAR = {2010}, 58 | MONTH = {October}, 59 | VOLUME = {}, 60 | NUMBER = {}, 61 | PAGES = {}, 62 | KEYWORDS = {sensor calibration, time synchronization}, 63 | ISSN = { }, 64 | } 65 | **/ 66 | bot_timestamp_sync_state_t * 67 | bot_timestamp_sync_init (double dev_ticks_per_second, int64_t dev_ticks_wraparound, 68 | double rate); 69 | void 70 | bot_timestamp_sync_free (bot_timestamp_sync_state_t * s); 71 | int64_t 72 | bot_timestamp_sync (bot_timestamp_sync_state_t * s, int64_t dev_ticks, 73 | int64_t host_utime); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /bot2-frames/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6.0) 2 | 3 | # pull in the pods macros. See cmake/pods.cmake for documentation 4 | set(POD_NAME bot2-frames) 5 | 6 | include(cmake/pods.cmake) 7 | 8 | include(cmake/lcmtypes.cmake) 9 | lcmtypes_build() 10 | 11 | find_package(PkgConfig REQUIRED) 12 | find_package(OpenGL REQUIRED) 13 | 14 | list(APPEND OPENGL_LIBRARIES GL) 15 | set(GLUT_CFLAGS "") 16 | set(GLUT_LIBRARIES -lglut) 17 | 18 | 19 | pkg_check_modules(GLIB2 REQUIRED glib-2.0) 20 | pkg_check_modules(LCM REQUIRED lcm) 21 | pkg_check_modules(BOT2_CORE REQUIRED bot2-core) 22 | pkg_check_modules(BOT2_PARAM REQUIRED bot2-param-client) 23 | 24 | add_subdirectory(src) 25 | add_subdirectory(src/test) 26 | 27 | pkg_check_modules(BOT2_VIS bot2-vis) 28 | if(NOT BOT2_VIS_FOUND) 29 | message("bot2-vis not found. Not building libbot2 renderer") 30 | else() 31 | add_subdirectory(src/renderer) 32 | endif() 33 | -------------------------------------------------------------------------------- /bot2-frames/Makefile: -------------------------------------------------------------------------------- 1 | # Default pod makefile distributed with pods version: 12.09.21 2 | 3 | default_target: all 4 | 5 | # Default to a less-verbose build. If you want all the gory compiler output, 6 | # run "make VERBOSE=1" 7 | $(VERBOSE).SILENT: 8 | 9 | # Figure out where to build the software. 10 | # Use BUILD_PREFIX if it was passed in. 11 | # If not, search up to four parent directories for a 'build' directory. 12 | # Otherwise, use ./build. 13 | ifeq "$(BUILD_PREFIX)" "" 14 | BUILD_PREFIX:=$(shell for pfx in ./ .. ../.. ../../.. ../../../..; do d=`pwd`/$$pfx/build;\ 15 | if [ -d $$d ]; then echo $$d; exit 0; fi; done; echo `pwd`/build) 16 | endif 17 | # create the build directory if needed, and normalize its path name 18 | BUILD_PREFIX:=$(shell mkdir -p $(BUILD_PREFIX) && cd $(BUILD_PREFIX) && echo `pwd`) 19 | 20 | # Default to a release build. If you want to enable debugging flags, run 21 | # "make BUILD_TYPE=Debug" 22 | ifeq "$(BUILD_TYPE)" "" 23 | BUILD_TYPE="Release" 24 | endif 25 | 26 | all: pod-build/Makefile 27 | $(MAKE) -C pod-build all install 28 | 29 | pod-build/Makefile: 30 | $(MAKE) configure 31 | 32 | .PHONY: configure 33 | configure: 34 | @echo "\nBUILD_PREFIX: $(BUILD_PREFIX)\n\n" 35 | 36 | # create the temporary build directory if needed 37 | @mkdir -p pod-build 38 | 39 | # run CMake to generate and configure the build scripts 40 | @cd pod-build && cmake -DCMAKE_INSTALL_PREFIX=$(BUILD_PREFIX) \ 41 | -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) .. 42 | 43 | clean: 44 | -if [ -e pod-build/install_manifest.txt ]; then rm -f `cat pod-build/install_manifest.txt`; fi 45 | -if [ -d pod-build ]; then $(MAKE) -C pod-build clean; rm -rf pod-build; fi 46 | 47 | # other (custom) targets are passed through to the cmake-generated Makefile 48 | %:: 49 | $(MAKE) -C pod-build $@ -------------------------------------------------------------------------------- /bot2-frames/README: -------------------------------------------------------------------------------- 1 | This software is constructed according to the Pods software policies and 2 | templates. The policies and templates can be found at: 3 | 4 | http://sourceforge.net/projects/pods 5 | 6 | ==== 7 | 8 | Name: bot2-frames 9 | Maintainers: 10 | Summary: A library that manages a set of coordinate frames. 11 | Description: 12 | bot2-frames reads the coordinate frame setup information from a parameter file stored by bot2-param 13 | 14 | ================= 15 | Requirements: 16 | GLib (>= 2.0) 17 | LCM (http://lcm.googlecode.com) 18 | bot2-core 19 | bot2-param 20 | bot2-vis (optional, for renderer) 21 | 22 | ================= 23 | Param File Format: 24 | bot2-frames assumes specific param-file format, an example of which is shown below 25 | 26 | 27 | coordinate_frames { 28 | root_frame = "local"; #a root_frame must be defined 29 | 30 | body { 31 | relative_to = "local"; 32 | history = 1000; #number of past transforms to keep around, 33 | update_channel = "BODY_TO_LOCAL"; #transform updates will be listened for on this channel 34 | initial_transform{ 35 | translation = [ 0, 0, 0 ]; #(x,y,z) translation vector 36 | quat = [ 1, 0, 0, 0 ]; #may be specified as a quaternion, rpy, rodrigues, or axis-angle 37 | } 38 | } 39 | laser { 40 | relative_to = "body"; 41 | history = 0; #if set to 0, transform will not be updated 42 | update_channel = ""; #ignored since history=0 43 | initial_transform{ 44 | translation = [ 0, 0, 0 ]; 45 | rpy = [ 0, 0, 0 ]; 46 | } 47 | } 48 | camera { 49 | relative_to = "body"; 50 | history = 0; 51 | initial_transform{ 52 | translation = [ 0, 0, 0 ]; 53 | rodrigues = [ 0, 0, 0 ]; 54 | } 55 | } 56 | #etc... 57 | } 58 | -------------------------------------------------------------------------------- /bot2-frames/lcmtypes/bot_frames_update_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_frames; 2 | 3 | struct update_t 4 | { 5 | int64_t utime; // utime that the actual measurement took place 6 | 7 | string frame; // name of the frame to update 8 | string relative_to; // frame that the update is relative to 9 | 10 | double trans[3]; // translation vector component (x,y,z) 11 | double quat[4]; // rotation quaternion component (w,x,y,z) 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bot2-frames/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | # Create a shared library libbot2-frames.so with a single source file 3 | add_library(bot2-frames SHARED bot_frames.c) 4 | set(REQUIRED_LIBS bot2-core bot2-param-client) 5 | 6 | target_link_libraries(bot2-frames lcmtypes_bot2-frames) 7 | pods_use_pkg_config_packages(bot2-frames ${REQUIRED_LIBS}) 8 | list(APPEND REQUIRED_LIBS lcmtypes_bot2-frames) 9 | 10 | # set the library API version. Increment this every time the public API 11 | # changes. 12 | set_target_properties(bot2-frames PROPERTIES SOVERSION 2) 13 | 14 | # make the header public 15 | # install it to include/bot2-frames 16 | pods_install_headers(bot_frames.h DESTINATION bot_frames) 17 | 18 | # make the library public 19 | pods_install_libraries(bot2-frames) 20 | 21 | # create a pkg-config file for the library, to make it for other software to 22 | # use it. 23 | pods_install_pkg_config_file(bot2-frames 24 | CFLAGS 25 | LIBS -lbot2-frames 26 | REQUIRES ${REQUIRED_LIBS} 27 | VERSION 0.0.1) 28 | -------------------------------------------------------------------------------- /bot2-frames/src/renderer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | # Create a shared library libbot2-frames-renderer.so with a single source file 3 | add_library(bot2-frames-renderers SHARED 4 | coord_frames_renderer.c articulated_body_renderer.c frame_modifier_renderer.c) 5 | 6 | set(REQUIRED_PACKAGES bot2-core bot2-param-client bot2-vis) 7 | 8 | 9 | pods_use_pkg_config_packages(bot2-frames-renderers ${REQUIRED_PACKAGES}) 10 | target_link_libraries(bot2-frames-renderers bot2-frames 11 | ${OPENGL_LIBRARIES}) 12 | list(APPEND REQUIRED_PACKAGES bot2-frames) 13 | 14 | # set the library API version. Increment this every time the public API 15 | # changes. 16 | set_target_properties(bot2-frames-renderers PROPERTIES SOVERSION 1) 17 | 18 | # make the header public 19 | # install it to include/bot_frames 20 | pods_install_headers(bot_frames_renderers.h DESTINATION bot_frames) 21 | 22 | # make the library public 23 | pods_install_libraries(bot2-frames-renderers) 24 | 25 | # create a pkg-config file for the library, to make it for other software to 26 | # use it. 27 | pods_install_pkg_config_file(bot2-frames-renderers 28 | CFLAGS 29 | LIBS -lbot2-frames-renderers 30 | REQUIRES ${REQUIRED_PACKAGES} 31 | VERSION 0.0.1) 32 | 33 | 34 | #build the test-viewer 35 | add_executable(test-viewer test_viewer.c) 36 | target_link_libraries(test-viewer ${GLUT_LIBRARIES} bot2-frames-renderers) 37 | pods_use_pkg_config_packages(test-viewer 38 | bot2-vis 39 | bot2-lcmgl-renderer) 40 | -------------------------------------------------------------------------------- /bot2-frames/src/renderer/bot_frames_renderers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * coord_frames_renderer.h 3 | * 4 | * Created on: Jan 22, 2011 5 | * Author: abachrac 6 | */ 7 | #include 8 | #include 9 | 10 | #ifndef COORD_FRAMES_RENDERER_H_ 11 | #define COORD_FRAMES_RENDERER_H_ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | //allow multiple simultaneous frames renders 18 | void bot_frames_add_named_renderer_to_viewer(BotViewer *viewer, int render_priority, BotFrames * frames, const char * name); 19 | 20 | void bot_frames_add_renderer_to_viewer(BotViewer *viewer, int render_priority, BotFrames * frames); 21 | 22 | void bot_frames_add_articulated_body_renderer_to_viewer(BotViewer *viewer, int render_priority, BotParam * param, 23 | BotFrames * frames, const char * model_path, const char * param_articulated_name); 24 | 25 | void bot_frames_add_frame_modifier_to_viewer(BotViewer *viewer, int render_priority, BotFrames * frames); 26 | 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif /* COORD_FRAMES_RENDERER_H_ */ 33 | -------------------------------------------------------------------------------- /bot2-frames/src/renderer/test_viewer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | //renderers 10 | #include 11 | #include 12 | 13 | static void on_top_view_clicked(GtkToggleToolButton *tb, void *user_data) 14 | { 15 | BotViewer *self = (BotViewer*) user_data; 16 | 17 | double eye[3]; 18 | double look[3]; 19 | double up[3]; 20 | self->view_handler->get_eye_look(self->view_handler, eye, look, up); 21 | 22 | eye[0] = 0; 23 | eye[1] = 0; 24 | eye[2] = 10; 25 | look[0] = 0; 26 | look[1] = 0; 27 | look[2] = 0; 28 | up[0] = 0; 29 | up[1] = 10; 30 | up[2] = 0; 31 | self->view_handler->set_look_at(self->view_handler, eye, look, up); 32 | 33 | bot_viewer_request_redraw(self); 34 | } 35 | 36 | int main(int argc, char *argv[]) 37 | { 38 | gtk_init(&argc, &argv); 39 | glutInit(&argc, argv); 40 | g_thread_init(NULL); 41 | 42 | // if (argc < 2) { 43 | // fprintf(stderr, "usage: %s \n", g_path_get_basename(argv[0])); 44 | // exit(1); 45 | // } 46 | lcm_t * lcm = bot_lcm_get_global(NULL); 47 | BotParam * param = bot_param_get_global(lcm, 0); 48 | BotFrames * bcf = bot_frames_get_global(lcm, param); 49 | bot_glib_mainloop_attach_lcm(lcm); 50 | 51 | BotViewer* viewer = bot_viewer_new("Bot Frames Test Viewer"); 52 | //die cleanly for control-c etc :-) 53 | bot_gtk_quit_on_interrupt(); 54 | 55 | // setup renderers 56 | bot_viewer_add_stock_renderer(viewer, BOT_VIEWER_STOCK_RENDERER_GRID, 1); 57 | bot_lcmgl_add_renderer_to_viewer(viewer, lcm, 1); 58 | bot_frames_add_renderer_to_viewer(viewer, 1, bcf); 59 | bot_frames_add_articulated_body_renderer_to_viewer(viewer, 1, param, bcf, NULL, "articulated_body_name"); 60 | 61 | //load the renderer params from the config file. 62 | char *fname = g_build_filename(g_get_user_config_dir(), ".bft-viewerrc", NULL); 63 | bot_viewer_load_preferences(viewer, fname); 64 | 65 | gtk_main(); 66 | 67 | //save the renderer params to the config file. 68 | bot_viewer_save_preferences(viewer, fname); 69 | 70 | bot_viewer_unref(viewer); 71 | } 72 | -------------------------------------------------------------------------------- /bot2-frames/src/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | # Create an executable program coord-frames-test 4 | add_executable(coord-frames-test coord_frames_test.c) 5 | 6 | # The test program uses the shared library, use the pkg-config file 7 | target_link_libraries(coord-frames-test bot2-frames) 8 | 9 | # make executable public 10 | #pods_install_executables(coord-frames-test) 11 | -------------------------------------------------------------------------------- /bot2-frames/src/test/coord_frames_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coord_frame_test.c 3 | * 4 | * Created on: Jan 14, 2011 5 | * Author: abachrac 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | void update_handler(BotFrames *bot_frames, const char *frame, const char * relative_to, int64_t utime, void *user) 13 | { 14 | printf("link %s->%s was updated, user = %p\n", frame, relative_to,user); 15 | } 16 | 17 | int main(int argc, char ** argv) 18 | { 19 | 20 | lcm_t * lcm = lcm_create(NULL); 21 | BotParam * param = bot_param_new_from_server(lcm, 0); 22 | BotFrames * bcf = bot_frames_get_global(lcm, param); 23 | bot_frames_add_update_subscriber(bcf,update_handler,NULL); 24 | 25 | for (int i = 0; i < 100; i++) { 26 | BotTrans t; 27 | bot_frames_get_trans(bcf, "laser", "local", &t); 28 | fprintf(stderr, "laser->local= (%f,%f,%f) - (%f,%f,%f,%f)\n", t.trans_vec[0], t.trans_vec[1], t.trans_vec[2], 29 | t.rot_quat[0], t.rot_quat[1], t.rot_quat[2], t.rot_quat[3]); 30 | bot_core_rigid_transform_t msg; 31 | msg.utime = bot_timestamp_now(); 32 | msg.trans[0] = ((float) rand()) / (RAND_MAX + 1.0); 33 | msg.trans[1] = ((float) rand()) / (RAND_MAX + 1.0); 34 | msg.trans[2] = ((float) rand()) / (RAND_MAX + 1.0); 35 | 36 | double rod[3]; 37 | rod[0] = ((float) rand()) / (RAND_MAX + 1.0); 38 | rod[1] = ((float) rand()) / (RAND_MAX + 1.0); 39 | rod[2] = ((float) rand()) / (RAND_MAX + 1.0); 40 | bot_rodrigues_to_quat(rod, msg.quat); 41 | 42 | bot_core_rigid_transform_t_publish(lcm, "BODY_TO_LOCAL", &msg); 43 | lcm_handle(lcm); 44 | } 45 | 46 | return 0; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /bot2-frames/src/test/test_params.cfg: -------------------------------------------------------------------------------- 1 | coordinate_frames { 2 | root_frame = "local"; 3 | 4 | body { 5 | relative_to = "local"; 6 | history = 1000; 7 | update_channel = "BODY_TO_LOCAL"; 8 | initial_transform{ 9 | translation = [ 0, 0, 0 ]; 10 | quat = [ 1, 0, 0, 0 ]; 11 | } 12 | } 13 | laser { 14 | relative_to = "body"; 15 | history = 0; 16 | update_channel = ""; 17 | initial_transform{ 18 | translation = [ 0, 0, 0 ]; 19 | rpy = [ 0, 0, 0 ]; 20 | } 21 | } 22 | camera { 23 | relative_to = "body"; 24 | history = 0; 25 | initial_transform{ 26 | translation = [ 1, 0, 0 ]; 27 | rodrigues = [ 0, 0, 0 ]; 28 | } 29 | } 30 | #etc... 31 | } 32 | 33 | 34 | articulated_body_name { 35 | body1 { 36 | frame = "laser"; 37 | visualization = "cylinder"; 38 | scale = [1, 2, 3]; 39 | translation = [.5, 1, 1.5]; 40 | rpy = [0,0,0]; 41 | color = [0, 1, 0, 1]; 42 | } 43 | 44 | body2 { 45 | frame = "camera"; 46 | visualization = "cube"; 47 | scale = [.001, .001, .001]; 48 | translation = [1.5, 1, .5]; 49 | rpy = [0,0,0]; 50 | color = [1, 0, 0, 1]; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /bot2-lcm-utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6.0) 2 | 3 | include(cmake/pods.cmake) 4 | 5 | add_subdirectory(src/logfilter) 6 | add_subdirectory(src/logsplice) 7 | add_subdirectory(src/who) 8 | add_subdirectory(src/tunnel) 9 | add_subdirectory(python) 10 | 11 | 12 | # bot-spy 13 | set(script_name bot-spy) 14 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} 15 | "#!/bin/sh\n" 16 | "CLASSPATH=`PKG_CONFIG_PATH=PKG_CONFIG_PATH:${CMAKE_INSTALL_PREFIX}/lib/pkgconfig pkg-config --variable=classpath lcm-java`\n" 17 | "for d in . .. ../.. ../../.. ../../../.. \"${CMAKE_INSTALL_PREFIX}\"; do\n" 18 | # "for d in \"${CMAKE_INSTALL_PREFIX}\"; do\n" 19 | " if [ -d $d/share/java ]; then\n" 20 | " jd=$d/share/java\n" 21 | " echo Checking $jd\n" 22 | " for f in $jd/lcmtypes_*.jar $jd/lcmspy_plugins_*.jar; do\n" 23 | " if [ -e $f ]; then\n" 24 | " echo \" Found $f\"\n" 25 | " CLASSPATH=\$CLASSPATH:\$f\n" 26 | " fi\n" 27 | " done\n" 28 | " fi\n" 29 | "done\n" 30 | "exec java -ea -cp \$CLASSPATH lcm.spy.Spy $*\n") 31 | 32 | # install it... 33 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script_name} DESTINATION bin) 34 | -------------------------------------------------------------------------------- /bot2-lcm-utils/Makefile: -------------------------------------------------------------------------------- 1 | # Default pod makefile distributed with pods version: 12.09.21 2 | 3 | default_target: all 4 | 5 | # Default to a less-verbose build. If you want all the gory compiler output, 6 | # run "make VERBOSE=1" 7 | $(VERBOSE).SILENT: 8 | 9 | # Figure out where to build the software. 10 | # Use BUILD_PREFIX if it was passed in. 11 | # If not, search up to four parent directories for a 'build' directory. 12 | # Otherwise, use ./build. 13 | ifeq "$(BUILD_PREFIX)" "" 14 | BUILD_PREFIX:=$(shell for pfx in ./ .. ../.. ../../.. ../../../..; do d=`pwd`/$$pfx/build;\ 15 | if [ -d $$d ]; then echo $$d; exit 0; fi; done; echo `pwd`/build) 16 | endif 17 | # create the build directory if needed, and normalize its path name 18 | BUILD_PREFIX:=$(shell mkdir -p $(BUILD_PREFIX) && cd $(BUILD_PREFIX) && echo `pwd`) 19 | 20 | # Default to a release build. If you want to enable debugging flags, run 21 | # "make BUILD_TYPE=Debug" 22 | ifeq "$(BUILD_TYPE)" "" 23 | BUILD_TYPE="Release" 24 | endif 25 | 26 | all: pod-build/Makefile 27 | $(MAKE) -C pod-build all install 28 | 29 | pod-build/Makefile: 30 | $(MAKE) configure 31 | 32 | .PHONY: configure 33 | configure: 34 | @echo "\nBUILD_PREFIX: $(BUILD_PREFIX)\n\n" 35 | 36 | # create the temporary build directory if needed 37 | @mkdir -p pod-build 38 | 39 | # run CMake to generate and configure the build scripts 40 | @cd pod-build && cmake -DCMAKE_INSTALL_PREFIX=$(BUILD_PREFIX) \ 41 | -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) .. 42 | 43 | clean: 44 | -if [ -e pod-build/install_manifest.txt ]; then rm -f `cat pod-build/install_manifest.txt`; fi 45 | -if [ -d pod-build ]; then $(MAKE) -C pod-build clean; rm -rf pod-build; fi 46 | 47 | # other (custom) targets are passed through to the cmake-generated Makefile 48 | %:: 49 | $(MAKE) -C pod-build $@ -------------------------------------------------------------------------------- /bot2-lcm-utils/README: -------------------------------------------------------------------------------- 1 | This software is constructed according to the Pods software policies and 2 | templates. The policies and templates can be found at: 3 | 4 | http://sourceforge.net/projects/pods 5 | 6 | ==== 7 | 8 | Name: bot2-lcm-utils 9 | Maintainers: FILL-ME-IN 10 | Summary: FILL-ME-IN 11 | Description: FILL-ME-IN 12 | 13 | Requirements: 14 | bot2-core 15 | -------------------------------------------------------------------------------- /bot2-lcm-utils/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(PythonInterp REQUIRED) 2 | 3 | # install all python packages in the src/ directory 4 | pods_install_python_packages(${CMAKE_CURRENT_SOURCE_DIR}/src) 5 | 6 | # executable scripts: script-name python-module 7 | pods_install_python_script(bot-log2mat bot_log2mat.log_to_mat) 8 | -------------------------------------------------------------------------------- /bot2-lcm-utils/python/src/bot_log2mat/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobotLocomotion/libbot/2dd5a49580292b85d3ba09db417722f218995ce5/bot2-lcm-utils/python/src/bot_log2mat/__init__.py -------------------------------------------------------------------------------- /bot2-lcm-utils/src/logfilter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | add_executable(bot-lcm-logfilter 4 | lcm-logfilter.c) 5 | 6 | pods_use_pkg_config_packages(bot-lcm-logfilter 7 | lcm glib-2.0) 8 | 9 | pods_install_executables(bot-lcm-logfilter) 10 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/logsplice/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | add_executable(bot-lcm-logsplice 4 | lcm-logsplice.c) 5 | 6 | pods_use_pkg_config_packages(bot-lcm-logsplice 7 | lcm glib-2.0) 8 | 9 | pods_install_executables(bot-lcm-logsplice) 10 | 11 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ldpc_sources 2 | ldpc/getopt.cpp 3 | ldpc/ldpc_create_pchk.cpp 4 | ldpc/ldpc_fec.cpp 5 | ldpc/ldpc_fec_iterative_decoding.cpp 6 | ldpc/ldpc_matrix_sparse.cpp 7 | ldpc/ldpc_rand.cpp 8 | ldpc/ldpc_scheme.cpp 9 | ldpc/ldpc_wrapper.cpp 10 | ldpc/tools.cpp 11 | ) 12 | 13 | add_executable(bot-lcm-tunnel 14 | introspect.c 15 | lcm_tunnel_params_t.c 16 | lcm_tunnel_sub_msg_t.c 17 | lcm_tunnel_udp_msg_t.c 18 | lcm_tunnel_disconnect_msg_t.c 19 | ssocket.c 20 | lcm_tunnel.cpp 21 | lcm_tunnel_server.cpp 22 | signal_pipe.c 23 | lcm_util.c 24 | ${ldpc_sources} 25 | ) 26 | 27 | add_executable(ldpc-wrapper-test 28 | ldpc/ldpc_wrapper_test.cpp 29 | ${ldpc_sources} 30 | ) 31 | 32 | set_source_files_properties(introspect.c lcm_tunnel_params_t.c ssocket.c signal_pipe.c lcm_util.c 33 | PROPERTIES COMPILE_FLAGS "-std=gnu99") 34 | 35 | pods_use_pkg_config_packages(bot-lcm-tunnel 36 | lcm glib-2.0) 37 | 38 | pods_install_executables(bot-lcm-tunnel) 39 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/introspect.h: -------------------------------------------------------------------------------- 1 | #ifndef __introspect_h__ 2 | #define __introspect_h__ 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | typedef struct _introspect_t introspect_t; 11 | 12 | /** 13 | * introspection only works for udpm LCM networks 14 | */ 15 | introspect_t * introspect_new(lcm_t * lcm); 16 | 17 | void introspect_send_introspection_packet(introspect_t* ipi); 18 | 19 | void introspect_destroy(introspect_t *ipi); 20 | 21 | int introspect_is_message_from_self(introspect_t * ipi, 22 | const lcm_recv_buf_t * rbuf, const char *channel); 23 | 24 | int introspect_is_ready(const introspect_t * ipi); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/lcm_tunnel_disconnect_msg_t.h: -------------------------------------------------------------------------------- 1 | /** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY 2 | * BY HAND!! 3 | * 4 | * Generated by lcm-gen 5 | **/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifndef _lcm_tunnel_disconnect_msg_t_h 13 | #define _lcm_tunnel_disconnect_msg_t_h 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct _lcm_tunnel_disconnect_msg_t lcm_tunnel_disconnect_msg_t; 20 | struct _lcm_tunnel_disconnect_msg_t 21 | { 22 | int64_t utime; 23 | }; 24 | 25 | lcm_tunnel_disconnect_msg_t *lcm_tunnel_disconnect_msg_t_copy(const lcm_tunnel_disconnect_msg_t *p); 26 | void lcm_tunnel_disconnect_msg_t_destroy(lcm_tunnel_disconnect_msg_t *p); 27 | 28 | typedef struct _lcm_tunnel_disconnect_msg_t_subscription_t lcm_tunnel_disconnect_msg_t_subscription_t; 29 | typedef void(*lcm_tunnel_disconnect_msg_t_handler_t)(const lcm_recv_buf_t *rbuf, 30 | const char *channel, const lcm_tunnel_disconnect_msg_t *msg, void *user); 31 | 32 | int lcm_tunnel_disconnect_msg_t_publish(lcm_t *lcm, const char *channel, const lcm_tunnel_disconnect_msg_t *p); 33 | lcm_tunnel_disconnect_msg_t_subscription_t* lcm_tunnel_disconnect_msg_t_subscribe(lcm_t *lcm, const char *channel, lcm_tunnel_disconnect_msg_t_handler_t f, void *userdata); 34 | int lcm_tunnel_disconnect_msg_t_unsubscribe(lcm_t *lcm, lcm_tunnel_disconnect_msg_t_subscription_t* hid); 35 | 36 | int lcm_tunnel_disconnect_msg_t_encode(void *buf, int offset, int maxlen, const lcm_tunnel_disconnect_msg_t *p); 37 | int lcm_tunnel_disconnect_msg_t_decode(const void *buf, int offset, int maxlen, lcm_tunnel_disconnect_msg_t *p); 38 | int lcm_tunnel_disconnect_msg_t_decode_cleanup(lcm_tunnel_disconnect_msg_t *p); 39 | int lcm_tunnel_disconnect_msg_t_encoded_size(const lcm_tunnel_disconnect_msg_t *p); 40 | 41 | // LCM support functions. Users should not call these 42 | int64_t __lcm_tunnel_disconnect_msg_t_get_hash(void); 43 | int64_t __lcm_tunnel_disconnect_msg_t_hash_recursive(const __lcm_hash_ptr *p); 44 | int __lcm_tunnel_disconnect_msg_t_encode_array(void *buf, int offset, int maxlen, const lcm_tunnel_disconnect_msg_t *p, int elements); 45 | int __lcm_tunnel_disconnect_msg_t_decode_array(const void *buf, int offset, int maxlen, lcm_tunnel_disconnect_msg_t *p, int elements); 46 | int __lcm_tunnel_disconnect_msg_t_decode_array_cleanup(lcm_tunnel_disconnect_msg_t *p, int elements); 47 | int __lcm_tunnel_disconnect_msg_t_encoded_array_size(const lcm_tunnel_disconnect_msg_t *p, int elements); 48 | int __lcm_tunnel_disconnect_msg_t_clone_array(const lcm_tunnel_disconnect_msg_t *p, lcm_tunnel_disconnect_msg_t *q, int elements); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/lcm_tunnel_disconnect_msg_t.lcm: -------------------------------------------------------------------------------- 1 | struct lcm_tunnel_disconnect_msg_t 2 | { 3 | int64_t utime; 4 | } 5 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/lcm_tunnel_params_t.h: -------------------------------------------------------------------------------- 1 | /** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY 2 | * BY HAND!! 3 | * 4 | * Generated by lcm-gen 5 | **/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifndef _lcm_tunnel_params_t_h 13 | #define _lcm_tunnel_params_t_h 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct _lcm_tunnel_params_t lcm_tunnel_params_t; 20 | struct _lcm_tunnel_params_t 21 | { 22 | int8_t udp; 23 | int32_t udp_port; 24 | int32_t tcp_max_age_ms; 25 | int32_t max_delay_ms; 26 | char* channels; 27 | float fec; 28 | }; 29 | 30 | lcm_tunnel_params_t *lcm_tunnel_params_t_copy(const lcm_tunnel_params_t *p); 31 | void lcm_tunnel_params_t_destroy(lcm_tunnel_params_t *p); 32 | 33 | typedef struct _lcm_tunnel_params_t_subscription_t lcm_tunnel_params_t_subscription_t; 34 | typedef void(*lcm_tunnel_params_t_handler_t)(const lcm_recv_buf_t *rbuf, 35 | const char *channel, const lcm_tunnel_params_t *msg, void *user); 36 | 37 | int lcm_tunnel_params_t_publish(lcm_t *lcm, const char *channel, const lcm_tunnel_params_t *p); 38 | lcm_tunnel_params_t_subscription_t* lcm_tunnel_params_t_subscribe(lcm_t *lcm, const char *channel, lcm_tunnel_params_t_handler_t f, void *userdata); 39 | int lcm_tunnel_params_t_unsubscribe(lcm_t *lcm, lcm_tunnel_params_t_subscription_t* hid); 40 | 41 | int lcm_tunnel_params_t_encode(void *buf, int offset, int maxlen, const lcm_tunnel_params_t *p); 42 | int lcm_tunnel_params_t_decode(const void *buf, int offset, int maxlen, lcm_tunnel_params_t *p); 43 | int lcm_tunnel_params_t_decode_cleanup(lcm_tunnel_params_t *p); 44 | int lcm_tunnel_params_t_encoded_size(const lcm_tunnel_params_t *p); 45 | 46 | // LCM support functions. Users should not call these 47 | int64_t __lcm_tunnel_params_t_get_hash(void); 48 | int64_t __lcm_tunnel_params_t_hash_recursive(const __lcm_hash_ptr *p); 49 | int __lcm_tunnel_params_t_encode_array(void *buf, int offset, int maxlen, const lcm_tunnel_params_t *p, int elements); 50 | int __lcm_tunnel_params_t_decode_array(const void *buf, int offset, int maxlen, lcm_tunnel_params_t *p, int elements); 51 | int __lcm_tunnel_params_t_decode_array_cleanup(lcm_tunnel_params_t *p, int elements); 52 | int __lcm_tunnel_params_t_encoded_array_size(const lcm_tunnel_params_t *p, int elements); 53 | int __lcm_tunnel_params_t_clone_array(const lcm_tunnel_params_t *p, lcm_tunnel_params_t *q, int elements); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/lcm_tunnel_params_t.lcm: -------------------------------------------------------------------------------- 1 | struct lcm_tunnel_params_t 2 | { 3 | boolean udp; 4 | int32_t udp_port; 5 | int32_t tcp_max_age_ms; 6 | int32_t max_delay_ms; 7 | string channels; 8 | float fec; 9 | } 10 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/lcm_tunnel_server.h: -------------------------------------------------------------------------------- 1 | #ifndef __lcm_tunnel_server_h__ 2 | #define __lcm_tunnel_server_h__ 3 | 4 | #include 5 | #include "lcm_tunnel.h" 6 | #include "ldpc/ldpc_wrapper.h" 7 | #include "introspect.h" 8 | #include "ssocket.h" 9 | #include 10 | 11 | class LcmTunnelServer { 12 | public: 13 | static int initializeServer(tunnel_server_params_t * params); 14 | static void destroyServer(); 15 | 16 | static bool initialized; 17 | 18 | static int acceptClient(GIOChannel *source, GIOCondition cond, void *user_data); 19 | static int disconnectClient(LcmTunnel * client); 20 | 21 | static GMainLoop * mainloop; 22 | static lcm_t * lcm; 23 | static introspect_t * introspect; 24 | 25 | static bool matches_a_client(const char *channel); 26 | static void check_and_send_to_tunnels(const char *channel, 27 | const void *data, unsigned int len, LcmTunnel * to_skip); 28 | 29 | static std::list clients_list; 30 | 31 | static ssocket_t * server_sock; 32 | static GIOChannel * server_sock_ioc; 33 | static guint server_sock_sid; 34 | 35 | static tunnel_server_params_t params; 36 | 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/lcm_tunnel_sub_msg_t.h: -------------------------------------------------------------------------------- 1 | /** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY 2 | * BY HAND!! 3 | * 4 | * Generated by lcm-gen 5 | **/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifndef _lcm_tunnel_sub_msg_t_h 13 | #define _lcm_tunnel_sub_msg_t_h 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct _lcm_tunnel_sub_msg_t lcm_tunnel_sub_msg_t; 20 | struct _lcm_tunnel_sub_msg_t 21 | { 22 | char* channel; 23 | int32_t data_size; 24 | uint8_t *data; 25 | }; 26 | 27 | lcm_tunnel_sub_msg_t *lcm_tunnel_sub_msg_t_copy(const lcm_tunnel_sub_msg_t *p); 28 | void lcm_tunnel_sub_msg_t_destroy(lcm_tunnel_sub_msg_t *p); 29 | 30 | typedef struct _lcm_tunnel_sub_msg_t_subscription_t lcm_tunnel_sub_msg_t_subscription_t; 31 | typedef void(*lcm_tunnel_sub_msg_t_handler_t)(const lcm_recv_buf_t *rbuf, 32 | const char *channel, const lcm_tunnel_sub_msg_t *msg, void *user); 33 | 34 | int lcm_tunnel_sub_msg_t_publish(lcm_t *lcm, const char *channel, const lcm_tunnel_sub_msg_t *p); 35 | lcm_tunnel_sub_msg_t_subscription_t* lcm_tunnel_sub_msg_t_subscribe(lcm_t *lcm, const char *channel, lcm_tunnel_sub_msg_t_handler_t f, void *userdata); 36 | int lcm_tunnel_sub_msg_t_unsubscribe(lcm_t *lcm, lcm_tunnel_sub_msg_t_subscription_t* hid); 37 | 38 | int lcm_tunnel_sub_msg_t_encode(void *buf, int offset, int maxlen, const lcm_tunnel_sub_msg_t *p); 39 | int lcm_tunnel_sub_msg_t_decode(const void *buf, int offset, int maxlen, lcm_tunnel_sub_msg_t *p); 40 | int lcm_tunnel_sub_msg_t_decode_cleanup(lcm_tunnel_sub_msg_t *p); 41 | int lcm_tunnel_sub_msg_t_encoded_size(const lcm_tunnel_sub_msg_t *p); 42 | 43 | // LCM support functions. Users should not call these 44 | int64_t __lcm_tunnel_sub_msg_t_get_hash(void); 45 | int64_t __lcm_tunnel_sub_msg_t_hash_recursive(const __lcm_hash_ptr *p); 46 | int __lcm_tunnel_sub_msg_t_encode_array(void *buf, int offset, int maxlen, const lcm_tunnel_sub_msg_t *p, int elements); 47 | int __lcm_tunnel_sub_msg_t_decode_array(const void *buf, int offset, int maxlen, lcm_tunnel_sub_msg_t *p, int elements); 48 | int __lcm_tunnel_sub_msg_t_decode_array_cleanup(lcm_tunnel_sub_msg_t *p, int elements); 49 | int __lcm_tunnel_sub_msg_t_encoded_array_size(const lcm_tunnel_sub_msg_t *p, int elements); 50 | int __lcm_tunnel_sub_msg_t_clone_array(const lcm_tunnel_sub_msg_t *p, lcm_tunnel_sub_msg_t *q, int elements); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/lcm_tunnel_sub_msg_t.lcm: -------------------------------------------------------------------------------- 1 | struct lcm_tunnel_sub_msg_t 2 | { 3 | string channel; 4 | int32_t data_size; 5 | byte data[data_size]; 6 | } 7 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/lcm_tunnel_udp_msg_t.h: -------------------------------------------------------------------------------- 1 | /** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY 2 | * BY HAND!! 3 | * 4 | * Generated by lcm-gen 5 | **/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifndef _lcm_tunnel_udp_msg_t_h 13 | #define _lcm_tunnel_udp_msg_t_h 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct _lcm_tunnel_udp_msg_t lcm_tunnel_udp_msg_t; 20 | struct _lcm_tunnel_udp_msg_t 21 | { 22 | int16_t seqno; 23 | int16_t fragno; 24 | int32_t payload_size; 25 | int32_t data_size; 26 | uint8_t *data; 27 | }; 28 | 29 | lcm_tunnel_udp_msg_t *lcm_tunnel_udp_msg_t_copy(const lcm_tunnel_udp_msg_t *p); 30 | void lcm_tunnel_udp_msg_t_destroy(lcm_tunnel_udp_msg_t *p); 31 | 32 | typedef struct _lcm_tunnel_udp_msg_t_subscription_t lcm_tunnel_udp_msg_t_subscription_t; 33 | typedef void(*lcm_tunnel_udp_msg_t_handler_t)(const lcm_recv_buf_t *rbuf, 34 | const char *channel, const lcm_tunnel_udp_msg_t *msg, void *user); 35 | 36 | int lcm_tunnel_udp_msg_t_publish(lcm_t *lcm, const char *channel, const lcm_tunnel_udp_msg_t *p); 37 | lcm_tunnel_udp_msg_t_subscription_t* lcm_tunnel_udp_msg_t_subscribe(lcm_t *lcm, const char *channel, lcm_tunnel_udp_msg_t_handler_t f, void *userdata); 38 | int lcm_tunnel_udp_msg_t_unsubscribe(lcm_t *lcm, lcm_tunnel_udp_msg_t_subscription_t* hid); 39 | 40 | int lcm_tunnel_udp_msg_t_encode(void *buf, int offset, int maxlen, const lcm_tunnel_udp_msg_t *p); 41 | int lcm_tunnel_udp_msg_t_decode(const void *buf, int offset, int maxlen, lcm_tunnel_udp_msg_t *p); 42 | int lcm_tunnel_udp_msg_t_decode_cleanup(lcm_tunnel_udp_msg_t *p); 43 | int lcm_tunnel_udp_msg_t_encoded_size(const lcm_tunnel_udp_msg_t *p); 44 | 45 | // LCM support functions. Users should not call these 46 | int64_t __lcm_tunnel_udp_msg_t_get_hash(void); 47 | int64_t __lcm_tunnel_udp_msg_t_hash_recursive(const __lcm_hash_ptr *p); 48 | int __lcm_tunnel_udp_msg_t_encode_array(void *buf, int offset, int maxlen, const lcm_tunnel_udp_msg_t *p, int elements); 49 | int __lcm_tunnel_udp_msg_t_decode_array(const void *buf, int offset, int maxlen, lcm_tunnel_udp_msg_t *p, int elements); 50 | int __lcm_tunnel_udp_msg_t_decode_array_cleanup(lcm_tunnel_udp_msg_t *p, int elements); 51 | int __lcm_tunnel_udp_msg_t_encoded_array_size(const lcm_tunnel_udp_msg_t *p, int elements); 52 | int __lcm_tunnel_udp_msg_t_clone_array(const lcm_tunnel_udp_msg_t *p, lcm_tunnel_udp_msg_t *q, int elements); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/lcm_tunnel_udp_msg_t.lcm: -------------------------------------------------------------------------------- 1 | struct lcm_tunnel_udp_msg_t 2 | { 3 | int16_t seqno; 4 | int16_t fragno; 5 | int32_t payload_size; //total size of message (probably split up into smaller fragmets) 6 | int32_t data_size; 7 | byte data[data_size]; 8 | } 9 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/lcm_util.h: -------------------------------------------------------------------------------- 1 | // lcm_util was copied from bot_core to make lcm_tunnel a standalone pod 2 | 3 | #ifndef __bot_lcm_util_h__ 4 | #define __bot_lcm_util_h__ 5 | 6 | #include 7 | 8 | /** 9 | * @defgroup BotCoreLcmUtil LcmUtil 10 | * @ingroup BotCoreIO 11 | * @brief Convenience functions for working with LCM 12 | * @include: bot_core/bot_core.h 13 | * 14 | * These functions attach an #lcm_t object to a #GMainLoop so that when there is 15 | * a new message on LCM, lcm_handle() gets called, and your message handlers 16 | * get invoked. 17 | * 18 | * Linking: `pkg-config --libs bot2-core` 19 | */ 20 | 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** 28 | * bot_glib_mainloop_attach_lcm: 29 | * @lcm: The LCM object to attach to the default #GMainLoop. 30 | * 31 | * Attaches LCM to the default #GMainLoop. When attached, lcm_handle() is 32 | * invoked "automatically" when a message is received over LCM. 33 | * 34 | * Only one instance of #lcm_t can be attached per process. 35 | * 36 | * This is the same as calling 37 | * bot_glib_mainloop_attach_lcm_full(%NULL, @lcm, %NULL, %NULL, %NULL). 38 | * 39 | * Returns: 0 on success, -1 on failure 40 | */ 41 | int bot_glib_mainloop_attach_lcm(lcm_t *lcm); 42 | 43 | /** 44 | * bot_glib_mainloop_detach_lcm: 45 | * @lcm: The LCM object to detach from whichever #GMainLoop it was attached 46 | * to. 47 | * 48 | * Detaches the passed LCM instance from whichever #GMainLoop it was attached 49 | * to. 50 | * 51 | * Returns: 0 on success, -1 on failure. 52 | */ 53 | int bot_glib_mainloop_detach_lcm(lcm_t *lcm); 54 | 55 | /** 56 | * bot_glib_mainloop_attach_lcm_full: 57 | * @mainloop: The mainloop to attach to or %NULL if default. 58 | * @lcm: The #lcm_t object to attach. 59 | * @quit_on_lcm_fail: If %TRUE, calls g_main_loop_quit() when lcm_handle() 60 | * returns an error. 61 | * 62 | * Attaches the passed LCM object to the passed #GMainLoop (or the default one 63 | * if the passed value is %NULL). 64 | * 65 | * Returns: 0 on success, -1 on failure. 66 | */ 67 | int bot_glib_mainloop_attach_lcm_full(GMainLoop * mainloop, lcm_t *lcm, 68 | gboolean quit_on_lcm_fail); 69 | 70 | 71 | /** 72 | * bot_lcm_get_global: 73 | * @provider: The string specifying the LCM network provider. If %NULL, the 74 | * environment variable "LCM_DEFAULT_URL" is used if it is defined, otherwise 75 | * the lcm_create default settings are used. 76 | * 77 | * The first time this function is invoked, it instantiates and returns new 78 | * lcm_t instance via lcm_create(provider). Every subsequent call just returns 79 | * the same lcm_t instance. 80 | * 81 | * This function is thread-safe, if g_thread_init() has been called. 82 | * 83 | * Returns: pointer to lcm_t 84 | */ 85 | lcm_t *bot_lcm_get_global(const char *provider); 86 | 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/ldpc/README: -------------------------------------------------------------------------------- 1 | This folder contains a copy of the low density parity check forward error correction library from: 2 | http://planete-bcast.inrialpes.fr/rubrique.php3?id_rubrique=5 3 | 4 | It was modified by Abraham Bachrach to add a wrapper class. This code is in ldpc_wrapper.cpp/h 5 | 6 | It is licensed with the LGPL: 7 | ===== 8 | This codec is: 9 | Copyright (c) 2002-2006 INRIA - All rights reserved. 10 | Copyright (c) 1995-2003 by Radford M. Neal 11 | 12 | It includes large portions of code written by Radford Neal and available here. 13 | 14 | The code coming from Radford M. Neal is distributed under the following licence: 15 | 16 | Permission is granted for anyone to copy, use, modify, or distribute these programs and accompanying documents for any purpose, provided this copyright notice is retained and prominently displayed, along with a note saying that the original programs are available from Radford Neal’s web page, and note is made of any changes made to these programs. These programs and documents are distributed without any warranty, express or implied. As the programs were written for research purposes only, they have not been tested to the degree that would be advisable in any important application. All use of these programs is entirely at the user’s own risk. 17 | The code coming from INRIA is distributed under the GNU/LGPL licence, with the following additional requirement: 18 | 19 | This copyright notice must be retained and prominently displayed, along with a note saying that the original programs are available from Vincent Roca’s web page, and note is made of any changes made to these programs. 20 | This FEC library can therefore freely be used in any program, commercial or not, open-source or not. 21 | 22 | 23 | === 24 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/ldpc/getopt.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // FILE: getopt.h 4 | // 5 | // Header for the GetOption function 6 | // 7 | // COMMENTS: 8 | // 9 | /////////////////////////////////////////////////////////////////////////////// 10 | 11 | // function prototypes 12 | int GetOption (int argc, char** argv, char* pszValidOpts, char** ppszParam); 13 | 14 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/ldpc/ldpc_create_pchk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The contents of this directory and its sub-directories are 3 | * Copyright (c) 1995-2003 by Radford M. Neal 4 | * 5 | * Permission is granted for anyone to copy, use, modify, or distribute these 6 | * programs and accompanying documents for any purpose, provided this copyright 7 | * notice is retained and prominently displayed, along with a note saying 8 | * that the original programs are available from Radford Neal's web page, and 9 | * note is made of any changes made to these programs. These programs and 10 | * documents are distributed without any warranty, express or implied. As the 11 | * programs were written for research purposes only, they have not been tested 12 | * to the degree that would be advisable in any important application. All use 13 | * of these programs is entirely at the user's own risk. 14 | */ 15 | 16 | 17 | #ifndef LDPC_CREATE_PCHK__ 18 | #define LDPC_CREATE_PCHK__ 19 | 20 | #include "ldpc_matrix_sparse.h" 21 | 22 | typedef enum make_method_enum 23 | { 24 | Evencol, /* Uniform number of bits per column, with number specified */ 25 | Evenboth /* Uniform (as possible) over both columns and rows */ 26 | } make_method; 27 | 28 | 29 | typedef enum SessionType_enum 30 | { 31 | TypeLDGM, 32 | TypeSTAIRS, 33 | TypeTRIANGLE 34 | } SessionType; 35 | 36 | mod2sparse* CreatePchkMatrix ( int nbRows, int nbCols, make_method makeMethod, int leftDegree, int seed, bool no4cycle, SessionType type, int verbosity ); 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/ldpc/ldpc_rand.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1995,1996,1997,1998,2001,2002 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | Contributed by Ulrich Drepper , August 1995. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, write to the Free 17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18 | 02111-1307 USA. */ 19 | 20 | 21 | /** 22 | * Initialize the PRNG with a seed between 1 and 0x7FFFFFFE 23 | * (2^^31-2) inclusive. 24 | */ 25 | void ldpc_srand (unsigned long s); 26 | 27 | /** 28 | * Returns a random integer between 0 and maxv-1 inclusive. 29 | * Derived from rand31pmc, Robin Whittle, Sept 20th 2005. 30 | * http://www.firstpr.com.au/dsp/rand31/ 31 | * 16807 multiplier constant (7^^5) 32 | * 0x7FFFFFFF modulo constant (2^^31-1) 33 | * The inner PRNG produces a value between 1 and 0x7FFFFFFE 34 | * (2^^31-2) inclusive. 35 | * This value is then scaled between 0 and maxv-1 inclusive. 36 | */ 37 | unsigned long ldpc_rand (unsigned long maxv); 38 | 39 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/ldpc/ldpc_types.h: -------------------------------------------------------------------------------- 1 | /* $Id: ldpc_types.h,v 1.1 2006/09/06 14:36:49 roca Exp $ */ 2 | /* 3 | * LDPC/LDGM FEC Library. 4 | * (c) Copyright 2002-2006 INRIA - All rights reserved 5 | * Main authors: Christoph Neumann (christoph.neumann@inrialpes.fr) 6 | * Vincent Roca (vincent.roca@inrialpes.fr) 7 | * Julien Laboure (julien.laboure@inrialpes.fr) 8 | * 9 | * This copyright notice must be retained and prominently displayed, 10 | * along with a note saying that the original programs are available from 11 | * Vincent Roca's web page, and note is made of any changes made to these 12 | * programs. 13 | * 14 | * This library is free software; you can redistribute it and/or 15 | * modify it under the terms of the GNU Lesser General Public 16 | * License as published by the Free Software Foundation; either 17 | * version 2.1 of the License, or (at your option) any later version. 18 | * 19 | * This library is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | * Lesser General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU Lesser General Public 25 | * License along with this library; if not, write to the Free Software 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | */ 28 | 29 | 30 | #ifndef LDPC_TYPES_H 31 | #define LDPC_TYPES_H 32 | 33 | /****** type specifications ******/ 34 | 35 | #ifndef UINT32 36 | #define INT8 char 37 | #define INT16 short 38 | #define UINT8 unsigned char 39 | #define UINT16 unsigned short 40 | #if defined(__LP64__) || (__WORDSIZE == 64) /* 64 bit architectures */ 41 | #define INT32 int // yes, it's also true in LP64! 42 | #define UINT32 unsigned int // yes, it's also true in LP64! 43 | #else /* 32 bit architectures */ 44 | #define INT32 int // int creates less compilations pbs than long 45 | #define UINT32 unsigned int // int creates less compilations pbs than long 46 | #endif /* 32/64 architectures */ 47 | #endif /* !UINT32 */ 48 | 49 | #ifndef UINT64 50 | #ifdef WIN32 51 | #define INT64 __int64 52 | #define UINT64 __uint64 53 | #else /* UNIX */ 54 | #define INT64 long long 55 | #define UINT64 unsigned long long 56 | #endif /* OS */ 57 | #endif /* !UINT64 */ 58 | 59 | 60 | #endif /* LDPC_TYPES_H */ 61 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/ldpc/ldpc_wrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ldpc_wrapper.h 3 | * 4 | * Created on: Mar 5, 2009 5 | * Author: abachrac 6 | */ 7 | 8 | #ifndef LDPC_WRAPPER_H_ 9 | #define LDPC_WRAPPER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "ldpc_fec.h" 20 | #include "ldpc_scheme.h" 21 | #include "macros.h" 22 | 23 | class ldpc_wrapper { 24 | public: 25 | ldpc_wrapper() 26 | { 27 | } 28 | ~ldpc_wrapper(); 29 | 30 | inline int getNumPackets() 31 | { 32 | return nbPKT; 33 | } 34 | 35 | //used for both 36 | int getObject(uint8_t * pktBuf); 37 | 38 | protected: 39 | int init(int objSize_, int pktSize_, double fec_rate_, int typeFlag); 40 | int typeFlag; 41 | 42 | int nbDATA; /* k parameter */ 43 | int nbFEC; /* n - k parameter */ 44 | int nbSYMBOLS; /* n parameter */ 45 | 46 | int pktSize; /* packet size */ 47 | int symbolSize; /* symbol size */ 48 | 49 | int nbSymbolsPerPkt; 50 | int nbDATAPkts; 51 | int nbFECPkts; 52 | int nbPKT; 53 | 54 | int objSize; 55 | double fec_ratio; 56 | LDPCFecScheme * MyFecScheme; 57 | 58 | uint8_t **data; /* filled with original data symbols AND built FEC symbols */ 59 | int packetNum; /* number of packets sent/received */ 60 | 61 | }; 62 | 63 | class ldpc_enc_wrapper: public ldpc_wrapper { 64 | public: 65 | //encoder stuff: 66 | ldpc_enc_wrapper(uint8_t * data_to_send, int objSize, int packetSize, double fec_rate); //initializer for encoder 67 | int getNextPacket(uint8_t * pktBuf, int16_t * ESI); 68 | int encodeData(uint8_t * data_to_send); 69 | }; 70 | 71 | class ldpc_dec_wrapper: public ldpc_wrapper { 72 | public: 73 | //decoder stuff: 74 | ldpc_dec_wrapper(int objSize, int packetSize, double fec_rate); //initializer for decoder 75 | int processPacket(uint8_t * newPkt, int16_t ESI); 76 | }; 77 | #endif /* LDPC_WRAPPER_H_ */ 78 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/ldpc/tools.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The contents of this directory and its sub-directories are 3 | * Copyright (c) 1995-2003 by Radford M. Neal 4 | * 5 | * Permission is granted for anyone to copy, use, modify, or distribute these 6 | * programs and accompanying documents for any purpose, provided this copyright 7 | * notice is retained and prominently displayed, along with a note saying 8 | * that the original programs are available from Radford Neal's web page, and 9 | * note is made of any changes made to these programs. These programs and 10 | * documents are distributed without any warranty, express or implied. As the 11 | * programs were written for research purposes only, they have not been tested 12 | * to the degree that would be advisable in any important application. All use 13 | * of these programs is entirely at the user's own risk. 14 | */ 15 | 16 | 17 | /* This module implements operations on sparse matrices of mod2 elements 18 | (bits, with addition and multiplication being done modulo 2). 19 | 20 | All procedures in this module display an error message on standard 21 | error and terminate the program if passed an invalid argument (indicative 22 | of a programming error), or if memory cannot be allocated. Errors from 23 | invalid contents of a file result in an error code being returned to the 24 | caller, with no message being printed by this module. 25 | */ 26 | 27 | 28 | /* DATA STRUCTURES USED TO STORE A SPARSE MATRIX. Non-zero entries (ie, 1s) 29 | are represented by nodes that are doubly-linked both by row and by column, 30 | with the headers for these lists being kept in arrays. Nodes are allocated 31 | in blocks to reduce time and space overhead. Freed nodes are kept for 32 | reuse in the same matrix, rather than being freed for other uses, except 33 | that they are all freed when the matrix is cleared to all zeros by the 34 | mod2sparse_clear procedure, or copied into by mod2sparse_copy. 35 | 36 | Direct access to these structures should be avoided except in low-level 37 | routines. Use the macros and procedures defined below instead. */ 38 | 39 | #ifndef TOOLS_H__ 40 | #define TOOLS_H__ 41 | 42 | #include 43 | #include 44 | 45 | 46 | void *chk_alloc(unsigned, unsigned); /* Calls 'calloc' and exits with error if it fails */ 47 | 48 | #if 0 49 | int intio_read (FILE *); /* Read an integer */ 50 | void intio_write(FILE *, int); /* Write an integer */ 51 | #endif 52 | 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/signal_pipe.h: -------------------------------------------------------------------------------- 1 | // signal_pipe was copied from bot_core to make lcm_tunnel a standalone pod 2 | 3 | #ifndef __bot_signal_pipe_h__ 4 | #define __bot_signal_pipe_h__ 5 | 6 | /** 7 | * @defgroup BotCoreSignalPipe Signals to pipes 8 | * @brief Receive UNIX signal notifications via pipes 9 | * @ingroup BotCoreIO 10 | * @include: bot_core/bot_core.h 11 | * 12 | * signal_pipe provides convenience wrappers to convert unix signals into glib 13 | * events. 14 | * 15 | * e.g. to catch SIGINT in a gtk callback function, you might do: 16 | * 17 | * 18 | * void handle_sigint (int signal, void *user) { 19 | * printf("caught SIGINT\n"); 20 | * gtk_main_quit(); 21 | * } 22 | * 23 | * int main(int argc, char **argv) { 24 | * gtk_init(); 25 | * bot_signal_pipe_init(); 26 | * bot_signal_pipe_add_signal (SIGINT); 27 | * bot_signal_pipe_attach_glib (handle_sigint, NULL); 28 | * 29 | * gtk_main(); 30 | * 31 | * bot_signal_pipe_destroy(); 32 | * } 33 | * 34 | * 35 | * @{ 36 | */ 37 | 38 | #include 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | typedef void (*bot_signal_pipe_glib_handler_t) (int signal, void *user_data); 45 | 46 | // initializes signal_pipe. call this once per process. 47 | int bot_signal_pipe_init (void); 48 | 49 | // cleans up resources used by the signal_pipe 50 | int bot_signal_pipe_cleanup (void); 51 | 52 | // specifies that signal should be caught by signal_pipe and converted to a 53 | // glib event 54 | void bot_signal_pipe_add_signal (int signal); 55 | 56 | // sets a handler function that is called when a signal is caught by 57 | // signal_pipe. The first argument to the user_func function is the number of 58 | // the signal caught. The second is the user_data parameter passed in here. 59 | int bot_signal_pipe_attach_glib (bot_signal_pipe_glib_handler_t user_func, 60 | gpointer user_data); 61 | 62 | // convenience function to setup a signal handler that calls 63 | // signal_pipe_init, and adds a signal handler that automatically call 64 | // g_main_loop_quit (mainloop) on receiving SIGTERM, SIGINT, or SIGHUP. 65 | // also invokes signal_pipe_cleanup() on receiving these signals. 66 | int bot_signal_pipe_glib_quit_on_kill (GMainLoop *mainloop); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/tunnel/ssocket.h: -------------------------------------------------------------------------------- 1 | #ifndef _SSOCKET_H 2 | #define _SSOCKET_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef struct ssocket ssocket_t; 14 | 15 | struct ssocket 16 | { 17 | int type; 18 | int socket; 19 | 20 | struct sockaddr addr; 21 | socklen_t addrlen; 22 | 23 | }; 24 | 25 | ssocket_t *ssocket_create(void); 26 | void ssocket_destroy(ssocket_t *s); 27 | 28 | // returns < 0 on error 29 | int ssocket_connect(ssocket_t *s, const char *hostname, int port); 30 | 31 | int ssocket_disable_nagle(ssocket_t *s); 32 | int ssocket_listen(ssocket_t *s, int port, int listenqueue, int localhostOnly); 33 | ssocket_t *ssocket_accept(ssocket_t *s); 34 | 35 | /** 36 | * ssocket_get_remote_ip: 37 | * 38 | * retrieves the IP address of the remote end of the connection. each octet of 39 | * the address is stored in a separate array element 40 | */ 41 | void ssocket_get_remote_ip(ssocket_t *s, int ip[4]); 42 | 43 | int ssocket_get_fd(ssocket_t *s); 44 | 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | #endif 50 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/who/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | add_executable(bot-lcm-who 4 | lcm-who.c 5 | signal_pipe.c) 6 | 7 | pods_use_pkg_config_packages(bot-lcm-who 8 | lcm glib-2.0) 9 | 10 | pods_install_executables(bot-lcm-who) 11 | -------------------------------------------------------------------------------- /bot2-lcm-utils/src/who/signal_pipe.h: -------------------------------------------------------------------------------- 1 | #ifndef __signal_pipe_h__ 2 | #define __signal_pipe_h__ 3 | 4 | /* signal_pipe provides convenience wrappers to convert unix signals into glib 5 | * events. 6 | * 7 | * e.g. to catch SIGINT in a gtk callback function, you might do: 8 | * 9 | * void handle_sigint (int signal, void *user) { 10 | * printf("caught SIGINT\n"); 11 | * gtk_main_quit(); 12 | * } 13 | * 14 | * int main(int argc, char **argv) { 15 | * gtk_init(); 16 | * bot_signal_pipe_init(); 17 | * bot_signal_pipe_add_signal (SIGINT); 18 | * bot_signal_pipe_attach_glib (handle_sigint, NULL); 19 | * 20 | * gtk_main(); 21 | * 22 | * bot_signal_pipe_destroy(); 23 | * } 24 | */ 25 | 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | typedef void (*bot_signal_pipe_glib_handler_t) (int signal, void *user_data); 33 | 34 | // initializes signal_pipe. call this once per process. 35 | int bot_signal_pipe_init (void); 36 | 37 | // cleans up resources used by the signal_pipe 38 | int bot_signal_pipe_cleanup (void); 39 | 40 | // specifies that signal should be caught by signal_pipe and converted to a 41 | // glib event 42 | void bot_signal_pipe_add_signal (int signal); 43 | 44 | // sets a handler function that is called when a signal is caught by 45 | // signal_pipe. The first argument to the user_func function is the number of 46 | // the signal caught. The second is the user_data parameter passed in here. 47 | int bot_signal_pipe_attach_glib (bot_signal_pipe_glib_handler_t user_func, 48 | gpointer user_data); 49 | 50 | // convenience function to setup a signal handler that calls 51 | // signal_pipe_init, and adds a signal handler that automatically call 52 | // g_main_loop_quit (mainloop) on receiving SIGTERM, SIGINT, or SIGHUP. 53 | // also invokes signal_pipe_cleanup() on receiving these signals. 54 | int bot_signal_pipe_glib_quit_on_kill (GMainLoop *mainloop); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /bot2-lcmgl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.4.6) 2 | 3 | set(POD_NAME bot2-lcmgl) 4 | 5 | include(cmake/pods.cmake) 6 | 7 | include(cmake/lcmtypes.cmake) 8 | lcmtypes_build(JAVA_DEST_DIR ${PROJECT_SOURCE_DIR}/java/src 9 | PY_DEST_DIR ${PROJECT_SOURCE_DIR}/python/src) 10 | 11 | set(ZLIB_LIBRARIES -lz) 12 | 13 | option(USE_BOT_VIS "Build bot2-lcmgl with libbot dependency." ON) 14 | 15 | add_definitions(-std=gnu99) 16 | 17 | add_subdirectory(src/bot_lcmgl_client) 18 | add_subdirectory(src/bot_lcmgl_render) 19 | 20 | if(USE_BOT_VIS) 21 | add_subdirectory(src/lcmgl-viewer) 22 | endif() 23 | 24 | add_subdirectory(java) 25 | add_subdirectory(python) 26 | -------------------------------------------------------------------------------- /bot2-lcmgl/Makefile: -------------------------------------------------------------------------------- 1 | # Default pod makefile distributed with pods version: 12.09.21 2 | 3 | default_target: all 4 | 5 | # Default to a less-verbose build. If you want all the gory compiler output, 6 | # run "make VERBOSE=1" 7 | $(VERBOSE).SILENT: 8 | 9 | # Figure out where to build the software. 10 | # Use BUILD_PREFIX if it was passed in. 11 | # If not, search up to four parent directories for a 'build' directory. 12 | # Otherwise, use ./build. 13 | ifeq "$(BUILD_PREFIX)" "" 14 | BUILD_PREFIX:=$(shell for pfx in ./ .. ../.. ../../.. ../../../..; do d=`pwd`/$$pfx/build;\ 15 | if [ -d $$d ]; then echo $$d; exit 0; fi; done; echo `pwd`/build) 16 | endif 17 | # create the build directory if needed, and normalize its path name 18 | BUILD_PREFIX:=$(shell mkdir -p $(BUILD_PREFIX) && cd $(BUILD_PREFIX) && echo `pwd`) 19 | 20 | # Default to a release build. If you want to enable debugging flags, run 21 | # "make BUILD_TYPE=Debug" 22 | ifeq "$(BUILD_TYPE)" "" 23 | BUILD_TYPE="Release" 24 | endif 25 | 26 | all: pod-build/Makefile 27 | $(MAKE) -C pod-build all install 28 | 29 | pod-build/Makefile: 30 | $(MAKE) configure 31 | 32 | .PHONY: configure 33 | configure: 34 | @echo "\nBUILD_PREFIX: $(BUILD_PREFIX)\n\n" 35 | 36 | # create the temporary build directory if needed 37 | @mkdir -p pod-build 38 | 39 | # run CMake to generate and configure the build scripts 40 | @cd pod-build && cmake -DCMAKE_INSTALL_PREFIX=$(BUILD_PREFIX) \ 41 | -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) .. 42 | 43 | clean: 44 | -if [ -e pod-build/install_manifest.txt ]; then rm -f `cat pod-build/install_manifest.txt`; fi 45 | -if [ -d pod-build ]; then $(MAKE) -C pod-build clean; rm -rf pod-build; fi 46 | 47 | # other (custom) targets are passed through to the cmake-generated Makefile 48 | %:: 49 | $(MAKE) -C pod-build $@ -------------------------------------------------------------------------------- /bot2-lcmgl/README: -------------------------------------------------------------------------------- 1 | This software is constructed according to the Pods software policies and 2 | templates. The policies and templates can be found at: 3 | 4 | http://sourceforge.net/projects/pods 5 | 6 | ==== 7 | 8 | Name: bot2-lcmgl 9 | Maintainers: 10 | Summary: Transmit OpenGL commands over LCM, and render them elsewhere. 11 | Description: 12 | bot2-lcmgl contains a set of client libraries in C, Java, and Python 13 | for transmitting OpenGL commands over LCM. It also provides routines 14 | for receiving and rendering these commands in either a standalone 15 | application (bot-lcmgl-viewer), or incorporated into another 16 | C/C++ application. 17 | 18 | A nice attribute of the client libraries is that they do not depend on 19 | any OpenGL libraries, and only require LCM. 20 | 21 | Requirements: FILL-ME-IN 22 | General requirements: 23 | 24 | LCM 25 | GTK+ (>= 2.0) 26 | OpenGL 27 | GLUT / FreeGLUT 28 | Java 29 | Python 30 | 31 | Requires the following pods, which are distributed as part of libbot2: 32 | 33 | bot2-core 34 | bot2-vis 35 | -------------------------------------------------------------------------------- /bot2-lcmgl/java/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Java) 2 | if(JAVA_COMPILE STREQUAL JAVA_COMPILE-NOTFOUND OR 3 | JAVA_ARCHIVE STREQUAL JAVA_ARCHIVE-NOTFOUND OR 4 | JAVA_COMPILE STREQUAL Java_JAVAC_EXECUTABLE-NOTFOUND OR 5 | JAVA_ARCHIVE STREQUAL Java_JAR_EXECUTABLE-NOTFOUND) 6 | message(STATUS "Java not found... not building lcmgl java bindings") 7 | return() 8 | endif() 9 | 10 | set(java_dir ${CMAKE_CURRENT_SOURCE_DIR}/src) 11 | set(class_dir ${CMAKE_CURRENT_BINARY_DIR}/java-build) 12 | set(jar_fname bot2-lcmgl.jar) 13 | 14 | # where is lcm.jar? 15 | execute_process(COMMAND pkg-config --variable=classpath lcm-java 16 | OUTPUT_VARIABLE LCM_JAR_FILE) 17 | if (NOT LCM_JAR_FILE) 18 | message(STATUS "\n\n----- ERROR: lcm-java not found. Not building bot-spy plugins") 19 | return() 20 | endif() 21 | string(STRIP ${LCM_JAR_FILE} LCM_JAR_FILE) 22 | 23 | set(classpath ${java_dir}:${LCM_JAR_FILE}) 24 | 25 | 26 | # ============= shouldn't need to modify anything below this line ============= 27 | 28 | # get a list of all .java files 29 | file(GLOB_RECURSE java_files ${java_dir}/*.java) 30 | 31 | # convert the list of .java filenames to a list of .class filenames 32 | foreach(javafile ${java_files}) 33 | string(REPLACE .java .class tmp_fname ${javafile}) 34 | string(REPLACE ${java_dir} ${class_dir} tmp_fname ${tmp_fname}) 35 | list(APPEND class_files ${tmp_fname}) 36 | endforeach() 37 | 38 | # create the java build directory if needed 39 | if(NOT IS_DIRECTORY ${class_dir}) 40 | file(MAKE_DIRECTORY ${class_dir}) 41 | endif() 42 | 43 | # add a rule to build the .class files from from the .java files 44 | add_custom_command(OUTPUT ${class_files} COMMAND 45 | ${JAVA_COMPILE} -source 6 -target 6 -cp ${classpath} -d ${class_dir} ${java_files} 46 | DEPENDS ${java_files} VERBATIM) 47 | 48 | # add a rule to build a .jar file from the .class files 49 | add_custom_command(OUTPUT ${jar_fname} COMMAND 50 | ${JAVA_ARCHIVE} cf ${jar_fname} -C ${class_dir} . 51 | DEPENDS ${class_files} VERBATIM) 52 | add_custom_target(jar ALL DEPENDS ${jar_fname}) 53 | 54 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${jar_fname} DESTINATION share/java) 55 | -------------------------------------------------------------------------------- /bot2-lcmgl/lcmtypes/bot_lcmgl_data_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_lcmgl; 2 | 3 | struct data_t 4 | { 5 | string name; // name of the image data 6 | int32_t scene; // incremented for each buffer flip 7 | int32_t sequence; // message number in this buffer 8 | 9 | int32_t datalen; // raw data goes here 10 | byte data[datalen]; 11 | } 12 | -------------------------------------------------------------------------------- /bot2-lcmgl/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(PythonInterp REQUIRED) 2 | 3 | # install all python packages in the src/ directory 4 | pods_install_python_packages(${CMAKE_CURRENT_SOURCE_DIR}/src) 5 | 6 | # executable scripts: 7 | #pods_install_python_script(script-name python-module) 8 | 9 | -------------------------------------------------------------------------------- /bot2-lcmgl/python/src/bot_lcmgl/__init__.py: -------------------------------------------------------------------------------- 1 | from data_t import data_t 2 | 3 | from lcmgl import * 4 | from .data_t import data_t 5 | -------------------------------------------------------------------------------- /bot2-lcmgl/src/bot_lcmgl_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | file(GLOB c_files *.c) 4 | file(GLOB h_files *.h) 5 | 6 | set(libname bot2-lcmgl-client) 7 | 8 | add_library(${libname} SHARED ${c_files}) 9 | 10 | #set(REQUIRED_LIBS ${LIBJPEG_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES}) 11 | target_link_libraries(${libname} ${ZLIB_LIBRARIES}) 12 | 13 | set(REQUIRED_PACKAGES glib-2.0 lcm) 14 | pods_use_pkg_config_packages(${libname} ${REQUIRED_PACKAGES}) 15 | target_link_libraries(${libname} lcmtypes_bot2-lcmgl) 16 | list(APPEND REQUIRED_PACKAGES lcmtypes_bot2-lcmgl) 17 | 18 | # set the library API version. Increment this every time the public API 19 | # changes. 20 | set_target_properties(${libname} PROPERTIES SOVERSION 1) 21 | 22 | # make both the shared library public 23 | pods_install_libraries(${libname}) 24 | 25 | pods_install_headers(${h_files} DESTINATION bot_lcmgl_client) 26 | 27 | pods_install_pkg_config_file(bot2-lcmgl-client 28 | LIBS -l${libname} 29 | REQUIRES ${REQUIRED_PACKAGES} 30 | VERSION 0.0.1) 31 | -------------------------------------------------------------------------------- /bot2-lcmgl/src/bot_lcmgl_render/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | set(c_files lcmgl_decode.c) 4 | set(h_files lcmgl_decode.h) 5 | set(REQUIRED_LIBS) 6 | 7 | if (USE_BOT_VIS) 8 | list(APPEND c_files lcmgl_bot_renderer.c) 9 | list(APPEND h_files lcmgl_bot_renderer.h) 10 | list(APPEND REQUIRED_LIBS bot2-vis gl) 11 | add_definitions(-DUSE_BOT_VIS) 12 | endif() 13 | 14 | 15 | add_library(bot2-lcmgl-renderer SHARED ${c_files}) 16 | 17 | find_package(OpenGL REQUIRED) 18 | target_link_libraries(bot2-lcmgl-renderer ${OPENGL_LIBRARIES} lcmtypes_bot2-lcmgl) 19 | 20 | if(REQUIRED_LIBS) 21 | pods_use_pkg_config_packages(bot2-lcmgl-renderer ${REQUIRED_LIBS}) 22 | endif() 23 | 24 | list(APPEND REQUIRED_LIBS lcmtypes_bot2-lcmgl) 25 | 26 | 27 | # set the library API version. Increment this every time the public API 28 | # changes. 29 | set_target_properties(bot2-lcmgl-renderer PROPERTIES SOVERSION 1) 30 | 31 | pods_install_libraries(bot2-lcmgl-renderer) 32 | 33 | pods_install_headers(${h_files} DESTINATION bot_lcmgl_render) 34 | 35 | pods_install_pkg_config_file(bot2-lcmgl-renderer 36 | LIBS -lbot2-lcmgl-renderer 37 | REQUIRES ${REQUIRED_LIBS} 38 | VERSION 0.0.1) 39 | -------------------------------------------------------------------------------- /bot2-lcmgl/src/bot_lcmgl_render/lcmgl_bot_renderer.h: -------------------------------------------------------------------------------- 1 | #ifndef __lcmgl_bot_renderer_h__ 2 | #define __lcmgl_bot_renderer_h__ 3 | 4 | /** 5 | * @defgroup BotLCMGLViewerRenderer BotViewer renderer 6 | * @ingroup BotLCMGL 7 | * @brief BotVis Viewer renderer plugin 8 | * @include bot_lcmgl_render/lcmgl_bot_renderer.h 9 | * 10 | * TODO 11 | * 12 | * Linking: `pkg-config --libs bot2-lcmgl-renderer` 13 | * @{ 14 | */ 15 | 16 | #include 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | void bot_lcmgl_add_renderer_to_viewer(BotViewer* viewer, lcm_t* lcm, int priority); 25 | 26 | /** 27 | * @} 28 | */ 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /bot2-lcmgl/src/bot_lcmgl_render/lcmgl_decode.h: -------------------------------------------------------------------------------- 1 | #ifndef _BOT_LCMGL_DECODE_H 2 | #define _BOT_LCMGL_DECODE_H 3 | 4 | #include 5 | 6 | /** 7 | * @defgroup BotLCMGLRender LCMGL decoding and rendering 8 | * @ingroup BotLCMGL 9 | * @brief Executing OpenGL commands received via LCMGL 10 | * @include bot_lcmgl_render/lcmgl_decode.h 11 | * 12 | * TODO 13 | * 14 | * Linking: `pkg-config --libs bot2-lcmgl-renderer` 15 | * 16 | * @{ 17 | */ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * bot_lcmgl_decode: 25 | * 26 | * Decodes a block of LCMGL data, and executes the OpenGL commands with 27 | * the current OpenGL context. 28 | */ 29 | void bot_lcmgl_decode(uint8_t *data, int datalen); 30 | 31 | /** 32 | * @} 33 | */ 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /bot2-lcmgl/src/lcmgl-viewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | include_directories(${PROJECT_SOURCE_DIR}/src/) 4 | add_executable(bot-lcmgl-viewer 5 | main.c 6 | udp_util.c 7 | view_menu.c 8 | ) 9 | target_link_libraries(bot-lcmgl-viewer bot2-lcmgl-renderer) 10 | pods_use_pkg_config_packages(bot-lcmgl-viewer bot2-vis) 11 | 12 | 13 | pods_install_executables(bot-lcmgl-viewer) 14 | -------------------------------------------------------------------------------- /bot2-lcmgl/src/lcmgl-viewer/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include "udp_util.h" 10 | #include "view_menu.h" 11 | 12 | typedef struct { 13 | BotViewer *viewer; 14 | lcm_t *lcm; 15 | } state_t; 16 | 17 | static int 18 | logplayer_remote_on_key_press(BotViewer *viewer, BotEventHandler *ehandler, 19 | const GdkEventKey *event) 20 | { 21 | int keyval = event->keyval; 22 | 23 | switch (keyval) 24 | { 25 | case 'P': 26 | case 'p': 27 | udp_send_string("127.0.0.1", 53261, "PLAYPAUSETOGGLE"); 28 | break; 29 | case 'N': 30 | case 'n': 31 | udp_send_string("127.0.0.1", 53261, "STEP"); 32 | break; 33 | case '=': 34 | case '+': 35 | udp_send_string("127.0.0.1", 53261, "FASTER"); 36 | break; 37 | case '_': 38 | case '-': 39 | udp_send_string("127.0.0.1", 53261, "SLOWER"); 40 | break; 41 | case '[': 42 | udp_send_string("127.0.0.1", 53261, "BACK5"); 43 | break; 44 | case ']': 45 | udp_send_string("127.0.0.1", 53261, "FORWARD5"); 46 | break; 47 | default: 48 | return 0; 49 | } 50 | 51 | return 1; 52 | } 53 | 54 | ///////////////////////////////////////////////////////////// 55 | 56 | int main(int argc, char *argv[]) 57 | { 58 | gtk_init(&argc, &argv); 59 | glutInit(&argc, argv); 60 | g_thread_init(NULL); 61 | 62 | setlinebuf(stdout); 63 | 64 | state_t app; 65 | memset(&app, 0, sizeof(app)); 66 | 67 | BotViewer *viewer = bot_viewer_new("Viewer"); 68 | app.viewer = viewer; 69 | app.lcm = lcm_create(NULL); 70 | bot_glib_mainloop_attach_lcm(app.lcm); 71 | 72 | setup_view_menu(viewer); 73 | 74 | // setup renderers 75 | bot_viewer_add_stock_renderer(viewer, BOT_VIEWER_STOCK_RENDERER_GRID, 1); 76 | bot_lcmgl_add_renderer_to_viewer(viewer, app.lcm, 0); 77 | 78 | // logplayer controls 79 | BotEventHandler *ehandler = (BotEventHandler*) calloc(1, sizeof(BotEventHandler)); 80 | ehandler->name = "LogPlayer Remote"; 81 | ehandler->enabled = 1; 82 | ehandler->key_press = logplayer_remote_on_key_press; 83 | bot_viewer_add_event_handler(viewer, ehandler, 0); 84 | 85 | // load saved preferences 86 | char *fname = g_build_filename(g_get_user_config_dir(), 87 | ".lcmgl-viewerrc", NULL); 88 | bot_viewer_load_preferences(viewer, fname); 89 | 90 | // run the main loop 91 | gtk_main(); 92 | 93 | // save any changed preferences 94 | bot_viewer_save_preferences(viewer, fname); 95 | free(fname); 96 | 97 | // cleanup 98 | bot_viewer_unref(viewer); 99 | } 100 | -------------------------------------------------------------------------------- /bot2-lcmgl/src/lcmgl-viewer/udp_util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "udp_util.h" 14 | 15 | /** make and bind a udp socket to a specified port. Returns the fd. **/ 16 | int udp_socket_listen(int port) 17 | { 18 | int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 19 | if (sock < 0) 20 | return -1; 21 | 22 | struct sockaddr_in listen_addr; 23 | memset(&listen_addr, 0, sizeof(struct sockaddr_in)); 24 | listen_addr.sin_family = AF_INET; 25 | listen_addr.sin_port = htons(port); 26 | listen_addr.sin_addr.s_addr = INADDR_ANY; 27 | 28 | int res = bind(sock, (struct sockaddr*) &listen_addr, sizeof(struct sockaddr_in)); 29 | if (res < 0) 30 | return -2; 31 | 32 | return sock; 33 | } 34 | 35 | /** make and bind a udp socket to an ephemeral port. Returns the fd. **/ 36 | int udp_socket_create(void) 37 | { 38 | int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 39 | if (sock < 0) 40 | return -1; 41 | 42 | struct sockaddr_in listen_addr; 43 | memset(&listen_addr, 0, sizeof(struct sockaddr_in)); 44 | listen_addr.sin_family = AF_INET; 45 | listen_addr.sin_port = INADDR_ANY; // ephemeral port, please 46 | listen_addr.sin_addr.s_addr = INADDR_ANY; 47 | 48 | int res = bind(sock, (struct sockaddr*) &listen_addr, sizeof(struct sockaddr_in)); 49 | if (res < 0) 50 | return -2; 51 | 52 | return sock; 53 | } 54 | 55 | /** return the local port number for a socket. **/ 56 | int udp_socket_get_port(int sock) 57 | { 58 | struct sockaddr_in addr; 59 | socklen_t addr_len = sizeof(addr); 60 | 61 | int res = getsockname(sock, (struct sockaddr*) &addr, &addr_len); 62 | 63 | if (res < 0) 64 | return -1; 65 | 66 | return ntohs(addr.sin_port); 67 | } 68 | 69 | // return 0 on success 70 | int udp_send(const char *ipaddr, int port, const void *data, int datalen) 71 | { 72 | // fill in address structure 73 | struct sockaddr_in remote_addr; 74 | 75 | memset(&remote_addr, 0, sizeof(struct sockaddr_in)); 76 | remote_addr.sin_family = AF_INET; 77 | remote_addr.sin_port = htons(port); 78 | 79 | struct hostent *host = gethostbyname(ipaddr); 80 | if (host == NULL) { 81 | printf("Couldn't resolve host %s\n", ipaddr); 82 | return -1; 83 | } 84 | 85 | memcpy(&remote_addr.sin_addr.s_addr, host->h_addr, host->h_length); 86 | 87 | // now actually send. 88 | int sock = udp_socket_create(); 89 | ssize_t res = sendto(sock, data, datalen, 0, (struct sockaddr*) &remote_addr, sizeof(remote_addr)); 90 | 91 | // cleanup 92 | close(sock); 93 | return res != datalen; 94 | } 95 | -------------------------------------------------------------------------------- /bot2-lcmgl/src/lcmgl-viewer/udp_util.h: -------------------------------------------------------------------------------- 1 | #ifndef _UDPUTIL_H 2 | #define _UDPUTIL_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /** make and bind a udp socket to an ephemeral port. Returns the fd. **/ 9 | int udp_socket_create(void); 10 | 11 | /** make and bind a udp socket to a specified port. Returns the fd. **/ 12 | int udp_socket_listen(int port); 13 | 14 | /** return the local port number for a socket. **/ 15 | int udp_socket_get_port(int sock); 16 | 17 | // convenience method that sends a one-off udp message 18 | // return 0 on success 19 | int udp_send(const char *ipaddr, int port, const void *data, int datalen); 20 | 21 | #define udp_send_string(ipaddr, port, string) udp_send(ipaddr, port, string, strlen(string)) 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /bot2-lcmgl/src/lcmgl-viewer/view_menu.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | void setup_view_menu(BotViewer *viewer); 7 | 8 | static void 9 | on_setview_y_up_item(GtkMenuItem *mi, void *user) 10 | { 11 | BotViewer *viewer = (BotViewer*)user; 12 | double eye[] = { 0, 0, 50 }; 13 | double lookat[] = { 0, 0, 0 }; 14 | double up[] = { 0, 1, 0 }; 15 | if(viewer->view_handler) 16 | viewer->view_handler->set_look_at(viewer->view_handler, eye, lookat, up); 17 | } 18 | 19 | static void 20 | on_setview_x_up_item(GtkMenuItem *mi, void *user) 21 | { 22 | BotViewer *viewer = (BotViewer*)user; 23 | double eye[] = { 0, 0, 50 }; 24 | double lookat[] = { 0, 0, 0 }; 25 | double up[] = { 1, 0, 0 }; 26 | if(viewer->view_handler) 27 | viewer->view_handler->set_look_at(viewer->view_handler, eye, lookat, up); 28 | } 29 | 30 | void 31 | setup_view_menu(BotViewer *viewer) 32 | { 33 | GtkWidget *view_menu = viewer->view_menu; 34 | 35 | // bookmarks 36 | 37 | gtk_menu_append(GTK_MENU(view_menu), gtk_separator_menu_item_new()); 38 | 39 | // predefined viewpoints 40 | GtkWidget *setview_y_up_item = gtk_menu_item_new_with_mnemonic("Y axis up"); 41 | gtk_menu_append(GTK_MENU(view_menu), setview_y_up_item); 42 | g_signal_connect(G_OBJECT(setview_y_up_item), "activate", 43 | G_CALLBACK(on_setview_y_up_item), viewer); 44 | 45 | // predefined viewpoints 46 | GtkWidget *setview_x_up_item = gtk_menu_item_new_with_mnemonic("X axis up"); 47 | gtk_menu_append(GTK_MENU(view_menu), setview_x_up_item); 48 | g_signal_connect(G_OBJECT(setview_x_up_item), "activate", 49 | G_CALLBACK(on_setview_x_up_item), viewer); 50 | 51 | gtk_widget_show_all(view_menu); 52 | } 53 | -------------------------------------------------------------------------------- /bot2-lcmgl/src/lcmgl-viewer/view_menu.h: -------------------------------------------------------------------------------- 1 | #ifndef __libbot2_bot_vis_view_menu_h__ 2 | #define __libbot2_bot_vis_view_menu_h__ 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | void setup_view_menu(BotViewer *viewer); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /bot2-param/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6.0) 2 | 3 | set(POD_NAME bot2-param) 4 | 5 | include(cmake/pods.cmake) 6 | pods_config_search_paths() 7 | 8 | # automatically build LCM types. This also defines a number of CMake 9 | # variables, see cmake/lcmtypes.cmake for details 10 | include(cmake/lcmtypes.cmake) 11 | lcmtypes_build() 12 | 13 | add_subdirectory(src/param_client) 14 | add_subdirectory(src/param_server) 15 | add_subdirectory(src/param_tester) 16 | -------------------------------------------------------------------------------- /bot2-param/Makefile: -------------------------------------------------------------------------------- 1 | # Default pod makefile distributed with pods version: 12.09.21 2 | 3 | default_target: all 4 | 5 | # Default to a less-verbose build. If you want all the gory compiler output, 6 | # run "make VERBOSE=1" 7 | $(VERBOSE).SILENT: 8 | 9 | # Figure out where to build the software. 10 | # Use BUILD_PREFIX if it was passed in. 11 | # If not, search up to four parent directories for a 'build' directory. 12 | # Otherwise, use ./build. 13 | ifeq "$(BUILD_PREFIX)" "" 14 | BUILD_PREFIX:=$(shell for pfx in ./ .. ../.. ../../.. ../../../..; do d=`pwd`/$$pfx/build;\ 15 | if [ -d $$d ]; then echo $$d; exit 0; fi; done; echo `pwd`/build) 16 | endif 17 | # create the build directory if needed, and normalize its path name 18 | BUILD_PREFIX:=$(shell mkdir -p $(BUILD_PREFIX) && cd $(BUILD_PREFIX) && echo `pwd`) 19 | 20 | # Default to a release build. If you want to enable debugging flags, run 21 | # "make BUILD_TYPE=Debug" 22 | ifeq "$(BUILD_TYPE)" "" 23 | BUILD_TYPE="Release" 24 | endif 25 | 26 | all: pod-build/Makefile 27 | $(MAKE) -C pod-build all install 28 | 29 | pod-build/Makefile: 30 | $(MAKE) configure 31 | 32 | .PHONY: configure 33 | configure: 34 | @echo "\nBUILD_PREFIX: $(BUILD_PREFIX)\n\n" 35 | 36 | # create the temporary build directory if needed 37 | @mkdir -p pod-build 38 | 39 | # run CMake to generate and configure the build scripts 40 | @cd pod-build && cmake -DCMAKE_INSTALL_PREFIX=$(BUILD_PREFIX) \ 41 | -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) .. 42 | 43 | clean: 44 | -if [ -e pod-build/install_manifest.txt ]; then rm -f `cat pod-build/install_manifest.txt`; fi 45 | -if [ -d pod-build ]; then $(MAKE) -C pod-build clean; rm -rf pod-build; fi 46 | 47 | # other (custom) targets are passed through to the cmake-generated Makefile 48 | %:: 49 | $(MAKE) -C pod-build $@ -------------------------------------------------------------------------------- /bot2-param/README: -------------------------------------------------------------------------------- 1 | This software is constructed according to the Pods software policies and 2 | templates. The policies and templates can be found at: 3 | 4 | http://sourceforge.net/projects/pods 5 | 6 | ==== 7 | 8 | Name: bot2-param 9 | Maintainers: FILL-ME-IN 10 | Summary: FILL-ME-IN 11 | Description: FILL-ME-IN 12 | 13 | 14 | Requirements: FILL-ME-IN 15 | -------------------------------------------------------------------------------- /bot2-param/lcmtypes/README.txt: -------------------------------------------------------------------------------- 1 | Place LCM type definitions in this directory. 2 | 3 | Each type should be named as: 4 | 5 | typename.lcm 6 | 7 | To automatically build message types from CMake, add the following lines to 8 | the root CMakeLists.txt file: 9 | 10 | include(cmake/lcmtypes.cmake) 11 | lcmtypes_build() 12 | 13 | # automatically build LCM types. This also defines a number of CMake 14 | # variables, see cmake/lcmtypes.cmake for details 15 | -------------------------------------------------------------------------------- /bot2-param/lcmtypes/bot_param_entry_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_param; 2 | 3 | struct entry_t 4 | { 5 | string key; //the key for this entry 6 | string value; //string containing the value for that key 7 | } -------------------------------------------------------------------------------- /bot2-param/lcmtypes/bot_param_request_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_param; 2 | 3 | struct request_t 4 | { 5 | int64_t utime; 6 | //not sure there is anything else to include... 7 | 8 | } 9 | -------------------------------------------------------------------------------- /bot2-param/lcmtypes/bot_param_set_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_param; 2 | 3 | struct set_t 4 | { 5 | int64_t utime; 6 | 7 | int64_t server_id; //The unique identifier for this param-server, 8 | int32_t sequence_number; //The version number of the last_param_file seen by sender 9 | 10 | int32_t numEntries; //number of keys that should be set 11 | bot_param.entry_t entries[numEntries]; //the key,value pairs to set 12 | } -------------------------------------------------------------------------------- /bot2-param/lcmtypes/bot_param_update_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_param; 2 | 3 | struct update_t 4 | { 5 | int64_t utime; 6 | 7 | int64_t server_id; //The unique identifier for this param-server, 8 | int32_t sequence_number; //The version number of the params 9 | 10 | string params; //string containing ALL params 11 | } 12 | 13 | -------------------------------------------------------------------------------- /bot2-param/src/param_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | add_library(bot2-param-client SHARED 4 | param_internal.c param_util.c) 5 | 6 | set(REQUIRED_LIBS lcm bot2-core glib-2.0) 7 | target_link_libraries(bot2-param-client lcmtypes_bot2-param) 8 | pods_use_pkg_config_packages(bot2-param-client ${REQUIRED_LIBS}) 9 | list(APPEND REQUIRED_LIBS lcmtypes_bot2-param) 10 | 11 | # set the library API version. Increment this every time the public API 12 | # changes. 13 | set_target_properties(bot2-param-client PROPERTIES SOVERSION 1) 14 | 15 | # make the header public 16 | pods_install_headers(param_client.h param_util.h DESTINATION bot_param) 17 | 18 | # make the library public 19 | pods_install_libraries(bot2-param-client) 20 | 21 | # create a pkg-config file for the library, to make it for other software to 22 | # use it. 23 | pods_install_pkg_config_file(bot2-param-client 24 | LIBS -lbot2-param-client 25 | REQUIRES ${REQUIRED_LIBS} 26 | VERSION 0.0.1) 27 | -------------------------------------------------------------------------------- /bot2-param/src/param_client/misc_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * misc_utils.h 3 | * 4 | * Created on: Oct 2, 2010 5 | * Author: abachrac 6 | */ 7 | #include 8 | #include 9 | #include 10 | 11 | #ifndef MISC_UTILS_H_ 12 | #define MISC_UTILS_H_ 13 | 14 | /** 15 | * lcm_sleep: 16 | * @lcm: The lcm_t object. 17 | * @sleeptime max time to wait in seconds 18 | * 19 | * Waits for up to @sleeptime seconds for an LCM message to arrive. 20 | * It handles the first message if one arrives. 21 | * 22 | */ 23 | static inline void lcm_sleep(lcm_t * lcm, double sleeptime) 24 | { // 25 | int lcm_fileno = lcm_get_fileno(lcm); 26 | 27 | fd_set rfds; 28 | int retval; 29 | FD_ZERO(&rfds); 30 | FD_SET(lcm_fileno, &rfds); 31 | struct timeval tv; 32 | tv.tv_sec = (int) sleeptime; 33 | tv.tv_usec = (int) ((sleeptime - tv.tv_sec) * 1.0e6); 34 | retval = select(lcm_fileno + 1, &rfds, NULL, NULL, &tv); 35 | if (retval == -1) { 36 | fprintf(stderr, "bot_lcm_poll: select() failed!\n"); 37 | return; 38 | } 39 | if (retval) { 40 | if (FD_ISSET(lcm_fileno, &rfds)) { 41 | lcm_handle(lcm); 42 | } 43 | } 44 | } 45 | 46 | static inline int64_t _timestamp_now() 47 | { 48 | struct timeval tv; 49 | gettimeofday(&tv, NULL); 50 | return (int64_t) tv.tv_sec * 1000000 + tv.tv_usec; 51 | } 52 | 53 | 54 | #endif /* MISC_UTILS_H_ */ 55 | -------------------------------------------------------------------------------- /bot2-param/src/param_server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | # Create an executable program bot-param-server 4 | add_executable(bot-param-server param_server.c lcm_util.c) 5 | pods_use_pkg_config_packages(bot-param-server lcm glib-2.0) 6 | target_link_libraries(bot-param-server bot2-param-client) 7 | 8 | # Create an executable program bot-param-tool 9 | add_executable(bot-param-tool param_tool.c) 10 | pods_use_pkg_config_packages(bot-param-tool lcm) 11 | target_link_libraries(bot-param-tool bot2-param-client) 12 | 13 | # make executables public 14 | pods_install_executables(bot-param-server bot-param-tool) 15 | 16 | -------------------------------------------------------------------------------- /bot2-param/src/param_server/lcm_util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "lcm_util.h" 6 | 7 | //#define dbg(...) fprintf (stderr, __VA_ARGS__) 8 | #define dbg(...) 9 | 10 | static int 11 | lcm_message_ready (GIOChannel *source, GIOCondition cond, lcm_t *lcm) 12 | { 13 | lcm_handle (lcm); 14 | return TRUE; 15 | } 16 | 17 | typedef struct { 18 | GIOChannel *ioc; 19 | guint sid; 20 | lcm_t *lcm; 21 | } glib_attached_lcm_t; 22 | 23 | static GHashTable *lcm_glib_sources = NULL; 24 | 25 | int 26 | lcmu_glib_mainloop_attach_lcm (lcm_t *lcm) 27 | { 28 | if (!lcm_glib_sources) { 29 | lcm_glib_sources = g_hash_table_new (g_direct_hash, g_direct_equal); 30 | } 31 | 32 | if (g_hash_table_lookup (lcm_glib_sources, lcm)) { 33 | dbg ("lcm %p already attached to mainloop\n", lcm); 34 | return -1; 35 | } 36 | 37 | glib_attached_lcm_t *galcm = 38 | (glib_attached_lcm_t*) calloc (1, sizeof (glib_attached_lcm_t)); 39 | 40 | galcm->ioc = g_io_channel_unix_new (lcm_get_fileno (lcm)); 41 | galcm->sid = g_io_add_watch (galcm->ioc, G_IO_IN, (GIOFunc) lcm_message_ready, 42 | lcm); 43 | galcm->lcm = lcm; 44 | 45 | dbg ("inserted lcm %p into glib mainloop\n", lcm); 46 | g_hash_table_insert (lcm_glib_sources, lcm, galcm); 47 | return 0; 48 | } 49 | 50 | int 51 | lcmu_glib_mainloop_detach_lcm (lcm_t *lcm) 52 | { 53 | if (!lcm_glib_sources) { 54 | dbg ("no lcm glib sources\n"); 55 | return -1; 56 | } 57 | 58 | glib_attached_lcm_t *galcm = 59 | (glib_attached_lcm_t*) g_hash_table_lookup (lcm_glib_sources, lcm); 60 | 61 | if (!galcm) { 62 | dbg ("couldn't find matching galcm\n"); 63 | return -1; 64 | } 65 | 66 | dbg ("detaching lcm from glib\n"); 67 | g_io_channel_unref (galcm->ioc); 68 | g_source_remove (galcm->sid); 69 | 70 | g_hash_table_remove (lcm_glib_sources, lcm); 71 | free (galcm); 72 | 73 | if (g_hash_table_size (lcm_glib_sources) == 0) { 74 | g_hash_table_destroy (lcm_glib_sources); 75 | lcm_glib_sources = NULL; 76 | } 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /bot2-param/src/param_server/lcm_util.h: -------------------------------------------------------------------------------- 1 | #ifndef __lc_util_h__ 2 | #define __lc_util_h__ 3 | 4 | #include 5 | 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /** 13 | * lcu_mainloop_attach_lc (lc_t *lc) 14 | * attaches/detaches LC to/from the glib mainloop 15 | * When attached, lc_handle() is invoked "automatically" when a message is 16 | * received over LC. 17 | * 18 | * only one instance of lc_t can be attached per process 19 | * 20 | * returns 0 on success, -1 on failure 21 | */ 22 | int lcmu_glib_mainloop_attach_lcm (lcm_t *lcm); 23 | 24 | int lcmu_glib_mainloop_detach_lcm (lcm_t *lcm); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /bot2-param/src/param_server/param_tool.c: -------------------------------------------------------------------------------- 1 | /* 2 | * conf_tester.cpp 3 | * 4 | * Created on: Sep 13, 2010 5 | * Author: abachrac 6 | */ 7 | // reading a complete binary file 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "../param_client/param_internal.h" 17 | #include "../param_client/misc_utils.h" 18 | 19 | #include 20 | 21 | int main(int argc, char ** argv) 22 | { 23 | 24 | lcm_t * lcm = lcm_create(NULL); //TODO: provider options? 25 | 26 | if (argc != 3) { 27 | fprintf(stderr, "usage:\n %s \n", argv[0]); 28 | exit(1); 29 | } 30 | 31 | BotParam * param = bot_param_new_from_server(lcm, 0); 32 | bot_param_set_t msg; 33 | msg.utime = _timestamp_now(); 34 | msg.sequence_number = bot_param_get_seqno(param); 35 | msg.server_id = bot_param_get_server_id(param); 36 | bot_param_entry_t entry; 37 | entry.key = argv[1]; 38 | entry.value = argv[2]; 39 | msg.numEntries = 1; 40 | msg.entries = &entry; 41 | 42 | char *param_prefix = getenv ("BOT_PARAM_SERVER_NAME"); 43 | gchar *set_channel = g_strconcat (param_prefix ? : "", 44 | BOT_PARAM_SET_CHANNEL, NULL); 45 | bot_param_set_t_publish(lcm, set_channel, &msg); 46 | g_free (param_prefix); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /bot2-param/src/param_tester/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | # Create an executable program param-tester 4 | add_executable(param-tester param_tester.c) 5 | pods_use_pkg_config_packages(param-tester lcm glib-2.0) 6 | target_link_libraries(param-tester bot2-param-client) 7 | 8 | # Create an executable program param-tester 9 | add_executable(bot-param-dump param_dump.c) 10 | pods_use_pkg_config_packages(bot-param-dump lcm glib-2.0) 11 | target_link_libraries(bot-param-dump bot2-param-client) 12 | 13 | # make executable public 14 | pods_install_executables(bot-param-dump) 15 | -------------------------------------------------------------------------------- /bot2-param/src/param_tester/param_dump.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include "../param_client/param_internal.h" 7 | 8 | static void _on_param_update(const lcm_recv_buf_t *rbuf, const char * channel, const bot_param_update_t * msg, 9 | void * user) 10 | { 11 | 12 | printf("%s", msg->params); 13 | exit(1); 14 | } 15 | 16 | int main() 17 | { 18 | lcm_t * lcm = lcm_create(NULL); 19 | 20 | bot_param_update_t_subscribe(lcm, BOT_PARAM_UPDATE_CHANNEL, _on_param_update, NULL); 21 | 22 | while (1) 23 | lcm_handle(lcm); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /bot2-param/src/param_tester/param_tester.c: -------------------------------------------------------------------------------- 1 | /* 2 | * conf_tester.cpp 3 | * 4 | * Created on: Sep 13, 2010 5 | * Author: abachrac 6 | */ 7 | // reading a complete binary file 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | void param_update_handler(BotParam * old_param,BotParam * new_param, int64_t utime, void *user){ 16 | fprintf(stderr, "some parameters were updated %p!\n",user); 17 | } 18 | 19 | 20 | int main() 21 | { 22 | lcm_t * lcm = lcm_create(NULL); 23 | 24 | BotParam * param = bot_param_new_from_server(lcm, 1); 25 | if (param == NULL) { 26 | fprintf(stderr, "could not get params!\n"); 27 | exit(1); 28 | } 29 | 30 | bot_param_add_update_subscriber(param,param_update_handler,lcm); 31 | 32 | char * s; 33 | int ret = bot_param_write_to_string(param, &s); 34 | fprintf(stderr, "%s", s); 35 | free(s); 36 | 37 | // double foo = bot_param_get_double_or_fail(param, "foo"); 38 | // double bar = bot_param_get_double_or_fail(param, "bar"); 39 | // printf("foo=%f, bar = %f\n", foo, bar); 40 | 41 | bot_param_write(param, stderr); 42 | 43 | while (1) { 44 | lcm_handle(lcm); 45 | char * key = "coordinate_frames.body.history"; 46 | fprintf(stderr, "%s = %d\n", key, bot_param_get_int_or_fail(param, key)); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /bot2-procman/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6.0) 2 | 3 | set(POD_NAME bot2-procman) 4 | 5 | include(cmake/pods.cmake) 6 | 7 | # automatically build LCM types. This also defines a number of CMake 8 | # variables, see cmake/lcmtypes.cmake for details 9 | include(cmake/lcmtypes.cmake) 10 | lcmtypes_build(PY_DEST_DIR ${PROJECT_SOURCE_DIR}/python/src) 11 | 12 | 13 | add_subdirectory(src/deputy) 14 | add_subdirectory(python) 15 | -------------------------------------------------------------------------------- /bot2-procman/Makefile: -------------------------------------------------------------------------------- 1 | # Default pod makefile distributed with pods version: 12.09.21 2 | 3 | default_target: all 4 | 5 | # Default to a less-verbose build. If you want all the gory compiler output, 6 | # run "make VERBOSE=1" 7 | $(VERBOSE).SILENT: 8 | 9 | # Figure out where to build the software. 10 | # Use BUILD_PREFIX if it was passed in. 11 | # If not, search up to four parent directories for a 'build' directory. 12 | # Otherwise, use ./build. 13 | ifeq "$(BUILD_PREFIX)" "" 14 | BUILD_PREFIX:=$(shell for pfx in ./ .. ../.. ../../.. ../../../..; do d=`pwd`/$$pfx/build;\ 15 | if [ -d $$d ]; then echo $$d; exit 0; fi; done; echo `pwd`/build) 16 | endif 17 | # create the build directory if needed, and normalize its path name 18 | BUILD_PREFIX:=$(shell mkdir -p $(BUILD_PREFIX) && cd $(BUILD_PREFIX) && echo `pwd`) 19 | 20 | # Default to a release build. If you want to enable debugging flags, run 21 | # "make BUILD_TYPE=Debug" 22 | ifeq "$(BUILD_TYPE)" "" 23 | BUILD_TYPE="Release" 24 | endif 25 | 26 | all: pod-build/Makefile 27 | $(MAKE) -C pod-build all install 28 | 29 | pod-build/Makefile: 30 | $(MAKE) configure 31 | 32 | .PHONY: configure 33 | configure: 34 | @echo "\nBUILD_PREFIX: $(BUILD_PREFIX)\n\n" 35 | 36 | # create the temporary build directory if needed 37 | @mkdir -p pod-build 38 | 39 | # run CMake to generate and configure the build scripts 40 | @cd pod-build && cmake -DCMAKE_INSTALL_PREFIX=$(BUILD_PREFIX) \ 41 | -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) .. 42 | 43 | clean: 44 | -if [ -e pod-build/install_manifest.txt ]; then rm -f `cat pod-build/install_manifest.txt`; fi 45 | -if [ -d pod-build ]; then $(MAKE) -C pod-build clean; rm -rf pod-build; fi 46 | 47 | # other (custom) targets are passed through to the cmake-generated Makefile 48 | %:: 49 | $(MAKE) -C pod-build $@ -------------------------------------------------------------------------------- /bot2-procman/README: -------------------------------------------------------------------------------- 1 | This software is constructed according to the Pods software policies and 2 | templates. The policies and templates can be found at: 3 | 4 | http://sourceforge.net/projects/pods 5 | 6 | ==== 7 | 8 | Name: bot2-procman 9 | Maintainers: Albert Huang 10 | Summary: Tools to manage many processes distributed over several workstations 11 | Description: 12 | Procman is a tool for managing many processes distributed over one or more 13 | computers. There are two ways to use procman: 14 | 15 | 1) Sheriff / Deputy mode 16 | 17 | In this mode, every workstation runs a bot-procman-deputy process. One 18 | workstation runs a bot-procman-sheriff process, which provides a GUI to 19 | command and communicate with the deputies. 20 | 21 | Using the GUI, you can: 22 | create new processes 23 | start, stop, restart processes 24 | aggregate processes together into logical groups (e.g., "Planning") 25 | view the standard output of each process (redirected by deputies) 26 | save and load process configuration files 27 | view process statistics (memory used, CPU% used) 28 | 29 | 2) Lone Ranger mode 30 | 31 | This mode is primarily useful when you only want to run processes on the 32 | local computer. In this mode, the sheriff acts as its own deputy. To 33 | operate in lone ranger mode, run 34 | 35 | bot-procman-sheriff --lone-ranger 36 | 37 | or with -l, but --lone-ranger is cooler. 38 | 39 | Requirements: 40 | GLib (>= 2.0) 41 | LCM (http://lcm.googlecode.com) 42 | 43 | Python 44 | PyGTK (bot-procman-sheriff is written in Python with PyGTK) 45 | 46 | Currently only tested on GNU/Linux. Some stuff will definitely only work on 47 | Linux (e.g., the process memory, CPU statistics). 48 | -------------------------------------------------------------------------------- /bot2-procman/doc/Doxyfile: -------------------------------------------------------------------------------- 1 | OUTPUT_DIRECTORY= 2 | PROJECT_NAME=procman 3 | GENERATE_LATEX=no 4 | #TAGFILES= 5 | #GENERATE_TAGFILE= 6 | #STRIP_FROM_PATH= 7 | JAVADOC_AUTOBRIEF=yes 8 | EXTERNAL_GROUPS=no 9 | 10 | INHERIT_DOCS = YES 11 | LAYOUT_FILE = DoxygenLayout.xml 12 | 13 | INPUT = content ../python/src/bot_procman/ 14 | FILE_PATTERNS = *.hpp *.md sheriff.py sheriff_script.py signal_slot.py 15 | EXCLUDE_PATTERNS = 16 | EXCLUDE_SYMBOLS = ScriptExecutionContext 17 | 18 | EXAMPLE_PATH = ../lcmtypes 19 | EXAMPLE_PATTERNS = *.lcm 20 | 21 | IMAGE_PATH = images 22 | INPUT_FILTER = 23 | FILTER_PATTERNS = *.py=doxypy 24 | -------------------------------------------------------------------------------- /bot2-procman/doc/content/design.md: -------------------------------------------------------------------------------- 1 | Procman design overview {#procman_design} 2 | ===================== 3 | 4 | This page explains the design of procman and how the different components work 5 | together to control processes. 6 | 7 | # Deputies and Sheriffs {#procman_design_deputies_and_sheriffs} 8 | 9 | There are two types of processes in procman: deputies and sheriffs. 10 | 11 | _Deputies_ host and control processes directly. A deputy can: 12 | - start child processes 13 | - stop child processes 14 | - monitor and report the status of hosted processes 15 | 16 | The deputy is essentially a daemon process that manages other commands. It is 17 | not interactive, does not have a GUI, and simply carries out orders that it 18 | receives from a sheriff. 19 | 20 | 21 | _Sheriffs_ tell deputies what to do. A single sheriff can command many 22 | deputies. Any process can be a sheriff as long as it implements the 23 | sheriff/deputy communications protocol, but the most commonly used sheriff is 24 | the `bot-procman-sheriff` GUI tool provided with Procman. The Procman Python API 25 | can also be used to implement a custom sheriff. 26 | 27 | Sheriffs and deputies [communicate via LCM](\ref procman_comms), a UDP 28 | multicast-based communications protocol. All communications are stateless, 29 | which enables sheriffs and deputies to work together more easily in the 30 | presence of network and communication dropouts. 31 | 32 | ## bot-procman-sheriff {#procman_design_bot_procman_sheriff} 33 | 34 | `bot-procman-sheriff` is the primary implementation of Procman sheriff, and can 35 | be used to communicate with and command deputies. The sheriff forms a global 36 | view of all deputies and their commands. The sheriff sends commands to the 37 | deputies, and specifies which commands a deputy should be managing, and the 38 | desired state of those commands. 39 | 40 | The sheriff has an interactive GUI through which a user can modify commands and 41 | their desired statuses. It also has a scripting facility that can be useful 42 | for starting multiple commands at once, sequencing a startup procedure, or 43 | running simple scripts in general. 44 | 45 | The sheriff can also be run from the command line without a GUI. 46 | 47 | \image html procman-sheriff-screenshot.png "bot-procman-sheriff screenshot" 48 | 49 | ### Observer mode {#procman_design_bot_procman_sheriff_observer_mode} 50 | 51 | `bot-procman-sheriff` can be switched to observer mode, where it stops 52 | transmitting commands, and simply displays the state of the deputies. Observer 53 | mode is useful in situations where you want to simply observe the state of a 54 | running system. Examples of this include situations where the active sheriff 55 | is running without a GUI, and also when replaying an LCM log file that contains 56 | deputy status message (using the LCM log playback tools). 57 | -------------------------------------------------------------------------------- /bot2-procman/doc/content/main.md: -------------------------------------------------------------------------------- 1 | Procman {#mainpage} 2 | ======= 3 | 4 | # Introduction {#procman_introduction} 5 | 6 | Procman is a set of tools for managing multiple processes distributed across 7 | one or more hosts. 8 | 9 | A single GUI provides the following features: 10 | - start, stop, and restart processes 11 | - view process-level CPU/memory usage and console output 12 | - group processes together (e.g., the "controls" group) for organization 13 | - run simple scripts 14 | 15 | In addition to the GUI, there is also a Python API for more programmatic 16 | control of processes. 17 | 18 | # Table of Contents {#procman_toc} 19 | 20 | - \ref procman_tutorial 21 | - [Design overview](\ref procman_design) 22 | - \ref procman_config_file 23 | - [Communications protocol](\ref procman_comms) 24 | -------------------------------------------------------------------------------- /bot2-procman/doc/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /bot2-procman/doc/images/procman-sheriff-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobotLocomotion/libbot/2dd5a49580292b85d3ba09db417722f218995ce5/bot2-procman/doc/images/procman-sheriff-screenshot.png -------------------------------------------------------------------------------- /bot2-procman/doc/images/sheriff-gui-add-command-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobotLocomotion/libbot/2dd5a49580292b85d3ba09db417722f218995ce5/bot2-procman/doc/images/sheriff-gui-add-command-menu.png -------------------------------------------------------------------------------- /bot2-procman/doc/images/sheriff-gui-add-command.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobotLocomotion/libbot/2dd5a49580292b85d3ba09db417722f218995ce5/bot2-procman/doc/images/sheriff-gui-add-command.png -------------------------------------------------------------------------------- /bot2-procman/doc/images/sheriff-gui-command-running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobotLocomotion/libbot/2dd5a49580292b85d3ba09db417722f218995ce5/bot2-procman/doc/images/sheriff-gui-command-running.png -------------------------------------------------------------------------------- /bot2-procman/doc/images/sheriff-gui-empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobotLocomotion/libbot/2dd5a49580292b85d3ba09db417722f218995ce5/bot2-procman/doc/images/sheriff-gui-empty.png -------------------------------------------------------------------------------- /bot2-procman/doc/images/sheriff-gui-start-command-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobotLocomotion/libbot/2dd5a49580292b85d3ba09db417722f218995ce5/bot2-procman/doc/images/sheriff-gui-start-command-menu.png -------------------------------------------------------------------------------- /bot2-procman/doc/images/sheriff-gui-with-xterm-stopped.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobotLocomotion/libbot/2dd5a49580292b85d3ba09db417722f218995ce5/bot2-procman/doc/images/sheriff-gui-with-xterm-stopped.png -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_command2_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | struct command2_t { 4 | // Executable string 5 | string exec_str; 6 | 7 | string command_name; 8 | 9 | string group; 10 | 11 | boolean auto_respawn; 12 | 13 | int8_t stop_signal; 14 | 15 | float stop_time_allowed; 16 | 17 | int32_t num_options; 18 | 19 | string option_names[num_options]; 20 | 21 | string option_values[num_options]; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_deputy_cmd2_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | /* describes the state of a command managed by the procman sheriff/deputy 4 | */ 5 | 6 | struct deputy_cmd2_t { 7 | 8 | // The command to execute. 9 | command2_t cmd; 10 | 11 | // If the command is running, then this is the pid if not, then this is 12 | // zero. 13 | int32_t pid; 14 | 15 | // an ID for the run instance 16 | int32_t actual_runid; 17 | 18 | // the last exit code 19 | int32_t exit_code; 20 | 21 | // [0, 1] 22 | float cpu_usage; 23 | 24 | // total virtual memory used by the process 25 | int64_t mem_vsize_bytes; 26 | 27 | // total physical memory used by the process 28 | int64_t mem_rss_bytes; 29 | 30 | // assigned by the sheriff, identifies the command 31 | int32_t sheriff_id; 32 | } 33 | -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_deputy_cmd_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | /* describes the state of a command managed by the procman sheriff/deputy 4 | */ 5 | 6 | struct deputy_cmd_t { 7 | 8 | // The command to execute. 9 | string name; 10 | 11 | // nickname of the command. This is also used as the display name. 12 | string nickname; 13 | 14 | // command group. Used only for UI purposes 15 | string group; 16 | 17 | // If the command is running, then this is the pid if not, then this is 18 | // zero. 19 | int32_t pid; 20 | 21 | // an ID for the run instance 22 | int32_t actual_runid; 23 | 24 | // the last exit code 25 | int32_t exit_code; 26 | 27 | // [0, 1] 28 | float cpu_usage; 29 | 30 | // total virtual memory used by the process 31 | int64_t mem_vsize_bytes; 32 | 33 | // total physical memory used by the process 34 | int64_t mem_rss_bytes; 35 | 36 | // assigned by the sheriff, identifies the command 37 | int32_t sheriff_id; 38 | 39 | // automatically restart when the process should be running 40 | boolean auto_respawn; 41 | } 42 | -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_discovery_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | /* 4 | message sent by a procman deputy or sheriff to discover other deputies and 5 | sheriffs on the network. 6 | */ 7 | 8 | struct discovery_t { 9 | int64_t utime; 10 | string host; 11 | int64_t nonce; 12 | } 13 | -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_info2_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | /* 4 | message sent by a procman deputy, primarily intended for the procman 5 | sheriff. informs the sheriff of the status of processes running on the 6 | host managed by the deputy. 7 | */ 8 | 9 | struct info2_t { 10 | int64_t utime; 11 | string host; 12 | 13 | // [0, 1] 14 | float cpu_load; 15 | 16 | int64_t phys_mem_total_bytes; 17 | int64_t phys_mem_free_bytes; 18 | int64_t swap_total_bytes; 19 | int64_t swap_free_bytes; 20 | 21 | int32_t ncmds; 22 | deputy_cmd2_t cmds[ncmds]; 23 | 24 | int32_t num_options; 25 | string option_names[num_options]; 26 | string option_values[num_options]; 27 | } 28 | -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_info_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | /* 4 | message sent by a procman deputy, primarily intended for the procman 5 | sheriff. informs the sheriff of the status of processes running on the 6 | host managed by the deputy. 7 | */ 8 | 9 | struct info_t { 10 | int64_t utime; 11 | string host; 12 | 13 | // [0, 1] 14 | float cpu_load; 15 | 16 | int64_t phys_mem_total_bytes; 17 | int64_t phys_mem_free_bytes; 18 | int64_t swap_total_bytes; 19 | int64_t swap_free_bytes; 20 | 21 | int32_t ncmds; 22 | deputy_cmd_t cmds[ncmds]; 23 | } 24 | -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_orders2_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | /* 4 | message sent by the procman sheriff to provide instructions for a procman 5 | deputy. As long as the deputy reports a status inconsistent with the 6 | orders, the orders will periodically be transmitted 7 | */ 8 | 9 | struct orders2_t { 10 | int64_t utime; 11 | string host; 12 | string sheriff_name; 13 | 14 | int32_t ncmds; 15 | sheriff_cmd2_t cmds[ncmds]; 16 | 17 | int32_t num_options; 18 | string option_names[num_options]; 19 | string option_values[num_options]; 20 | } 21 | -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_orders_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | /* 4 | message sent by the procman commander to provide instructions for a procman 5 | deputy. As long as the deputy reports a status inconsistent with the 6 | orders, the orders will periodically be transmitted 7 | */ 8 | 9 | struct orders_t { 10 | int64_t utime; 11 | string host; 12 | string sheriff_name; 13 | 14 | int32_t ncmds; 15 | sheriff_cmd_t cmds[ncmds]; 16 | 17 | int32_t nvars; 18 | string varnames[nvars]; 19 | string varvals[nvars]; 20 | } 21 | -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_printf_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | /* message sent by a procman deputy when a child process writes something to 4 | * its stdout/stderr fd. this message contains the contents of that write 5 | * (usually a printf) 6 | * also sent when the deputy itself has something to say. 7 | */ 8 | 9 | struct printf_t { 10 | int64_t utime; 11 | string deputy_name; 12 | 13 | // sheriff-assigned id of the child process. 0 if generated by the deputy 14 | int32_t sheriff_id; 15 | 16 | string text; 17 | } 18 | -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_sheriff_cmd2_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | /* describes the state of a command managed by the procman sheriff/deputy 4 | */ 5 | // ============ set by the sheriff ========== 6 | 7 | struct sheriff_cmd2_t { 8 | 9 | // describes the command 10 | command2_t cmd; 11 | 12 | // to start a command running, the sheriff should change desired_runid and 13 | // unset force_quit 14 | int32_t desired_runid; 15 | 16 | // flag set by the sheriff. If set, then the deputy should forcefully 17 | // terminate the command 18 | int8_t force_quit; 19 | 20 | // Automatically assigned by the sheriff, identifies the command 21 | int32_t sheriff_id; 22 | } 23 | -------------------------------------------------------------------------------- /bot2-procman/lcmtypes/bot_procman_sheriff_cmd_t.lcm: -------------------------------------------------------------------------------- 1 | package bot_procman; 2 | 3 | /* describes the state of a command managed by the procman sheriff/deputy 4 | */ 5 | // ============ set by the sheriff ========== 6 | 7 | struct sheriff_cmd_t { 8 | 9 | // name of the command 10 | string name; 11 | 12 | // nickname of the command 13 | string nickname; 14 | 15 | // group of the command 16 | string group; 17 | 18 | // to start a command running, the sheriff should change desired_runid and 19 | // unset force_quit 20 | int32_t desired_runid; 21 | 22 | // flag set by the sheriff. If set, then the deputy should forcefully 23 | // terminate the command 24 | int8_t force_quit; 25 | 26 | // assigned by the sheriff, identifies the command 27 | int32_t sheriff_id; 28 | 29 | // automatically restart when the process should be running (i.e., 30 | // force_quit is not set) 31 | boolean auto_respawn; 32 | } 33 | -------------------------------------------------------------------------------- /bot2-procman/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(PythonInterp REQUIRED) 2 | 3 | option(GEN_BUILD_PREFIX "Generate build_prefix.py" ON) 4 | 5 | if(GEN_BUILD_PREFIX) 6 | file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/src/bot_procman/build_prefix.py 7 | "BUILD_PREFIX='${CMAKE_INSTALL_PREFIX}'\n") 8 | # set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/bot_procman/build_prefix.py) 9 | endif(GEN_BUILD_PREFIX) 10 | 11 | # install all python packages in the src/ directory 12 | pods_install_python_packages(${CMAKE_CURRENT_SOURCE_DIR}/src) 13 | 14 | # executable scripts: script-name python-module 15 | pods_install_python_script(bot-procman-sheriff bot_procman.sheriff_gtk.sheriff_gtk) 16 | 17 | install(FILES procman-sheriff.glade DESTINATION share/bot_procman) 18 | -------------------------------------------------------------------------------- /bot2-procman/python/scripts/bot-procman-sheriff: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from bot_procman.sheriff_gtk import sheriff_gtk 4 | sheriff_gtk.main() 5 | -------------------------------------------------------------------------------- /bot2-procman/python/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | 3 | setup(name="lcm", version="0.1.0", 4 | package_dir = { '' : 'src' }, 5 | packages=["bot_procman", "bot_procman/sheriff_gtk"], 6 | scripts=["scripts/bot-procman-sheriff"]) 7 | -------------------------------------------------------------------------------- /bot2-procman/python/src/bot_procman/__init__.py: -------------------------------------------------------------------------------- 1 | """LCM package __init__.py file 2 | This file automatically generated by lcm-gen. 3 | DO NOT MODIFY BY HAND!!!! 4 | """ 5 | 6 | from orders_t import orders_t 7 | from info_t import info_t 8 | from printf_t import printf_t 9 | from sheriff_cmd_t import sheriff_cmd_t 10 | from deputy_cmd_t import deputy_cmd_t 11 | 12 | from sheriff import Sheriff 13 | from sheriff_script import SheriffScript 14 | from discovery_t import discovery_t 15 | from orders2_t import orders2_t 16 | from sheriff_cmd2_t import sheriff_cmd2_t 17 | from command2_t import command2_t 18 | from deputy_cmd2_t import deputy_cmd2_t 19 | from info2_t import info2_t 20 | from .command2_t import command2_t 21 | from .deputy_cmd2_t import deputy_cmd2_t 22 | from .deputy_cmd_t import deputy_cmd_t 23 | from .discovery_t import discovery_t 24 | from .info2_t import info2_t 25 | from .info_t import info_t 26 | from .orders2_t import orders2_t 27 | from .orders_t import orders_t 28 | from .printf_t import printf_t 29 | from .sheriff_cmd2_t import sheriff_cmd2_t 30 | from .sheriff_cmd_t import sheriff_cmd_t 31 | -------------------------------------------------------------------------------- /bot2-procman/python/src/bot_procman/deputy_cmd2_t.py: -------------------------------------------------------------------------------- 1 | """LCM type definitions 2 | This file automatically generated by lcm. 3 | DO NOT MODIFY BY HAND!!!! 4 | """ 5 | 6 | import cStringIO as StringIO 7 | import struct 8 | 9 | import command2_t 10 | 11 | class deputy_cmd2_t(object): 12 | __slots__ = ["cmd", "pid", "actual_runid", "exit_code", "cpu_usage", "mem_vsize_bytes", "mem_rss_bytes", "sheriff_id"] 13 | 14 | def __init__(self): 15 | self.cmd = None 16 | self.pid = 0 17 | self.actual_runid = 0 18 | self.exit_code = 0 19 | self.cpu_usage = 0.0 20 | self.mem_vsize_bytes = 0 21 | self.mem_rss_bytes = 0 22 | self.sheriff_id = 0 23 | 24 | def encode(self): 25 | buf = StringIO.StringIO() 26 | buf.write(deputy_cmd2_t._get_packed_fingerprint()) 27 | self._encode_one(buf) 28 | return buf.getvalue() 29 | 30 | def _encode_one(self, buf): 31 | assert self.cmd._get_packed_fingerprint() == command2_t.command2_t._get_packed_fingerprint() 32 | self.cmd._encode_one(buf) 33 | buf.write(struct.pack(">iiifqqi", self.pid, self.actual_runid, self.exit_code, self.cpu_usage, self.mem_vsize_bytes, self.mem_rss_bytes, self.sheriff_id)) 34 | 35 | def decode(data): 36 | if hasattr(data, 'read'): 37 | buf = data 38 | else: 39 | buf = StringIO.StringIO(data) 40 | if buf.read(8) != deputy_cmd2_t._get_packed_fingerprint(): 41 | raise ValueError("Decode error") 42 | return deputy_cmd2_t._decode_one(buf) 43 | decode = staticmethod(decode) 44 | 45 | def _decode_one(buf): 46 | self = deputy_cmd2_t() 47 | self.cmd = command2_t.command2_t._decode_one(buf) 48 | self.pid, self.actual_runid, self.exit_code, self.cpu_usage, self.mem_vsize_bytes, self.mem_rss_bytes, self.sheriff_id = struct.unpack(">iiifqqi", buf.read(36)) 49 | return self 50 | _decode_one = staticmethod(_decode_one) 51 | 52 | _hash = None 53 | def _get_hash_recursive(parents): 54 | if deputy_cmd2_t in parents: return 0 55 | newparents = parents + [deputy_cmd2_t] 56 | tmphash = (0xe86006ec5c7fbaa+ command2_t.command2_t._get_hash_recursive(newparents)) & 0xffffffffffffffff 57 | tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff 58 | return tmphash 59 | _get_hash_recursive = staticmethod(_get_hash_recursive) 60 | _packed_fingerprint = None 61 | 62 | def _get_packed_fingerprint(): 63 | if deputy_cmd2_t._packed_fingerprint is None: 64 | deputy_cmd2_t._packed_fingerprint = struct.pack(">Q", deputy_cmd2_t._get_hash_recursive([])) 65 | return deputy_cmd2_t._packed_fingerprint 66 | _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) 67 | 68 | -------------------------------------------------------------------------------- /bot2-procman/python/src/bot_procman/discovery_t.py: -------------------------------------------------------------------------------- 1 | """LCM type definitions 2 | This file automatically generated by lcm. 3 | DO NOT MODIFY BY HAND!!!! 4 | """ 5 | 6 | import cStringIO as StringIO 7 | import struct 8 | 9 | class discovery_t(object): 10 | __slots__ = ["utime", "host", "nonce"] 11 | 12 | def __init__(self): 13 | self.utime = 0 14 | self.host = "" 15 | self.nonce = 0 16 | 17 | def encode(self): 18 | buf = StringIO.StringIO() 19 | buf.write(discovery_t._get_packed_fingerprint()) 20 | self._encode_one(buf) 21 | return buf.getvalue() 22 | 23 | def _encode_one(self, buf): 24 | buf.write(struct.pack(">q", self.utime)) 25 | __host_encoded = self.host.encode('utf-8') 26 | buf.write(struct.pack('>I', len(__host_encoded)+1)) 27 | buf.write(__host_encoded) 28 | buf.write("\0") 29 | buf.write(struct.pack(">q", self.nonce)) 30 | 31 | def decode(data): 32 | if hasattr(data, 'read'): 33 | buf = data 34 | else: 35 | buf = StringIO.StringIO(data) 36 | if buf.read(8) != discovery_t._get_packed_fingerprint(): 37 | raise ValueError("Decode error") 38 | return discovery_t._decode_one(buf) 39 | decode = staticmethod(decode) 40 | 41 | def _decode_one(buf): 42 | self = discovery_t() 43 | self.utime = struct.unpack(">q", buf.read(8))[0] 44 | __host_len = struct.unpack('>I', buf.read(4))[0] 45 | self.host = buf.read(__host_len)[:-1].decode('utf-8', 'replace') 46 | self.nonce = struct.unpack(">q", buf.read(8))[0] 47 | return self 48 | _decode_one = staticmethod(_decode_one) 49 | 50 | _hash = None 51 | def _get_hash_recursive(parents): 52 | if discovery_t in parents: return 0 53 | tmphash = (0x888b70fffb199d38) & 0xffffffffffffffff 54 | tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff 55 | return tmphash 56 | _get_hash_recursive = staticmethod(_get_hash_recursive) 57 | _packed_fingerprint = None 58 | 59 | def _get_packed_fingerprint(): 60 | if discovery_t._packed_fingerprint is None: 61 | discovery_t._packed_fingerprint = struct.pack(">Q", discovery_t._get_hash_recursive([])) 62 | return discovery_t._packed_fingerprint 63 | _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) 64 | 65 | -------------------------------------------------------------------------------- /bot2-procman/python/src/bot_procman/printf_t.py: -------------------------------------------------------------------------------- 1 | """LCM type definitions 2 | This file automatically generated by lcm. 3 | DO NOT MODIFY BY HAND!!!! 4 | """ 5 | 6 | import cStringIO as StringIO 7 | import struct 8 | 9 | class printf_t(object): 10 | __slots__ = ["utime", "deputy_name", "sheriff_id", "text"] 11 | 12 | def __init__(self): 13 | self.utime = 0 14 | self.deputy_name = "" 15 | self.sheriff_id = 0 16 | self.text = "" 17 | 18 | def encode(self): 19 | buf = StringIO.StringIO() 20 | buf.write(printf_t._get_packed_fingerprint()) 21 | self._encode_one(buf) 22 | return buf.getvalue() 23 | 24 | def _encode_one(self, buf): 25 | buf.write(struct.pack(">q", self.utime)) 26 | __deputy_name_encoded = self.deputy_name.encode('utf-8') 27 | buf.write(struct.pack('>I', len(__deputy_name_encoded)+1)) 28 | buf.write(__deputy_name_encoded) 29 | buf.write("\0") 30 | buf.write(struct.pack(">i", self.sheriff_id)) 31 | __text_encoded = self.text.encode('utf-8') 32 | buf.write(struct.pack('>I', len(__text_encoded)+1)) 33 | buf.write(__text_encoded) 34 | buf.write("\0") 35 | 36 | def decode(data): 37 | if hasattr(data, 'read'): 38 | buf = data 39 | else: 40 | buf = StringIO.StringIO(data) 41 | if buf.read(8) != printf_t._get_packed_fingerprint(): 42 | raise ValueError("Decode error") 43 | return printf_t._decode_one(buf) 44 | decode = staticmethod(decode) 45 | 46 | def _decode_one(buf): 47 | self = printf_t() 48 | self.utime = struct.unpack(">q", buf.read(8))[0] 49 | __deputy_name_len = struct.unpack('>I', buf.read(4))[0] 50 | self.deputy_name = buf.read(__deputy_name_len)[:-1].decode('utf-8', 'replace') 51 | self.sheriff_id = struct.unpack(">i", buf.read(4))[0] 52 | __text_len = struct.unpack('>I', buf.read(4))[0] 53 | self.text = buf.read(__text_len)[:-1].decode('utf-8', 'replace') 54 | return self 55 | _decode_one = staticmethod(_decode_one) 56 | 57 | _hash = None 58 | def _get_hash_recursive(parents): 59 | if printf_t in parents: return 0 60 | tmphash = (0x855d6226c71d3dd6) & 0xffffffffffffffff 61 | tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff 62 | return tmphash 63 | _get_hash_recursive = staticmethod(_get_hash_recursive) 64 | _packed_fingerprint = None 65 | 66 | def _get_packed_fingerprint(): 67 | if printf_t._packed_fingerprint is None: 68 | printf_t._packed_fingerprint = struct.pack(">Q", printf_t._get_hash_recursive([])) 69 | return printf_t._packed_fingerprint 70 | _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) 71 | 72 | -------------------------------------------------------------------------------- /bot2-procman/python/src/bot_procman/sheriff_cmd2_t.py: -------------------------------------------------------------------------------- 1 | """LCM type definitions 2 | This file automatically generated by lcm. 3 | DO NOT MODIFY BY HAND!!!! 4 | """ 5 | 6 | import cStringIO as StringIO 7 | import struct 8 | 9 | import command2_t 10 | 11 | class sheriff_cmd2_t(object): 12 | __slots__ = ["cmd", "desired_runid", "force_quit", "sheriff_id"] 13 | 14 | def __init__(self): 15 | self.cmd = None 16 | self.desired_runid = 0 17 | self.force_quit = 0 18 | self.sheriff_id = 0 19 | 20 | def encode(self): 21 | buf = StringIO.StringIO() 22 | buf.write(sheriff_cmd2_t._get_packed_fingerprint()) 23 | self._encode_one(buf) 24 | return buf.getvalue() 25 | 26 | def _encode_one(self, buf): 27 | assert self.cmd._get_packed_fingerprint() == command2_t.command2_t._get_packed_fingerprint() 28 | self.cmd._encode_one(buf) 29 | buf.write(struct.pack(">ibi", self.desired_runid, self.force_quit, self.sheriff_id)) 30 | 31 | def decode(data): 32 | if hasattr(data, 'read'): 33 | buf = data 34 | else: 35 | buf = StringIO.StringIO(data) 36 | if buf.read(8) != sheriff_cmd2_t._get_packed_fingerprint(): 37 | raise ValueError("Decode error") 38 | return sheriff_cmd2_t._decode_one(buf) 39 | decode = staticmethod(decode) 40 | 41 | def _decode_one(buf): 42 | self = sheriff_cmd2_t() 43 | self.cmd = command2_t.command2_t._decode_one(buf) 44 | self.desired_runid, self.force_quit, self.sheriff_id = struct.unpack(">ibi", buf.read(9)) 45 | return self 46 | _decode_one = staticmethod(_decode_one) 47 | 48 | _hash = None 49 | def _get_hash_recursive(parents): 50 | if sheriff_cmd2_t in parents: return 0 51 | newparents = parents + [sheriff_cmd2_t] 52 | tmphash = (0xc749fe5a5de67849+ command2_t.command2_t._get_hash_recursive(newparents)) & 0xffffffffffffffff 53 | tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff 54 | return tmphash 55 | _get_hash_recursive = staticmethod(_get_hash_recursive) 56 | _packed_fingerprint = None 57 | 58 | def _get_packed_fingerprint(): 59 | if sheriff_cmd2_t._packed_fingerprint is None: 60 | sheriff_cmd2_t._packed_fingerprint = struct.pack(">Q", sheriff_cmd2_t._get_hash_recursive([])) 61 | return sheriff_cmd2_t._packed_fingerprint 62 | _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) 63 | 64 | -------------------------------------------------------------------------------- /bot2-procman/python/src/bot_procman/sheriff_gtk/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobotLocomotion/libbot/2dd5a49580292b85d3ba09db417722f218995ce5/bot2-procman/python/src/bot_procman/sheriff_gtk/__init__.py -------------------------------------------------------------------------------- /bot2-procman/src/deputy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | add_executable(bot-procman-deputy 4 | lcm_util.c 5 | procinfo.c 6 | procman.c 7 | procman_deputy.c 8 | signal_pipe.c) 9 | 10 | pods_use_pkg_config_packages(bot-procman-deputy 11 | glib-2.0 12 | gthread-2.0 13 | lcm) 14 | target_link_libraries(bot-procman-deputy util lcmtypes_bot2-procman) 15 | 16 | pods_install_executables(bot-procman-deputy) 17 | -------------------------------------------------------------------------------- /bot2-procman/src/deputy/lcm_util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "lcm_util.h" 6 | 7 | //#define dbg(...) fprintf (stderr, __VA_ARGS__) 8 | #define dbg(...) 9 | 10 | static int 11 | lcm_message_ready (GIOChannel *source, GIOCondition cond, lcm_t *lcm) 12 | { 13 | lcm_handle (lcm); 14 | return TRUE; 15 | } 16 | 17 | typedef struct { 18 | GIOChannel *ioc; 19 | guint sid; 20 | lcm_t *lcm; 21 | } glib_attached_lcm_t; 22 | 23 | static GHashTable *lcm_glib_sources = NULL; 24 | 25 | int 26 | lcmu_glib_mainloop_attach_lcm (lcm_t *lcm) 27 | { 28 | if (!lcm_glib_sources) { 29 | lcm_glib_sources = g_hash_table_new (g_direct_hash, g_direct_equal); 30 | } 31 | 32 | if (g_hash_table_lookup (lcm_glib_sources, lcm)) { 33 | dbg ("lcm %p already attached to mainloop\n", lcm); 34 | return -1; 35 | } 36 | 37 | glib_attached_lcm_t *galcm = 38 | (glib_attached_lcm_t*) calloc (1, sizeof (glib_attached_lcm_t)); 39 | 40 | galcm->ioc = g_io_channel_unix_new (lcm_get_fileno (lcm)); 41 | galcm->sid = g_io_add_watch (galcm->ioc, G_IO_IN, (GIOFunc) lcm_message_ready, 42 | lcm); 43 | galcm->lcm = lcm; 44 | 45 | dbg ("inserted lcm %p into glib mainloop\n", lcm); 46 | g_hash_table_insert (lcm_glib_sources, lcm, galcm); 47 | return 0; 48 | } 49 | 50 | int 51 | lcmu_glib_mainloop_detach_lcm (lcm_t *lcm) 52 | { 53 | if (!lcm_glib_sources) { 54 | dbg ("no lcm glib sources\n"); 55 | return -1; 56 | } 57 | 58 | glib_attached_lcm_t *galcm = 59 | (glib_attached_lcm_t*) g_hash_table_lookup (lcm_glib_sources, lcm); 60 | 61 | if (!galcm) { 62 | dbg ("couldn't find matching galcm\n"); 63 | return -1; 64 | } 65 | 66 | dbg ("detaching lcm from glib\n"); 67 | g_io_channel_unref (galcm->ioc); 68 | g_source_remove (galcm->sid); 69 | 70 | g_hash_table_remove (lcm_glib_sources, lcm); 71 | free (galcm); 72 | 73 | if (g_hash_table_size (lcm_glib_sources) == 0) { 74 | g_hash_table_destroy (lcm_glib_sources); 75 | lcm_glib_sources = NULL; 76 | } 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /bot2-procman/src/deputy/lcm_util.h: -------------------------------------------------------------------------------- 1 | #ifndef __lc_util_h__ 2 | #define __lc_util_h__ 3 | 4 | #include 5 | 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /** 13 | * lcu_mainloop_attach_lc (lc_t *lc) 14 | * attaches/detaches LC to/from the glib mainloop 15 | * When attached, lc_handle() is invoked "automatically" when a message is 16 | * received over LC. 17 | * 18 | * only one instance of lc_t can be attached per process 19 | * 20 | * returns 0 on success, -1 on failure 21 | */ 22 | int lcmu_glib_mainloop_attach_lcm (lcm_t *lcm); 23 | 24 | int lcmu_glib_mainloop_detach_lcm (lcm_t *lcm); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /bot2-procman/src/deputy/procinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef __procinfo_h__ 2 | #define __procinfo_h__ 3 | 4 | // functions for reading how much CPU and memory are being used by individual 5 | // processes and the system as a whole 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef struct { 14 | int pid; 15 | 16 | // cpu usage time 17 | uint32_t user; 18 | uint32_t system; 19 | 20 | // memory usage 21 | int64_t vsize; 22 | int64_t rss; 23 | int64_t shared; 24 | int64_t text; 25 | int64_t data; 26 | } proc_cpu_mem_t; 27 | 28 | typedef struct { 29 | uint32_t user; 30 | uint32_t user_low; 31 | uint32_t system; 32 | uint32_t idle; 33 | 34 | int64_t memtotal; 35 | int64_t memfree; 36 | int64_t swaptotal; 37 | int64_t swapfree; 38 | 39 | } sys_cpu_mem_t; 40 | 41 | int procinfo_read_proc_cpu_mem (int pid, proc_cpu_mem_t *s); 42 | 43 | int procinfo_read_sys_cpu_mem (sys_cpu_mem_t *s); 44 | 45 | /** 46 | * returns a GArray of ints. 47 | */ 48 | GArray* procinfo_get_descendants (int pid); 49 | 50 | int procinfo_is_orphaned_child_of(int orphan, int parent); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /bot2-procman/src/deputy/signal_pipe.h: -------------------------------------------------------------------------------- 1 | #ifndef __signal_pipe_h__ 2 | #define __signal_pipe_h__ 3 | 4 | /* signal_pipe provides convenience wrappers to convert unix signals into glib 5 | * events. 6 | * 7 | * e.g. to catch SIGINT in a gtk callback function, you might do: 8 | * 9 | * void handle_sigint (int signal, void *user) { 10 | * printf("caught SIGINT\n"); 11 | * gtk_main_quit(); 12 | * } 13 | * 14 | * int main(int argc, char **argv) { 15 | * gtk_init(); 16 | * signal_pipe_init(); 17 | * signal_pipe_add_signal (SIGINT); 18 | * signal_pipe_attach_glib (handle_sigint, NULL); 19 | * 20 | * gtk_main(); 21 | * 22 | * signal_pipe_destroy(); 23 | * } 24 | */ 25 | 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | typedef void (*signal_pipe_glib_handler_t) (int signal, void *user_data); 33 | 34 | // initializes signal_pipe. call this once per process. 35 | int signal_pipe_init (void); 36 | 37 | // cleans up resources used by the signal_pipe 38 | int signal_pipe_cleanup (void); 39 | 40 | // specifies that signal should be caught by signal_pipe and converted to a 41 | // glib event 42 | void signal_pipe_add_signal (int signal); 43 | 44 | // sets a handler function that is called when a signal is caught by 45 | // signal_pipe. The first argument to the user_func function is the number of 46 | // the signal caught. The second is the user_data parameter passed in here. 47 | int signal_pipe_attach_glib (signal_pipe_glib_handler_t user_func, 48 | gpointer user_data); 49 | 50 | // convenience function to setup a signal handler that calls 51 | // signal_pipe_init, and adds a signal handler that automatically call 52 | // g_main_loop_quit (mainloop) on receiving SIGTERM, SIGINT, or SIGHUP. 53 | // also invokes signal_pipe_cleanup() on receiving these signals. 54 | int signal_pipe_glib_quit_on_kill (GMainLoop *mainloop); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /bot2-vis/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6.0) 2 | 3 | set(POD_NAME bot2-vis) 4 | 5 | include_directories(${PROJECT_SOURCE_DIR}/src) 6 | 7 | include(cmake/pods.cmake) 8 | 9 | find_package(PkgConfig REQUIRED) 10 | 11 | set(GLUT_LIBRARIES -lglut) 12 | 13 | set(ZLIB_LIBRARIES -lz) 14 | 15 | find_package(JPEG REQUIRED) 16 | 17 | add_definitions(-std=gnu99) 18 | 19 | add_subdirectory(src/bot_vis) 20 | add_subdirectory(src/testers) 21 | add_subdirectory(src/rwx-viewer) 22 | add_subdirectory(src/wavefront-viewer) 23 | 24 | # bot-ppmsgz script 25 | install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bot-ppmsgz DESTINATION bin) 26 | -------------------------------------------------------------------------------- /bot2-vis/Makefile: -------------------------------------------------------------------------------- 1 | # Default pod makefile distributed with pods version: 12.09.21 2 | 3 | default_target: all 4 | 5 | # Default to a less-verbose build. If you want all the gory compiler output, 6 | # run "make VERBOSE=1" 7 | $(VERBOSE).SILENT: 8 | 9 | # Figure out where to build the software. 10 | # Use BUILD_PREFIX if it was passed in. 11 | # If not, search up to four parent directories for a 'build' directory. 12 | # Otherwise, use ./build. 13 | ifeq "$(BUILD_PREFIX)" "" 14 | BUILD_PREFIX:=$(shell for pfx in ./ .. ../.. ../../.. ../../../..; do d=`pwd`/$$pfx/build;\ 15 | if [ -d $$d ]; then echo $$d; exit 0; fi; done; echo `pwd`/build) 16 | endif 17 | # create the build directory if needed, and normalize its path name 18 | BUILD_PREFIX:=$(shell mkdir -p $(BUILD_PREFIX) && cd $(BUILD_PREFIX) && echo `pwd`) 19 | 20 | # Default to a release build. If you want to enable debugging flags, run 21 | # "make BUILD_TYPE=Debug" 22 | ifeq "$(BUILD_TYPE)" "" 23 | BUILD_TYPE="Release" 24 | endif 25 | 26 | all: pod-build/Makefile 27 | $(MAKE) -C pod-build all install 28 | 29 | pod-build/Makefile: 30 | $(MAKE) configure 31 | 32 | .PHONY: configure 33 | configure: 34 | @echo "\nBUILD_PREFIX: $(BUILD_PREFIX)\n\n" 35 | 36 | # create the temporary build directory if needed 37 | @mkdir -p pod-build 38 | 39 | # run CMake to generate and configure the build scripts 40 | @cd pod-build && cmake -DCMAKE_INSTALL_PREFIX=$(BUILD_PREFIX) \ 41 | -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) .. 42 | 43 | clean: 44 | -if [ -e pod-build/install_manifest.txt ]; then rm -f `cat pod-build/install_manifest.txt`; fi 45 | -if [ -d pod-build ]; then $(MAKE) -C pod-build clean; rm -rf pod-build; fi 46 | 47 | # other (custom) targets are passed through to the cmake-generated Makefile 48 | %:: 49 | $(MAKE) -C pod-build $@ -------------------------------------------------------------------------------- /bot2-vis/README: -------------------------------------------------------------------------------- 1 | This software is constructed according to the Pods software policies and 2 | templates. The policies and templates can be found at: 3 | 4 | http://sourceforge.net/projects/pods 5 | 6 | ==== 7 | 8 | Name: bot2-vis 9 | Maintainers: FILL-ME-IN 10 | Summary: Visualization libraries for libbot2 11 | Description: FILL-ME-IN 12 | 13 | 14 | Requirements: 15 | General requirements: 16 | 17 | GTK+ >= 2.0 18 | OpenGL 19 | GLUT 20 | LCM (http://lcm.googlecode.com) 21 | 22 | Requires the following pods, which are distributed as part of libbot2: 23 | 24 | bot2-core 25 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB c_files *.c) 2 | file(GLOB h_files *.h) 3 | 4 | # Keep the GLM library out of the public API 5 | list(REMOVE_ITEM h_files glm.h) 6 | 7 | include_directories(${JPEG_INCLUDE_DIR}) 8 | 9 | add_library(bot2-vis SHARED ${c_files}) 10 | 11 | set(REQUIRED_LIBS ${JPEG_LIBRARY} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES}) 12 | if (APPLE) 13 | # note: the following lines will now work on every platform (and 14 | # really should be included), but they depend on a fix to pods.cmake, 15 | # which has to be copied around to all dependent pods. For this reason, 16 | # I've unfortunately restricted the fix to APPLE for the short term. - Russ T 17 | find_package( X11 REQUIRED ) 18 | include_directories ( ${X11_INCLUDE_DIR} ) 19 | set(REQUIRED_LIBS ${REQUIRED_LIBS} ${X11_LIBRARIES}) 20 | endif(APPLE) 21 | 22 | target_link_libraries(bot2-vis ${REQUIRED_LIBS}) 23 | 24 | set(REQUIRED_PACKAGES glib-2.0 gtk+-2.0 gdk-pixbuf-2.0 lcm bot2-core libpng gl glu gthread-2.0) 25 | pods_use_pkg_config_packages(bot2-vis ${REQUIRED_PACKAGES}) 26 | 27 | # set the library API version. Increment this every time the public API 28 | # changes. 29 | set_target_properties(bot2-vis PROPERTIES SOVERSION 1) 30 | 31 | pods_install_libraries(bot2-vis) 32 | 33 | pods_install_headers(${h_files} DESTINATION bot_vis) 34 | 35 | pods_install_pkg_config_file(${PROJECT_NAME} 36 | LIBS -lbot2-vis ${REQUIRED_LIBS} 37 | REQUIRES ${REQUIRED_PACKAGES} 38 | VERSION 0.0.1) 39 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/bot_vis.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot2_vis_h__ 2 | #define __bot2_vis_h__ 3 | 4 | #include "batch_gl.h" 5 | #include "console.h" 6 | #include "default_view_handler.h" 7 | #include "fbgl_drawing_area.h" 8 | #include "gl_drawing_area.h" 9 | #include "gl_image_area.h" 10 | #include "gl_util.h" 11 | #include "gtk_util.h" 12 | #include "param_widget.h" 13 | #include "rwx.h" 14 | #include "wavefront.h" 15 | #include "scrollplot2d.h" 16 | #include "texture.h" 17 | #include "viewer.h" 18 | #include "view.h" 19 | 20 | /** 21 | * @defgroup BotVis Bot Vis 22 | * @brief Visualization with OpenGL and GTK+ 23 | */ 24 | 25 | /** 26 | * @defgroup BotVisGtk GTK+ 27 | * @brief GTK+ Widgets utility functions 28 | * @ingroup BotVis 29 | */ 30 | 31 | /** 32 | * @defgroup BotVisGl OpenGL 33 | * @brief OpenGL data structures and utility functions 34 | * @ingroup BotVis 35 | */ 36 | 37 | /** 38 | * @defgroup BotViewerGroup Viewer 39 | * @brief Visualization with OpenGL and GTK+ 40 | * @ingroup BotVis 41 | */ 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/console.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_gl_console_h__ 2 | #define __bot_gl_console_h__ 3 | 4 | /** 5 | * @defgroup console Vertically scrolling text overlay 6 | * @brief Vertically scrolling text 7 | * @ingroup BotVisGl 8 | * @include: bot_vis/bot_vis.h 9 | * 10 | * Utility class for rendering vertically scrolling text. Text can be added 11 | * with printf-style formatting, and will scroll vertically as more text is 12 | * added. A decay value can also be set to fade away text over time. 13 | * 14 | * This class can be useful for displaying textual debugging or status 15 | * information in an OpenGL window. 16 | * 17 | * Linking: `pkg-config --libs bot2-vis` 18 | * 19 | * @{ 20 | */ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef struct _BotGlConsole BotGlConsole; 27 | 28 | /** 29 | * Constructor. 30 | */ 31 | BotGlConsole *bot_gl_console_new(void); 32 | 33 | /** 34 | * Destructor. 35 | */ 36 | void bot_gl_console_destroy(BotGlConsole *console); 37 | 38 | /** 39 | * Sets the rendering font. See GLUT documentation for possible options. 40 | */ 41 | void bot_gl_console_set_glut_font(BotGlConsole *console, void *font); 42 | 43 | //void bot_gl_console_set_pos (BotGlConsole *console, double x, double y); 44 | 45 | /** 46 | * Sets how quickly text will fade away. 47 | */ 48 | void bot_gl_console_set_decay_lambda(BotGlConsole *console, double lambda); 49 | 50 | /** 51 | * Sets the text color. 52 | */ 53 | void bot_gl_console_color3f(BotGlConsole *console, float r, float g, float b); 54 | 55 | /** 56 | * Adds text to display. Uses printf-style formatting. 57 | */ 58 | void bot_gl_console_printf(BotGlConsole *console, const char *format, ...); 59 | 60 | /** 61 | * Render the scrolling text. 62 | * @param elapsed_time how much time, in seconds, has elapsed since the last 63 | * rendering. This is used in combination with 64 | * bot_gl_console_set_decay_lambda() to determine the text transparency. If 65 | * less than zero, then the elapsed time will be automatically determined using 66 | * the system clock. 67 | */ 68 | void bot_gl_console_render(BotGlConsole *console, double elapsed_time); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/default_view_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef __default_view_handler_h__ 2 | #define __default_view_handler_h__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "viewer.h" 9 | 10 | typedef struct _BotDefaultViewHandler BotDefaultViewHandler; 11 | struct _BotDefaultViewHandler 12 | { 13 | BotEventHandler ehandler; 14 | BotViewHandler vhandler; 15 | BotViewer* viewer; 16 | 17 | //goal view 18 | double goal_eye[3]; 19 | double goal_lookat[3]; 20 | double goal_up[3]; 21 | 22 | //initial view 23 | double origin_eye[3]; 24 | double origin_lookat[3]; 25 | double origin_up[3]; 26 | 27 | double viewpath_duration_ms; 28 | int64_t viewpath_timer_start; 29 | 30 | int width, height; 31 | double aspect_ratio; 32 | 33 | double fov_degrees; 34 | 35 | double last_mouse_x; 36 | double last_mouse_y; 37 | 38 | int projection_type; 39 | 40 | // these three variables determine the position and orientation of 41 | // the camera. 42 | double lookat[3]; 43 | double eye[3]; 44 | double up[3]; 45 | 46 | // when there's a mouse press in the scene, we determine which 47 | // point in the scene is the one being manipulated. This 48 | // manipulation point is preserved under the mouse cursor during 49 | // any pan operations. 50 | double manipulation_point[4]; 51 | 52 | // should be recomputed whenever look/eye/up is modified. must be 53 | // kept in-sync with look/eye/up 54 | double model_matrix[16]; 55 | 56 | // should be recomputed whenever camera is modified. 57 | double projection_matrix[16]; 58 | 59 | int viewport[4]; 60 | 61 | // these are used to implement follow: they correspond to the last 62 | // position of the object. we manipulate the lookat/eye/up values 63 | // to make the position of the object invariant to motions of this 64 | // point. 65 | int have_last; 66 | double lastpos[3], lastquat[4]; 67 | }; 68 | 69 | BotDefaultViewHandler *bot_default_view_handler_new(BotViewer *viewer); 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/fbgl_drawing_area.h: -------------------------------------------------------------------------------- 1 | #ifndef __BOT_FBGL_DRAWING_AREA_H__ 2 | #define __BOT_FBGL_DRAWING_AREA_H__ 3 | 4 | #ifdef __APPLE__ 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | /** 11 | * @defgroup BotFBGLDrawingArea OpenGL offscreen rendering 12 | * @brief Offscreen rendering using Framebuffer objects 13 | * @ingroup BotVisGl 14 | * @include: bot_vis/bot_vis.h 15 | * 16 | * TODO 17 | * 18 | * Linking: `pkg-config --libs bot2-vis` 19 | * @{ 20 | */ 21 | 22 | G_BEGIN_DECLS 23 | 24 | #define BOT_TYPE_FBGL_DRAWING_AREA (bot_fbgl_drawing_area_get_type ()) 25 | #define BOT_FBGL_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOT_TYPE_FBGL_DRAWING_AREA, BotFbglDrawingArea)) 26 | #define BOT_FBGL_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOT_TYPE_FBGL_DRAWING_AREA, BotFbglDrawingAreaClass)) 27 | #define FB_IS_GL_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOT_TYPE_FBGL_DRAWING_AREA)) 28 | #define FB_IS_GL_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOT_TYPE_FBGL_DRAWING_AREA)) 29 | #define BOT_FBGL_DRAWING_AREA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOT_TYPE_FBGL_DRAWING_AREA, BotFbglDrawingAreaClass)) 30 | 31 | typedef struct _BotFbglDrawingArea BotFbglDrawingArea; 32 | typedef struct _BotFbglDrawingAreaClass BotFbglDrawingAreaClass; 33 | 34 | struct _BotFbglDrawingArea { 35 | GObject parent; 36 | 37 | int width, height; 38 | }; 39 | 40 | struct _BotFbglDrawingAreaClass { 41 | GObjectClass parent; 42 | }; 43 | 44 | GType bot_fbgl_drawing_area_get_type (void); 45 | BotFbglDrawingArea * bot_fbgl_drawing_area_new (gboolean new_context, 46 | int width, int height, GLenum format); 47 | void bot_fbgl_drawing_area_swap_buffers (BotFbglDrawingArea * glarea); 48 | int bot_fbgl_drawing_area_begin (BotFbglDrawingArea * glarea); 49 | int bot_fbgl_drawing_area_end (BotFbglDrawingArea * glarea); 50 | int bot_fbgl_drawing_area_flush (BotFbglDrawingArea * glarea); 51 | 52 | G_END_DECLS 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/gl_drawing_area.h: -------------------------------------------------------------------------------- 1 | #ifndef __BOT_GTK_GL_GL_DRAWING_AREA_H__ 2 | #define __BOT_GTK_GL_GL_DRAWING_AREA_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /** 9 | * @defgroup BotGtkGlDrawingArea BotGTKGlDrawingArea 10 | * @brief GTK+ drawing-area widget with an OpenGL context 11 | * @ingroup BotVisGtk 12 | * @include: bot_vis/bot_vis.h 13 | * 14 | * TODO 15 | * 16 | * Linking: `pkg-config --libs bot-vis` 17 | * @{ 18 | */ 19 | 20 | G_BEGIN_DECLS 21 | 22 | #define BOT_GTK_TYPE_GL_DRAWING_AREA (bot_gtk_gl_drawing_area_get_type ()) 23 | #define BOT_GTK_GL_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOT_GTK_TYPE_GL_DRAWING_AREA, BotGtkGlDrawingArea)) 24 | #define BOT_GTK_GL_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOT_GTK_TYPE_GL_DRAWING_AREA, BotGtkGlDrawingAreaClass)) 25 | #define BOT_GTK_IS_GL_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOT_GTK_TYPE_GL_DRAWING_AREA)) 26 | #define BOT_GTK_IS_GL_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOT_GTK_TYPE_GL_DRAWING_AREA)) 27 | #define BOT_GTK_GL_DRAWING_AREA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOT_GTK_TYPE_GL_DRAWING_AREA, BotGtkGlDrawingAreaClass)) 28 | 29 | typedef struct _BotGtkGlDrawingArea BotGtkGlDrawingArea; 30 | typedef struct _BotGtkGlDrawingAreaClass BotGtkGlDrawingAreaClass; 31 | 32 | struct _BotGtkGlDrawingArea { 33 | GtkDrawingArea area; 34 | 35 | gboolean vblank_sync; 36 | }; 37 | 38 | struct _BotGtkGlDrawingAreaClass { 39 | GtkDrawingAreaClass parent_class; 40 | }; 41 | 42 | GType bot_gtk_gl_drawing_area_get_type (void); 43 | GtkWidget * bot_gtk_gl_drawing_area_new (gboolean vblank_sync); 44 | void bot_gtk_gl_drawing_area_set_vblank_sync (BotGtkGlDrawingArea * glarea, 45 | gboolean vblank_sync); 46 | void bot_gtk_gl_drawing_area_swap_buffers (BotGtkGlDrawingArea * glarea); 47 | int bot_gtk_gl_drawing_area_set_context (BotGtkGlDrawingArea * glarea); 48 | void bot_gtk_gl_drawing_area_invalidate (BotGtkGlDrawingArea * glarea); 49 | 50 | G_END_DECLS 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/gl_image_area.h: -------------------------------------------------------------------------------- 1 | #ifndef __BOT_GTK_GL_IMAGE_AREA_H__ 2 | #define __BOT_GTK_GL_IMAGE_AREA_H__ 3 | 4 | /** 5 | * @defgroup BotGtkGlImageArea BotGTKGlImageArea 6 | * @brief GTK+ widget to draw images with OpenGL 7 | * @ingroup BotVisGl 8 | * @include: bot_vis/bot_vis.h 9 | * 10 | * TODO 11 | * 12 | * Linking: `pkg-config --libs bot-vis` 13 | * @{ 14 | */ 15 | 16 | #ifdef __APPLE__ 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #include "gl_drawing_area.h" 23 | 24 | G_BEGIN_DECLS 25 | 26 | #define BOT_GTK_TYPE_GL_IMAGE_AREA (bot_gtk_gl_image_area_get_type ()) 27 | #define BOT_GTK_GL_IMAGE_AREA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOT_GTK_TYPE_GL_IMAGE_AREA, BotGtkGlImageArea)) 28 | #define BOT_GTK_GL_IMAGE_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOT_GTK_TYPE_GL_IMAGE_AREA, BotGtkGlImageAreaClass)) 29 | #define GTK_IS_GL_IMAGE_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOT_GTK_TYPE_GL_IMAGE_AREA)) 30 | #define GTK_IS_GL_IMAGE_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOT_GTK_TYPE_GL_IMAGE_AREA)) 31 | #define BOT_GTK_GL_IMAGE_AREA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOT_GTK_TYPE_GL_IMAGE_AREA, BotGtkGlImageAreaClass)) 32 | 33 | typedef struct _BotGtkGlImageArea BotGtkGlImageArea; 34 | typedef struct _BotGtkGlImageAreaClass BotGtkGlImageAreaClass; 35 | 36 | struct _BotGtkGlImageArea { 37 | BotGtkGlDrawingArea parent; 38 | 39 | /*< private >*/ 40 | GLenum target; 41 | GLint int_format; 42 | GLint format; 43 | GLuint texname; 44 | int width; 45 | int height; 46 | 47 | GLuint texc_width; 48 | GLuint texc_height; 49 | 50 | GLuint pbo; 51 | int use_pbo; 52 | int max_data_size; 53 | }; 54 | 55 | struct _BotGtkGlImageAreaClass { 56 | GtkDrawingAreaClass parent_class; 57 | }; 58 | 59 | GType bot_gtk_gl_image_area_get_type (void); 60 | GtkWidget * bot_gtk_gl_image_area_new (void); 61 | int bot_gtk_gl_image_area_set_image_format (BotGtkGlImageArea *self, 62 | int width, int height, GLenum format); 63 | int bot_gtk_gl_image_area_upload_image (BotGtkGlImageArea * self, 64 | const void *data, int row_stride); 65 | 66 | G_END_DECLS 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | #endif 73 | 74 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/glmint.h: -------------------------------------------------------------------------------- 1 | #ifndef __glmint_h__ 2 | #define __glmint_h__ 3 | 4 | extern GLenum _glmTextureTarget; 5 | 6 | /* private routines from glm_util.c */ 7 | extern char * __glmStrStrip(const char *string); 8 | #ifdef HAVE_STRDUP 9 | #define __glmStrdup strdup 10 | #else 11 | extern char * __glmStrdup(const char *string); 12 | #endif 13 | extern void __glmWarning(char *format,...); 14 | extern void __glmFatalError(char *format,...); 15 | extern void __glmFatalUsage(char *format,...); 16 | extern char* __glmDirName(char* path); 17 | void __glmReportErrors(void); 18 | 19 | #ifdef DEBUG 20 | #define DBG_(_x) ((void)(_x)) 21 | #else 22 | #define DBG_(_x) ((void)0) 23 | #endif 24 | 25 | #ifdef GLDEBUG 26 | #define GLDBG_(_x) { GLenum ret = (_x); if(ret != GL_NO_ERROR) __glmWarning("OpenGL error at %d : %s",__LINE__,gluErrorString(ret)); } 27 | #else 28 | #define GLDBG_(_x) ((void)0) 29 | #endif 30 | 31 | #ifndef GL_BGR 32 | #define GL_BGR GL_BGR_EXT 33 | #endif 34 | 35 | #ifndef GL_BGRA 36 | #define GL_BGRA GL_BGRA_EXT 37 | #endif 38 | 39 | 40 | GLubyte* glmReadDevIL(const char*, GLboolean, int*, int*, int*); 41 | GLubyte* glmReadJPG(const char*, GLboolean, int*, int*, int*); 42 | GLubyte* glmReadPNG(const char*, GLboolean, int*, int*, int*); 43 | GLubyte* glmReadSDL(const char*, GLboolean, int*, int*, int*); 44 | GLubyte* glmReadSimage(const char*, GLboolean, int*, int*, int*); 45 | #endif /* __glmint_h__ */ 46 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/gtk_util.h: -------------------------------------------------------------------------------- 1 | #ifndef __gtk_util_h__ 2 | #define __gtk_util_h__ 3 | 4 | #include 5 | #include "param_widget.h" 6 | #include "gl_drawing_area.h" 7 | #include "gl_image_area.h" 8 | #include "viewer.h" 9 | 10 | /** 11 | * @defgroup BotVisGtkUtil Miscellaneous GTK+ utility functions 12 | * @brief GTK utility functions 13 | * @ingroup BotVisGtk 14 | * @include: bot_vis/bot_vis.h 15 | * 16 | * TODO 17 | * 18 | * Linking: `pkg-config --libs bot2-vis` 19 | * @{ 20 | */ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /** 27 | * Adds an event handler to the GTK mainloop that calls gtk_main_quit() when 28 | * SIGINT, SIGTERM, or SIGHUP are received 29 | */ 30 | int bot_gtk_quit_on_interrupt(void); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | /** 37 | * @} 38 | */ 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/rwx.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_rwx_h__ 2 | #define __bot_rwx_h__ 3 | 4 | /** 5 | * @defgroup BotVisRwx Renderware (.rwx) mesh model rendering 6 | * @brief Parsing and rendering .rwx models 7 | * @ingroup BotVisGl 8 | * @include: bot_vis/bot_vis.h 9 | * 10 | * Linking: `pkg-config --libs bot2-vis` 11 | * @{ 12 | */ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #include 19 | 20 | typedef struct _bot_rwx_vertex 21 | { 22 | double pos[3]; 23 | int id; 24 | } BotRwxVertex; 25 | 26 | typedef struct _bot_rwx_triangle 27 | { 28 | int vertices[3]; 29 | } BotRwxTriangle; 30 | 31 | typedef struct _bot_rwx_clump 32 | { 33 | double color[3]; 34 | // double surface[3]; 35 | double diffuse; 36 | double specular; 37 | double opacity; 38 | double ambient; 39 | char *name; 40 | BotRwxVertex *vertices; 41 | BotRwxTriangle *triangles; 42 | int nvertices; 43 | int ntriangles; 44 | } BotRwxClump; 45 | 46 | typedef struct _bot_rwx_model 47 | { 48 | GList *clumps; 49 | int nclumps; 50 | } BotRwxModel; 51 | 52 | 53 | BotRwxModel * bot_rwx_model_create( const char *fname ); 54 | 55 | void bot_rwx_model_destroy( BotRwxModel *model ); 56 | 57 | void bot_rwx_model_apply_transform( BotRwxModel *model, double m[16]); 58 | 59 | void bot_rwx_model_gl_draw( BotRwxModel *model ); 60 | 61 | void bot_rwx_model_get_extrema (BotRwxModel * model, 62 | double minv[3], double maxv[3]); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/tokenize.h: -------------------------------------------------------------------------------- 1 | #ifndef _TOKENIZE_H 2 | #define _TOKENIZE_H 3 | 4 | #include 5 | 6 | typedef struct tokenize tokenize_t; 7 | 8 | struct tokenize 9 | { 10 | // current token 11 | char *token; 12 | 13 | // position where last token started 14 | int line, column; 15 | 16 | // position where next token starts 17 | int nextline, nextcolumn; 18 | 19 | // used to track accurate positions wrt ungetc 20 | int save_line, save_column; 21 | int unget_char; // the char that was unget'd, or -1 22 | 23 | // current position of parser (end of last token, usually) 24 | int in_line, in_column; 25 | 26 | // the current line 27 | char *line_buffer; 28 | int line_pos, line_len; 29 | 30 | char *path; 31 | FILE *f; 32 | 33 | // do we have a token ready? 34 | int hasnext; 35 | }; 36 | 37 | tokenize_t *tokenize_create(const char *path); 38 | void tokenize_destroy(tokenize_t *t); 39 | int tokenize_next(tokenize_t *t); 40 | int tokenize_peek(tokenize_t *t); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/view.h: -------------------------------------------------------------------------------- 1 | #ifndef __bot_gl_view_h__ 2 | #define __bot_gl_view_h__ 3 | 4 | /** 5 | * @defgroup BotGlView BotGlView 6 | * @brief Viewpoints and OpenGL matrices 7 | * @ingroup BotVisGl 8 | * @include: bot_vis/bot_vis.h 9 | * 10 | * Linking: `pkg-config --libs bot2-vis` 11 | * @{ 12 | */ 13 | 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct _BotGlView BotGlView; 21 | 22 | BotGlView * bot_gl_view_new(void); 23 | 24 | void bot_gl_view_unref(BotGlView *view); 25 | 26 | void bot_gl_view_setup_camera(BotGlView *self); 27 | 28 | void bot_gl_view_look_at(BotGlView *self, 29 | const double eye[3], const double lookAt[3], const double up[3]); 30 | 31 | void bot_gl_view_follow(BotGlView *self, 32 | double lastPos[3], double lastQuat[4], 33 | double newPos[3], double newQuat[4], 34 | gboolean followYaw); 35 | 36 | // 1.0 for full perspective, 0.0 for orthographic. Interpolated otherwise. 37 | void bot_gl_view_set_perspectiveness(BotGlView *self, double perspectiveness); 38 | 39 | double bot_gl_view_get_perspectiveness(const BotGlView * self); 40 | 41 | /** 42 | * bot_gl_view_get_projection_matrix: 43 | * 44 | * Retrieves the projection matrix as set by the view in column-major order 45 | */ 46 | void bot_gl_view_get_projection_matrix(const BotGlView *self, double m[16]); 47 | 48 | /** 49 | * bot_gl_view_get_projection_matrix: 50 | * 51 | * Retrieves the modelview matrix as set by the view in column-major order 52 | */ 53 | void bot_gl_view_get_modelview_matrix(const BotGlView *self, double m[16]); 54 | 55 | /** 56 | * bot_gl_view_get_viewport: 57 | * 58 | * Retrieves the last used viewport 59 | */ 60 | void bot_gl_view_get_viewport(const BotGlView *self, int viewport[4]); 61 | 62 | void bot_gl_view_get_look_at(const BotGlView *self, double eye[3], 63 | double lookAt[3], double up[3]); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /bot2-vis/src/bot_vis/wavefront.h: -------------------------------------------------------------------------------- 1 | #ifndef __BOT_WAVEFRONT_H_ 2 | #define __BOT_WAVEFRONT_H_ 3 | /* 4 | * wavefront.h 5 | * 6 | * Public API for rendering 3D models that are represented in the 7 | * Wavefront OBJ (geometry) and MTL (material properties) file formats. 8 | * 9 | * The API is largely a wrapper for the GLM library 10 | * 11 | * Created on: Dec 2, 2010 12 | * Author: mwalter 13 | * 14 | */ 15 | 16 | #include 17 | 18 | 19 | /** 20 | * @defgroup BotVisWavefront Wavefront (.obj:geometry; .mtl:material) 21 | * mesh mesh model rendering 22 | * @brief Parsing and rendering .obj geometry models and their corresponding 23 | .mtl material properties definition 24 | * @ingroup BotVisGl 25 | * @include: bot_vis/bot_vis.h 26 | * 27 | * Linking: `pkg-config --libs bot2-vis` 28 | * @{ 29 | */ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | typedef struct _BotWavefrontModel BotWavefrontModel; 37 | 38 | /** 39 | * bot_wavefront_model_create: 40 | * @filename: The name of the model's Wavefront .obj file 41 | * 42 | * Reads the model represented as a Wavefront .obj file. 43 | * 44 | * Returns: A pointer to a newly-allocated %BotWavefrontModel 45 | * or %NULL on parse error. 46 | */ 47 | BotWavefrontModel * 48 | bot_wavefront_model_create (const char *filename); 49 | 50 | 51 | /** 52 | * bot_wavefront_model_destroy: 53 | * @model: The %BotWavefrontModel to free 54 | * 55 | * Frees the provided %BotWavefrontModel 56 | * 57 | */ 58 | void 59 | bot_wavefront_model_destroy (BotWavefrontModel *model); 60 | 61 | 62 | /** 63 | * bot_wavefront_model_get_extrema: 64 | * @model: The %BotWavefrontModel 65 | * 66 | * Determins the min/max extrema over vertices 67 | * 68 | */ 69 | void 70 | bot_wavefront_model_get_extrema (BotWavefrontModel *model, 71 | double minv[3], double maxv[3]); 72 | 73 | /** 74 | * bot_wavefront_model_gl_draw: 75 | * @model: The %BotWavefrontModel 76 | * 77 | * Draws the model using opengl 78 | */ 79 | void 80 | bot_wavefront_model_gl_draw (BotWavefrontModel *model); 81 | 82 | 83 | 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /bot2-vis/src/rwx-viewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | add_executable(bot-rwx-viewer 4 | main.c 5 | renderer_rwx.c) 6 | 7 | pods_use_pkg_config_packages(bot-rwx-viewer bot2-vis) # need header as well as target link library 8 | 9 | pods_install_executables(bot-rwx-viewer) 10 | -------------------------------------------------------------------------------- /bot2-vis/src/rwx-viewer/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | #include 7 | 8 | void setup_renderer_rwx(BotViewer *viewer, int render_priority, const char *rwx_fname); 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | gtk_init(&argc, &argv); 13 | glutInit(&argc, argv); 14 | g_thread_init(NULL); 15 | 16 | if(argc < 2) { 17 | fprintf(stderr, "usage: %s \n", 18 | g_path_get_basename(argv[0])); 19 | exit(1); 20 | } 21 | 22 | const char *rwx_fname = argv[1]; 23 | 24 | BotViewer* viewer = bot_viewer_new("RWX Viewer"); 25 | 26 | char *fname = g_build_filename(g_get_user_config_dir(), ".rwx-viewerrc", NULL); 27 | 28 | bot_viewer_load_preferences(viewer, fname); 29 | 30 | // setup renderers 31 | bot_viewer_add_stock_renderer(viewer, BOT_VIEWER_STOCK_RENDERER_GRID, 1); 32 | setup_renderer_rwx(viewer, 1, rwx_fname); 33 | 34 | gtk_main(); 35 | 36 | bot_viewer_save_preferences(viewer, fname); 37 | 38 | bot_viewer_unref(viewer); 39 | } 40 | -------------------------------------------------------------------------------- /bot2-vis/src/testers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | set(testers 4 | gl_drawing_area_tester 5 | gl_image_area_tester 6 | param_widget_tester) 7 | 8 | foreach(tester ${testers}) 9 | add_executable(${tester} "${tester}.c") 10 | pods_use_pkg_config_packages(${tester} bot2-vis) # need headers as well as bot2-vis target 11 | endforeach() 12 | -------------------------------------------------------------------------------- /bot2-vis/src/wavefront-viewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-std=gnu99) 2 | 3 | add_executable(bot-wavefront-viewer 4 | main.c 5 | renderer_wavefront.c) 6 | 7 | pods_use_pkg_config_packages(bot-wavefront-viewer bot2-vis) # need headers as well as target link libraries 8 | 9 | pods_install_executables(bot-wavefront-viewer) 10 | -------------------------------------------------------------------------------- /bot2-vis/src/wavefront-viewer/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | #include 7 | 8 | void setup_renderer_wavefront(BotViewer *viewer, int render_priority, 9 | const char *wavefront_fname); 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | gtk_init(&argc, &argv); 14 | glutInit(&argc, argv); 15 | g_thread_init(NULL); 16 | 17 | if(argc < 2) { 18 | fprintf(stderr, "usage: %s \n", 19 | g_path_get_basename(argv[0])); 20 | exit(1); 21 | } 22 | 23 | const char *wavefront_fname = argv[1]; 24 | 25 | BotViewer* viewer = bot_viewer_new("Wavefront OBJ Viewer"); 26 | 27 | char *fname = g_build_filename(g_get_user_config_dir(), ".wavefront-viewerrc", NULL); 28 | 29 | bot_viewer_load_preferences(viewer, fname); 30 | 31 | // setup renderers 32 | bot_viewer_add_stock_renderer(viewer, BOT_VIEWER_STOCK_RENDERER_GRID, 1); 33 | setup_renderer_wavefront(viewer, 1, wavefront_fname); 34 | 35 | gtk_main(); 36 | 37 | bot_viewer_save_preferences(viewer, fname); 38 | 39 | bot_viewer_unref(viewer); 40 | } 41 | -------------------------------------------------------------------------------- /install_prereqs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | case $1 in 4 | ("homebrew") 5 | brew install cmake gtk+ libpng libjpeg;; 6 | ("macports") 7 | ;; 8 | ("ubuntu") 9 | apt-get install libglib2.0-dev python-dev python-gtk2 libgtk2.0-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libjpeg-dev ;; 10 | ("cygwin") 11 | ;; 12 | (*) 13 | echo "Usage: ./install_prereqs.sh package_manager" 14 | echo "where package_manager is one of the following: " 15 | echo " homebrew" 16 | echo " macports" 17 | echo " ubuntu" 18 | echo " cygwin" 19 | exit 1 ;; 20 | esac 21 | 22 | if [ -f tobuild.txt ]; then 23 | SUBDIRS=`grep -v "^\#" tobuild.txt` 24 | for subdir in $SUBDIRS; do 25 | if [ -f $subdir/install_prereqs.sh ]; then 26 | echo "installing prereqs for $subdir" 27 | ( cd $subdir; ./install_prereqs.sh $1 || true ) 28 | fi 29 | done 30 | fi 31 | -------------------------------------------------------------------------------- /tobuild.txt: -------------------------------------------------------------------------------- 1 | # list of subdirectories to build, one one each line. Empty lines 2 | # and lines starting with '#' are ignored 3 | 4 | bot2-core 5 | bot2-vis 6 | bot2-procman 7 | bot2-lcmgl 8 | bot2-lcm-utils 9 | bot2-param 10 | bot2-frames 11 | --------------------------------------------------------------------------------