SDK Introduction
The Foxglove SDK allows you to quickly and easily:
- Stream and visualize your robot data live in Foxglove
- Log your data to MCAP files
The SDK is available for C++, Python, and Rust under the MIT license.
This documentation provides an overview of the SDK to help you get started. For more detailed information, see the additional resources for each language below.
Installation
- Rust
- Python
- C++
Install foxglove
from crates.io: https://crates.io/crates/foxglove
cargo add foxglove
Install foxglove-sdk
from PyPI: https://pypi.org/project/foxglove-sdk
pip install foxglove-sdk
The C++ SDK is a wrapper around a C library. To build it, you will need to link that library and compile the SDK source as part of your build process. The SDK assumes C++17 or newer.
Download the library, source, and header files for your platform from the SDK release assets.
If you're using CMake, you can reference the SDK's CMakeLists.txt file for an example.
Getting started
Here's a minimal example that sends Log messages to the Foxglove app.
When you run this example and open a Log panel in the Foxglove app, you'll see messages logged a few times per second.
- Rust
- Python
- C++
use foxglove::{
WebSocketServer, log,
schemas::{Log, Timestamp, log::Level},
};
use std::{thread, time::Duration};
fn main() {
WebSocketServer::new()
.start_blocking()
.expect("Server failed to start");
loop {
log!(
"/hello",
Log {
level: Level::Info.into(),
timestamp: Some(Timestamp::now()),
message: "Hello, Foxglove!".to_string(),
..Default::default()
}
);
thread::sleep(Duration::from_millis(100));
}
}
import foxglove
import time
from foxglove.schemas import Log, LogLevel, Timestamp
server = foxglove.start_server()
while True:
foxglove.log(
"/hello",
Log(
timestamp=Timestamp.now(),
level=LogLevel.Info,
message="Hello, Foxglove!",
)
)
time.sleep(0.033)
#include <foxglove/server.hpp>
#include <foxglove/schemas.hpp>
#include <thread>
int main(int argc, const char *argv[])
{
foxglove::WebSocketServerOptions ws_options;
auto server = foxglove::WebSocketServer::create(std::move(ws_options)).value();
auto channel = foxglove::schemas::LogChannel::create("/hello").value();
while (true)
{
const auto now = std::chrono::system_clock::now();
const auto nanos_since_epoch = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
const auto seconds_since_epoch = nanos_since_epoch / 1000000000;
const auto remaining_nanos = nanos_since_epoch % 1000000000;
foxglove::schemas::Log log;
log.level = foxglove::schemas::Log::LogLevel::INFO;
log.message = "Hello, Foxglove!";
log.timestamp = foxglove::Timestamp{
static_cast<uint32_t>(seconds_since_epoch),
static_cast<uint32_t>(remaining_nanos)};
channel.log(log);
std::this_thread::sleep_for(std::chrono::milliseconds(33));
}
return 0;
}
Reference
Reference API documentation, additional examples, and other resources for each SDK language.
- Rust
- Python
- C++