### Install Manual Pages
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-logger/CMakeLists.txt
Installs the manual pages for lcm-logger and lcm-logplayer to the man1 directory.
```cmake
install(FILES
lcm-logger.1
lcm-logplayer.1
DESTINATION share/man/man1
)
```
--------------------------------
### Install Executables
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-logger/CMakeLists.txt
Installs the built lcm-logger and lcm-logplayer executables to the bin directory.
```cmake
install(TARGETS
lcm-logger
lcm-logplayer
DESTINATION bin
)
```
--------------------------------
### Install Bazelisk for Bazel Builds
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Install Bazelisk to ensure the 'bazel' command is available in your PATH. This is a prerequisite for using Bazel to build LCM.
```shell
bazel run //lcm-java:lcm-spy
```
--------------------------------
### Install LCM Java components on Ubuntu
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/install-instructions.md
Use this command to install the Java-based components for LCM on Ubuntu systems via apt.
```shell
sudo apt install liblcm-java
```
--------------------------------
### Build and Install LCM with Meson on Ubuntu/Debian
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Builds and installs LCM using Meson on Ubuntu or Debian systems. Assumes build directory is 'build'.
```shell
meson setup build
cd build
meson compile
sudo meson install
```
--------------------------------
### Install Python Package Initialization Files
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-python/CMakeLists.txt
Copies the __init__.py, __init__.pyi, and py.typed files to the installation directory. These files are essential for the Python package structure and type hinting.
```cmake
lcm_copy_file_target(lcm-python-init
${CMAKE_CURRENT_SOURCE_DIR}/lcm/__init__.py
${CMAKE_BINARY_DIR}/python/lcm/__init__.py
)
install(FILES lcm/__init__.py DESTINATION ${PYTHON_INSTALL_DIR})
lcm_copy_file_target(lcm-python-stub
${CMAKE_CURRENT_SOURCE_DIR}/lcm/__init__.pyi
${CMAKE_BINARY_DIR}/python/lcm/__init__.pyi
)
install(FILES lcm/__init__.pyi DESTINATION ${PYTHON_INSTALL_DIR})
lcm_copy_file_target(lcm-python-typed
${CMAKE_CURRENT_SOURCE_DIR}/lcm/py.typed
${CMAKE_BINARY_DIR}/python/lcm/py.typed
)
install(FILES lcm/py.typed DESTINATION ${PYTHON_INSTALL_DIR})
```
--------------------------------
### Install LCM Headers and Python Bindings
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-cmake.md
Install generated LCM headers and Python modules using CMake's installation commands. `lcm_install_headers` and `lcm_install_python` are convenience functions for proper placement.
```cmake
lcm_install_headers(DESTINATION include
${CMAKE_CURRENT_BINARY_DIR}/my_lcmtypes_export.h
${c_install_headers}
${cpp_install_headers}
)
if(${Python_Interpreter_FOUND})
lcm_install_python(${python_install_sources})
endif()
```
--------------------------------
### Install LCM C/C++ Libraries and Java JAR
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-cmake.md
Install the compiled LCM C/C++ libraries and the Java JAR file to their respective destinations using CMake's `install` command and a helper function for JARs. Ensure include directories match header destinations.
```cmake
install(TARGETS my_lcmtypes my_lcmtypes-cpp
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib${LIB_SUFFIX}
ARCHIVE DESTINATION lib${LIB_SUFFIX}
INCLUDES DESTINATION include
)
if(JAVA_FOUND)
install_jar(my_lcmtypes-jar share/java)
endif()
```
--------------------------------
### Java: Subscribe to Example Messages
Source: https://context7.com/lcm-proj/lcm/llms.txt
Subscribes to 'EXAMPLE' channel messages using the LCM Java API and prints decoded message details. Implements LCMSubscriber interface.
```java
import java.io.*;
import lcm.lcm.*;
import exlcm.*;
// --- Subscriber ---
class Listener implements LCMSubscriber {
public void messageReceived(LCM lcm, String channel, LCMDataInputStream ins) {
try {
if ("EXAMPLE".equals(channel)) {
example_t msg = new example_t(ins);
System.out.printf("ts=%d pos=[%.1f,%.1f,%.1f] name=%s%n",
msg.timestamp,
msg.position[0], msg.position[1], msg.position[2],
msg.name);
}
} catch (IOException ex) {
System.err.println("decode error: " + ex);
}
}
public static void main(String[] args) throws Exception {
LCM lcm = new LCM(); // explicit instance
lcm.subscribe("EXAMPLE", new Listener());
// background thread handles receive; main thread sleeps
while (true) Thread.sleep(1000);
}
}
/*
Build:
lcm-gen -j example_t.lcm
javac -cp .:lcm.jar *.java exlcm/*.java
java -cp .:lcm.jar Listener # terminal 1
java -cp .:lcm.jar Publisher # terminal 2
*/
```
--------------------------------
### Install Homebrew Packages for LCM Build
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Installs necessary packages using Homebrew on macOS. Swap 'cmake' for 'meson' if using Meson.
```shell
brew install glib pkg-config cmake
```
--------------------------------
### Configure and Install LCM Pkgconfig File
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-pkgconfig/CMakeLists.txt
This snippet configures the main lcm.pc pkgconfig file using a template and installs it to the appropriate directory. It ensures that pkgconfig can find the LCM library.
```cmake
file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" LCM_INSTALL_PREFIX)
configure_file(lcm.pc.in ${lcm_BINARY_DIR}/lcm.pc @ONLY)
install(FILES ${lcm_BINARY_DIR}/lcm.pc
DESTINATION lib${LIB_SUFFIX}/pkgconfig)
```
--------------------------------
### Build and Install LCM with Meson on OS X
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Builds and installs LCM using Meson on OS X. Assumes build directory is 'build'.
```shell
meson setup build
cd build
meson compile
meson install
```
--------------------------------
### Java API - Publisher
Source: https://context7.com/lcm-proj/lcm/llms.txt
Example of how to publish messages using the Java LCM API. It demonstrates creating an `example_t` message, populating its fields, and publishing it to the 'EXAMPLE' channel.
```APIDOC
## Java API – `LCM` class publish / subscribe
### Publisher
```java
import java.io.*;
import lcm.lcm.*;
import exlcm.*;
class Publisher {
public static void main(String[] args) throws IOException {
LCM lcm = LCM.getSingleton();
example_t msg = new example_t();
msg.timestamp = System.nanoTime();
msg.position = new double[]{ 1.0, 2.0, 3.0 };
msg.orientation = new double[]{ 1.0, 0.0, 0.0, 0.0 };
msg.ranges = new short[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
msg.num_ranges = msg.ranges.length;
msg.name = "sensor_A";
msg.enabled = true;
lcm.publish("EXAMPLE", msg);
}
}
```
```
--------------------------------
### Troubleshoot LCM Python Module Installation
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
If the standard pip install fails, try removing the build directory, reconfiguring with the vcpkg preset, and then installing the Python module, specifying the build directory.
```powershell
Remove-Item -Path build/ -Recurse -Force
cmake --preset=vcpkg-vs
pip install -v . --config-settings=cmake.args=--preset=vcpkg-vs -Cbuild-dir=build
```
--------------------------------
### Install LCM Python Module
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Installs the Python module for LCM from source. Use the `-v` flag for verbose output.
```default
pip3 install -v .
```
--------------------------------
### Install LCM core package on Ubuntu
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/install-instructions.md
Use this command to install the main LCM development package on Ubuntu systems via apt.
```shell
sudo apt install liblcm-dev
```
--------------------------------
### Publish LCM Message in Java
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-java.md
Publishes a sample 'example_t' message on the 'EXAMPLE' channel. This involves creating, populating, and sending the message.
```java
import java.io.*;
import lcm.lcm.*;
public class SendMessage
{
public static void main(String args[])
{
try {
LCM lcm = LCM.getSingleton();
exlcm.example_t msg = new exlcm.example_t();
msg.timestamp = System.nanoTime();
msg.position = new double[] { 1, 2, 3 };
msg.orientation = new double[] { 1, 0, 0, 0 };
msg.ranges = new short[] {
0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
};
msg.num_ranges = msg.ranges.length;
msg.name = "example string";
msg.enabled = true;
lcm.publish("EXAMPLE", msg);
} catch (IOException ex) {
System.out.println("Exception: " + ex);
}
}
}
```
--------------------------------
### Install MSYS2 Dependencies
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Install necessary dependencies for building LCM within an MSYS2 MINGW64 environment using pacman and pacboy.
```shell
pacman -S pactoys git make
pacboy -S make toolchain cmake glib2 gtest python-pip
```
--------------------------------
### Java: Publish Example Message
Source: https://context7.com/lcm-proj/lcm/llms.txt
Publishes an example_t message using the LCM Java API. Ensure lcm.jar is in the classpath and example_t.java is generated.
```java
import java.io.*;
import lcm.lcm.*;
import exlcm.*;
// --- Publisher ---
class Publisher {
public static void main(String[] args) throws IOException {
LCM lcm = LCM.getSingleton();
example_t msg = new example_t();
msg.timestamp = System.nanoTime();
msg.position = new double[]{ 1.0, 2.0, 3.0 };
msg.orientation = new double[]{ 1.0, 0.0, 0.0, 0.0 };
msg.ranges = new short[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
msg.num_ranges = msg.ranges.length;
msg.name = "sensor_A";
msg.enabled = true;
lcm.publish("EXAMPLE", msg);
}
}
```
--------------------------------
### Install lcm-lua Library
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-lua/CMakeLists.txt
Installs the lcm-lua target to the appropriate library directory based on the system's library suffix and Lua version.
```cmake
install(TARGETS lcm-lua
DESTINATION lib${LIB_SUFFIX}/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
)
```
--------------------------------
### Example Transmitter Application in C#
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-dotnet.md
This C# code implements a transmitter application that publishes messages of type 'example_t' on the 'EXAMPLE' channel. Ensure the LCM library is correctly referenced.
```csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LCM;
namespace LCM.Examples
{
///
/// Demo transmitter, see LCM .NET tutorial for more information
///
class ExampleTransmit
{
public static void Main(string[] args)
{
try
{
LCM.LCM myLCM = LCM.LCM.Singleton;
exlcm.example_t msg = new exlcm.example_t();
TimeSpan span = DateTime.Now - new DateTime(1970, 1, 1);
msg.timestamp = span.Ticks * 100;
msg.position = new double[] { 1, 2, 3 };
msg.orientation = new double[] { 1, 0, 0, 0 };
msg.ranges = new short[] { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
msg.num_ranges = msg.ranges.Length;
msg.name = "example string";
msg.enabled = true;
myLCM.Publish("EXAMPLE", msg);
}
catch (Exception ex)
{
Console.Error.WriteLine("Ex: " + ex);
}
}
}
}
```
--------------------------------
### Configure and Install LCM Java Pkgconfig File
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-pkgconfig/CMakeLists.txt
Conditionally configures and installs the lcm-java.pc pkgconfig file if LCM Java support is enabled. This allows pkgconfig to find the LCM Java bindings.
```cmake
if(LCM_ENABLE_JAVA)
configure_file(lcm-java.pc.in ${lcm_BINARY_DIR}/lcm-java.pc @ONLY)
install(FILES ${lcm_BINARY_DIR}/lcm-java.pc
DESTINATION lib${LIB_SUFFIX}/pkgconfig)
endif()
```
--------------------------------
### Launch Graphical Log Player
Source: https://context7.com/lcm-proj/lcm/llms.txt
Start the Java-based graphical interface for playing back LCM log files, providing a visual way to inspect recorded data.
```bash
lcm-logplayer-gui recording.lcm
```
--------------------------------
### C LCM Message Listener
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-c.md
Subscribes to the 'EXAMPLE' channel and prints received messages. Ensure the 'exlcm_example_t' type is defined.
```c
#include
#include
#include
#include "exlcm_example_t.h"
static void
my_handler(const lcm_recv_buf_t *rbuf, const char * channel,
const exlcm_example_t * msg, void * user)
{
int i;
printf("Received message on channel \"%s\":\n", channel);
printf(" timestamp = %"PRId64"\n", msg->timestamp);
printf(" position = (%f, %f, %f)\n",
msg->position[0], msg->position[1], msg->position[2]);
printf(" orientation = (%f, %f, %f, %f)\n",
msg->orientation[0], msg->orientation[1], msg->orientation[2],
msg->orientation[3]);
printf(" ranges:");
for(i = 0; i < msg->num_ranges; i++)
printf(" %d", msg->ranges[i]);
printf("\n");
printf(" name = '%s'\n", msg->name);
printf(" enabled = %d\n", msg->enabled);
}
int
main(int argc, char ** argv)
{
lcm_t * lcm = lcm_create(NULL);
if(!lcm)
return 1;
exlcm_example_t_subscribe(lcm, "EXAMPLE", &my_handler, NULL);
while(1)
lcm_handle(lcm);
lcm_destroy(lcm);
return 0;
}
```
--------------------------------
### Build and Install LCM with CMake on Ubuntu/Debian
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Builds and installs LCM using CMake on Ubuntu or Debian systems. Assumes build directory is 'build'.
```shell
mkdir build
cd build
cmake ..
make
sudo make install
```
--------------------------------
### Example Receiver Application in C#
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-dotnet.md
This C# code implements a receiver application that subscribes to all channels and specifically processes messages of type 'example_t' received on the 'EXAMPLE' channel. It demonstrates how to deserialize and display message content.
```csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LCM;
namespace LCM.Examples
{
///
/// Demo listener, demonstrating interoperability with other implementations
/// Just run this listener and use any of the example_t message senders
///
class ExampleDisplay
{
public static void Main(string[] args)
{
LCM.LCM myLCM;
try
{
myLCM = new LCM.LCM();
myLCM.SubscribeAll(new SimpleSubscriber());
while (true)
System.Threading.Thread.Sleep(1000);
}
catch (Exception ex)
{
Console.Error.WriteLine("Ex: " + ex);
Environment.Exit(1);
}
}
internal class SimpleSubscriber : LCM.LCMSubscriber
{
public void MessageReceived(LCM.LCM lcm, string channel, LCM.LCMDataInputStream dins)
{
Console.WriteLine("RECV: " + channel);
if (channel == "EXAMPLE")
{
exlcm.example_t msg = new exlcm.example_t(dins);
Console.WriteLine("Received message of the type example_t:");
Console.WriteLine(" timestamp = {0:D}", msg.timestamp);
Console.WriteLine(" position = ({0:N}, {1:N}, {2:N})",
msg.position[0], msg.position[1], msg.position[2]);
Console.WriteLine(" orientation = ({0:N}, {1:N}, {2:N}, {3:N})",
msg.orientation[0], msg.orientation[1], msg.orientation[2],
msg.orientation[3]);
Console.Write(" ranges = [ ");
for (int i = 0; i < msg.num_ranges; i++)
{
Console.Write(" {0:D}", msg.ranges[i]);
if (i < msg.num_ranges-1)
Console.Write(", ");
}
Console.WriteLine(" ]");
Console.WriteLine(" name = '" + msg.name + "'" );
Console.WriteLine(" enabled = '" + msg.enabled + "'" );
}
}
}
}
}
```
--------------------------------
### Python LCM Message Listener
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-python.md
Sets up an LCM listener that subscribes to the 'EXAMPLE' channel and prints received message details. Ensure the 'exlcm' package is available for message decoding.
```python
import lcm
from exlcm import example_t
def my_handler(channel, data):
msg = example_t.decode(data)
print("Received message on channel \"%s\"" % channel)
print(" timestamp = %s" % str(msg.timestamp))
print(" position = %s" % str(msg.position))
print(" orientation = %s" % str(msg.orientation))
print(" ranges: %s" % str(msg.ranges))
print(" name = '%s'" % msg.name)
print(" enabled = %s" % str(msg.enabled))
print("")
lc = lcm.LCM()
subscription = lc.subscribe("EXAMPLE", my_handler)
try:
while True:
lc.handle()
except KeyboardInterrupt:
pass
```
--------------------------------
### Configure Gradle for LCM Dependency
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/java-notes.md
Example Gradle configuration to include LCM and custom types from local directories. It dynamically checks the OS name to set the repository path.
```groovy
// build.gradle
String osName = System.getProperty("os.name").toLowerCase();
project.logger.lifecycle(osName)
repositories {
mavenCentral()
flatDir {
if (osName.contains("linux")) {
dirs '/usr/local/share/java'
} // else TODO
dirs 'libs'
}
}
dependencies {
implementation ':lcm'
implementation ':my-lcm-types'
}
```
--------------------------------
### Publish LCM Message in C
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-c.md
Publishes a message of type 'exlcm_example_t' on the 'EXAMPLE' channel. Handles variable-length arrays by setting the count and pointer.
```c
#include
#include "exlcm_example_t.h"
int
main(int argc, char ** argv)
{
lcm_t * lcm = lcm_create(NULL);
if(!lcm)
return 1;
exlcm_example_t my_data = {
.timestamp = 0,
.position = { 1, 2, 3 },
.orientation = { 1, 0, 0, 0 },
};
int16_t ranges[15];
int i;
for(i = 0; i < 15; i++)
ranges[i] = i;
my_data.num_ranges = 15;
my_data.ranges = ranges;
my_data.name = "example string";
my_data.enabled = 1;
exlcm_example_t_publish(lcm, "EXAMPLE", &my_data);
lcm_destroy(lcm);
return 0;
}
```
--------------------------------
### Subscribe to LCM Channel and Process Messages in MATLAB
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-matlab.md
Initializes LCM, subscribes to the 'EXAMPLE' channel using a MessageAggregator, and enters a loop to wait for and process incoming messages. Decodes and displays message fields once a message is received.
```matlab
lc = lcm.lcm.LCM.getSingleton();
aggregator = lcm.lcm.MessageAggregator();
lc.subscribe('EXAMPLE', aggregator);
while true
disp waiting
millis_to_wait = 1000;
msg = aggregator.getNextMessage(millis_to_wait);
if ~isempty(msg)
break
end
end
disp(sprintf('channel of received message: %s', char(msg.channel)))
disp(sprintf('raw bytes of received message:'))
disp(sprintf('%d ', msg.data'))
m = exlcm.example_t(msg.data);
disp(sprintf('decoded message:\n'))
disp([ 'timestamp: ' sprintf('%d ', m.timestamp) ])
disp([ 'position: ' sprintf('%f ', m.position) ])
disp([ 'orientation: ' sprintf('%f ', m.orientation) ])
disp([ 'ranges: ' sprintf('%f ', m.ranges) ])
disp([ 'name: ' sprintf('%s ', m.name ])
disp([ 'enabled: ' sprintf('%d ', m.enabled) ])
```
--------------------------------
### Subscribe to LCM Channel and Handle Messages in Lua
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-lua.md
This Lua script subscribes to the 'EXAMPLE' channel and defines a handler function to decode and print received messages. It continuously processes incoming messages using lc:handle(). Ensure the 'exlcm' module is correctly set up.
```lua
local lcm = require('lcm')
-- this might be necessary depending on platform and LUA_PATH
package.path = './?/init.lua;' .. package.path
local exlcm = require('exlcm')
function array_to_str(array)
str = '{'
for i = 1, #array - 1 do
str = str .. array[i] .. ', '
end
return str .. array[#array] .. '}'
end
function my_handler(channel, data)
local msg = exlcm.example_t.decode(data)
print(string.format("Received message on channel \"%s\"", channel))
print(string.format(" timestamp = %d", msg.timestamp))
print(string.format(" position = %s", array_to_str(msg.position)))
print(string.format(" orientation = %s", array_to_str(msg.orientation)))
print(string.format(" ranges: %s", array_to_str(msg.ranges)))
print(string.format(" name = '%s'", msg.name))
print(string.format(" enabled = %s", tostring(msg.enabled)))
print("")
end
lc = lcm.lcm.new()
sub = lc:subscribe("EXAMPLE", my_handler)
while true do
lc:handle()
end
-- all remaining subscriptions are unsubed at garbage collection
```
--------------------------------
### Lua LCM Example Message Structure
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-lua.md
Defines the structure of the example_t LCM message in Lua, including fields for timestamp, position, orientation, ranges, name, and enabled status. Fixed-length arrays are initialized, while variable-length arrays start empty.
```lua
local example_t = {}
example_t.__index = example_t
example_t.name = 'exlcm.example_t'
example_t.packagename = 'exlcm'
example_t.shortname = 'example_t'
function example_t:new()
local obj = {}
obj.timestamp = 0
obj.position = {}
for d0 = 1, 3 do
obj.position[d0] = 0.0
end
obj.orientation = {}
for d0 = 1, 4 do
obj.orientation[d0] = 0.0
end
obj.num_ranges = 0
obj.ranges = {}
obj.name = ''
obj.enabled = false
setmetatable(obj, self)
return obj
end
```
--------------------------------
### Install LCM Python Module
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-python/CMakeLists.txt
Installs the compiled LCM Python module to the determined Python installation directory. This makes the module available for import in Python.
```cmake
install(TARGETS lcm-python
RUNTIME DESTINATION ${PYTHON_INSTALL_DIR}
LIBRARY DESTINATION ${PYTHON_INSTALL_DIR}
)
```
--------------------------------
### Preview Web Documentation
Source: https://github.com/lcm-proj/lcm/blob/master/CONTRIBUTING.md
Preview the built Sphinx documentation by serving the HTML files from the build directory. Replace 5000 with your preferred port.
```shell
cd ./docs/_build/html; python3 -m http.server 5000
```
--------------------------------
### Set Python Installation Directory
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-python/CMakeLists.txt
Determines the Python installation directory based on whether LCM is being built as a Python wheel. Adjusts the path for Python wheels to ensure correct installation.
```cmake
cmake_minimum_required(VERSION 3.12)
option(LCM_PIP_BUILD "When true, adjusts install path to something appropriate for a Python wheel" OFF)
if (NOT LCM_PIP_BUILD)
execute_process(
COMMAND "${Python_EXECUTABLE}" -c "if True:
from sysconfig import get_path
from os.path import sep
print(get_path('platlib').replace(get_path('data') + sep, ''))"
OUTPUT_VARIABLE PYTHON_SITE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(PYTHON_INSTALL_DIR ${PYTHON_SITE}/lcm)
else()
set(PYTHON_INSTALL_DIR lcm)
endif()
```
--------------------------------
### Launch Advanced Demo (Windows)
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-java/jchart2d-code/readme-binaries.txt
Run the AdvancedDynamicChart demo on Windows, including necessary third-party libraries in the classpath.
```bash
java -cp jchart2d-3.2.1.jar;xmlgraphics-commons-1.3.1.jar;bislider.jar info.monitorenter.gui.chart.demos.AdvancedDynamicChart
```
--------------------------------
### Python LCM Initialization
Source: https://context7.com/lcm-proj/lcm/llms.txt
Demonstrates initializing the Python LCM client, either by setting the LCM_DEFAULT_URL environment variable or by providing an explicit URL to the LCM constructor.
```python
import lcm, os
os.environ["LCM_DEFAULT_URL"] = "udpm://239.255.76.67:7667?ttl=1"
lc = lcm.LCM()
```
```python
lc = lcm.LCM("file:///tmp/test.lcm")
```
--------------------------------
### Launch Advanced Demo (Linux)
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-java/jchart2d-code/readme-binaries.txt
Run the AdvancedDynamicChart demo on Linux, including necessary third-party libraries in the classpath.
```bash
java -cp jchart2d-3.2.1.jar:xmlgraphics-commons-1.3.1.jar:bislider.jar info.monitorenter.gui.chart.demos.AdvancedDynamicChart
```
--------------------------------
### Install LCM on macOS via Homebrew
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/install-instructions.md
Use this command to install the LCM package on macOS systems using the Homebrew package manager.
```shell
brew install lcm
```
--------------------------------
### Install Debug Libraries on Windows
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-python/CMakeLists.txt
Installs debug DLLs on Windows. This targets files ending with '.dll' or '.DLL' in the build type specific directory.
```cmake
install(
DIRECTORY "${CMAKE_BINARY_DIR}/python/lcm/${CMAKE_BUILD_TYPE}/"
DESTINATION ${PYTHON_INSTALL_DIR}
FILES_MATCHING REGEX "[^\\/.]\.[dD][lL][lL]$"
)
```
--------------------------------
### Install LCM Python Module with VCPKG
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Install the Python module for LCM using pip, configuring CMake arguments to use the vcpkg preset.
```shell
pip install -v . --config-settings=cmake.args=--preset=vcpkg-vs
```
--------------------------------
### Build and Install LCM with CMake on OS X
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Builds and installs LCM using CMake on OS X. Assumes build directory is 'build'.
```shell
mkdir build
cd build
cmake ..
make
make install
```
--------------------------------
### Create LCM Instance with File Provider
Source: https://context7.com/lcm-proj/lcm/llms.txt
Instantiate an LCM client using the file provider to replay a log file. The 'speed' parameter allows controlling the playback rate.
```c
lcm_t *lcm = lcm_create("file:///path/to/recording.lcm?speed=2.0");
```
--------------------------------
### Instantiate Axis with Transformation Policy
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-java/jchart2d-code/readme-binaries.txt
Shows how to create an axis with a transformation scale policy, suitable for logarithmic scales.
```java
IAxis> axisTransformed = new AxisLog10();
```
--------------------------------
### Install LCM Python package on Ubuntu 24.04
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/install-instructions.md
Installs the LCM Python package specifically for Ubuntu 24.04 (Noble Numbat) using apt.
```shell
# On 24.04 (Noble Numbat) only
sudo apt install python3-lcm
```
--------------------------------
### Install LCM Python package on Ubuntu 18.04
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/install-instructions.md
Installs the LCM Python package specifically for Ubuntu 18.04 (Bionic Beaver) using apt.
```shell
# On 18.04 (Bionic Beaver) only
sudo apt install python-liblcm
```
--------------------------------
### Create Executable and Link Libraries
Source: https://github.com/lcm-proj/lcm/blob/master/examples/cpp/CMakeLists.txt
This section defines executables for 'listener', 'send_message', and 'read_log'. Each executable is linked against the 'example_messages-cpp' library and the LCM library, ensuring they can use LCM functionalities and message types.
```cmake
add_executable(listener "listener.cpp")
lcm_target_link_libraries(listener example_messages-cpp ${LCM_NAMESPACE}lcm)
add_executable(send_message "send_message.cpp")
lcm_target_link_libraries(send_message example_messages-cpp ${LCM_NAMESPACE}lcm)
add_executable(read_log "read_log.cpp")
lcm_target_link_libraries(read_log example_messages-cpp ${LCM_NAMESPACE}lcm)
```
--------------------------------
### Instantiate Axis with Manual Ticks Policy
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-java/jchart2d-code/readme-binaries.txt
Demonstrates how to instantiate an axis and set a manual ticks scale policy for custom tick control.
```java
IAxis> axis = new AxisLinear();
```
--------------------------------
### Java API - Subscriber
Source: https://context7.com/lcm-proj/lcm/llms.txt
Example of how to subscribe to messages using the Java LCM API. It defines a `Listener` class implementing `LCMSubscriber` to process incoming messages on the 'EXAMPLE' channel.
```APIDOC
### Subscriber
```java
import java.io.*;
import lcm.lcm.*;
import exlcm.*;
class Listener implements LCMSubscriber {
public void messageReceived(LCM lcm, String channel, LCMDataInputStream ins) {
try {
if ("EXAMPLE".equals(channel)) {
example_t msg = new example_t(ins);
System.out.printf("ts=%d pos=[%.1f,%.1f,%.1f] name=%s%n",
msg.timestamp,
msg.position[0], msg.position[1], msg.position[2],
msg.name);
}
} catch (IOException ex) {
System.err.println("decode error: " + ex);
}
}
public static void main(String[] args) throws Exception {
LCM lcm = new LCM(); // explicit instance
lcm.subscribe("EXAMPLE", new Listener());
// background thread handles receive; main thread sleeps
while (true) Thread.sleep(1000);
}
}
```
```
--------------------------------
### Update VCPKG Baseline
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Run this command to configure a newly-installed vcpkg. Ensure you are in a shell with the correct environment variables set.
```shell
vcpkg x-update-baseline --add-initial-baseline
```
--------------------------------
### Build Sphinx Documentation
Source: https://github.com/lcm-proj/lcm/blob/master/CONTRIBUTING.md
Build only the Sphinx site for web documentation. Ensure to run 'make clean html' within the docs directory for every rebuild.
```shell
cd ./docs; make clean html
```
--------------------------------
### Run LCM Tools Installed via pip
Source: https://context7.com/lcm-proj/lcm/llms.txt
Execute LCM command-line tools like logger, logplayer, and spy when they have been installed via pip, using the python -m command.
```bash
python -m lcm.run_logger
```
```bash
python -m lcm.run_logplayer
```
```bash
python -m lcm.run_spy
```
--------------------------------
### Build Javadocs for LCM Java API
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/java-notes.md
Run this script to generate Javadoc documentation for the LCM Java API. Ensure LCM is built first.
```none
$ lcm-java/make-javadocs.sh
```
--------------------------------
### Format C/C++ Code
Source: https://github.com/lcm-proj/lcm/blob/master/CONTRIBUTING.md
Run this script to format C and C++ code. It uses a specific version of clang-format for consistency. Consider using Docker if the required version is not available.
```shell
./format_code.sh
```
--------------------------------
### Configure LCM Type Generation for Installation
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-cmake.md
Set up CMake variables for LCM type generation, specifically distinguishing between files to be compiled and files intended for installation. This aids in organizing build artifacts.
```cmake
if(${Python_Interpreter_FOUND})
set(python_args PYTHON_SOURCES python_install_sources)
endif()
if(JAVA_FOUND)
set(java_args JAVA_SOURCES java_sources)
endif()
lcm_wrap_types(
C_EXPORT my_lcmtypes
C_SOURCES c_sources
C_HEADERS c_install_headers
CPP_HEADERS cpp_install_headers
${python_args}
${java_args}
my_type_1.lcm
my_type_2.lcm
...
)
```
--------------------------------
### Build LCM with VCPKG
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/build-instructions.md
Build the LCM project using the configured build directory and Release configuration.
```shell
cmake --build build --config Release
```
--------------------------------
### Install LCM Python package via pip
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/install-instructions.md
Installs the LCM Python package using pip. This package includes the LCM Python module, LCM executables, and development files. It has a hard runtime dependency on GLib 2.0.
```shell
pip3 install lcm
```
--------------------------------
### Create Executable and Link Libraries
Source: https://github.com/lcm-proj/lcm/blob/master/examples/cpp/lcm_log_writer/CMakeLists.txt
Defines the main executable for the log writer and links it against the generated message library and the LCM static library. This step integrates all components into a runnable application.
```cmake
add_executable(lcm_log_writer "main.cpp")
lcm_target_link_libraries(lcm_log_writer pjs_messages-cpp ${LCM_NAMESPACE}lcm-static)
```
--------------------------------
### Lua: Publish and Subscribe
Source: https://context7.com/lcm-proj/lcm/llms.txt
Demonstrates publishing and subscribing to messages using the Lua LCM binding. Requires lcm and exlcm modules.
```lua
local lcm = require('lcm')
package.path = './?/init.lua;' .. package.path -- adjust if needed
local exlcm = require('exlcm') -- generated with: lcm-gen -l example_t.lcm
-- --- Publish ---
local lc = lcm.lcm.new() -- default URL
local msg = exlcm.example_t:new()
msg.timestamp = 1234567890
msg.position = {1.5, 2.5, 3.5}
msg.orientation = {1.0, 0.0, 0.0, 0.0}
for i = 1, 10 do table.insert(msg.ranges, i * 5) end
msg.num_ranges = #msg.ranges
msg.name = "arm_joint_1"
msg.enabled = true
lc:publish("EXAMPLE", msg:encode())
-- --- Subscribe ---
local function on_message(channel, data)
local m = exlcm.example_t.decode(data)
print(string.format("[%s] ts=%d name=%s", channel, m.timestamp, m.name))
end
local sub = lc:subscribe("EXAMPLE", on_message)
-- Event loop with timeout for interleaved work
while true do
local got = lc:handle_timeout(200) -- returns true if message handled
if not got then
io.write(".") -- heartbeat
io.flush()
end
end
-- subscriptions are auto-cancelled at garbage collection
```
--------------------------------
### Create LCM Instance with Memory Queue Provider
Source: https://context7.com/lcm-proj/lcm/llms.txt
Instantiate an LCM client using the memory queue provider. This is suitable for unit tests as it avoids network sockets and provides in-process communication.
```c
lcm_t *lcm = lcm_create("memq://");
```
--------------------------------
### Configure Windows UDP Buffer Sizes
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/multicast-setup.md
Set registry keys to configure default receive and send window sizes on Windows. Requires administrator privileges and a system restart.
```powershell
Set registry keys:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\AFD\Parameters]
"DefaultReceiveWindow"=dword:00200000
"DefaultSendWindow"=dword:00200000
```
--------------------------------
### Find GLib2 and LCM Packages
Source: https://github.com/lcm-proj/lcm/blob/master/examples/cpp/lcm_log_writer/CMakeLists.txt
Configures the build to find the GLib2 and LCM libraries. Ensure FindGLib2.cmake is available in your CMAKE_MODULE_PATH if reusing this setup.
```cmake
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../../../cmake")
find_package(GLib2 REQUIRED)
find_package(lcm REQUIRED)
include(${LCM_USE_FILE})
```
--------------------------------
### Simplified API: Point Painter Usage
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-java/jchart2d-code/readme-binaries.txt
Demonstrates the simplified API for point highlighting. Use IPointPainter instead of IPointHighlighter and extend APointPainter instead of APointHighlighter. The PointHighlighterConfigurable class is replaced by directly using the PointPainter argument from its constructor.
```java
new PointPainterConfigurable(new PointPainterDisc(20), true) -> new PointPainterDisc(20)
```
--------------------------------
### Subscribe to LCM Channel in Java
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-java.md
Subscribes to messages on a specific channel ('EXAMPLE') using a custom LCMSubscriber. The LCM instance listens in a background thread.
```java
lcm.subscriber("EXAMPLE", new MySubscriber());
```
--------------------------------
### Record LCM Traffic with lcm-logger
Source: https://context7.com/lcm-proj/lcm/llms.txt
Start the lcm-logger utility to record all LCM traffic to a timestamped log file. This is the basic command for capturing data.
```bash
lcm-logger
```
--------------------------------
### Update Lua Module Paths with LuaRocks
Source: https://github.com/lcm-proj/lcm/blob/master/lcm-lua/rock/LUAROCKS_INSTALL.md
After installation, update Lua's `package.path` and `package.cpath` to recognize LuaRocks modules by evaluating the output of `luarocks path`.
```bash
$ luarocks path
```
```bash
$ eval $(luarocks path)
```
--------------------------------
### Configure Loopback Interface for Multicast on Linux
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/multicast-setup.md
Use these commands on Linux to enable multicast traffic on the loopback interface if your machine is not connected to an external network and you need to use LCM locally.
```default
sudo ifconfig lo multicast
sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev lo
```
--------------------------------
### C Structs for Mutually Recursive Types
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/lcm-type-ref.md
Example C struct definitions demonstrating mutual recursion between types A, B, and C, which necessitates careful fingerprint computation.
```C
struct A
{
B b;
C c;
}
struct B
{
A a;
}
struct C
{
B b;
}
```
--------------------------------
### LCM Java Build and Run Commands
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/tutorial-java.md
These commands demonstrate the process of compiling and running LCM Java applications. It includes generating Java code from LCM types, compiling with the LCM JAR, and executing the subscriber and sender applications.
```bash
# 1. Create the Java implementation of temperature_t.lcm
lcm-gen -j example_t.lcm
# 2. Compile the demo applications and the LCM type created above.
javac -cp .:lcm.jar *.java exlcm/*.java
# 3. Run MySubscriber (in one terminal)
java -cp .:lcm.jar MySubscriber
# 4. Run SendMessage (in another terminal)
java -cp .:lcm.jar SendMessage
```
--------------------------------
### Define a Struct with Comments in LCM
Source: https://github.com/lcm-proj/lcm/blob/master/docs/content/lcm-type-ref.md
LCM structs are compound types. This example shows a simple struct with integer and double fields, including single-line and multi-line comments.
```C
struct temperature_t
{
int64_t utime; // Timestamp, in microseconds
/* Temperature in degrees Celsius. A "float" would probably
* be good enough, unless we're measuring temperatures during
* the big bang. Note that the asterisk on the beginning of this
* line is not syntactically necessary, it's just pretty.
*/
double degCelsius;
}
```
--------------------------------
### Set Minimum CMake Version and Project Name
Source: https://github.com/lcm-proj/lcm/blob/master/examples/cpp/lcm_log_writer/CMakeLists.txt
Specifies the minimum required CMake version and sets the project name. This is a standard starting point for any CMake project.
```cmake
cmake_minimum_required(VERSION 3.10)
project(lcm_log_writer)
```