Skip to content

UZ9/pros-grafana-lib

Repository files navigation

Pros Grafana Lib

 

PROS Grafana Library

Github top language

🚧 This library is still highly experimental 🚧


About   |   Features   |   Technologies   |   Requirements   |   Starting   |   Usage   |   Author


🎯 About

This project aims to improve the VEX Robotics development process by allowing statistics to easily be recorded by a V5 brain and in realtime be sent to a Grafana dashboard. The PROS Grafana Library consists of three parts:

  • The PROS C++ template (this repository)
  • The PROS-Grafana CLI, adding a custom command for brain interaction
  • (Unfinished) The optional Grafana plugin allowing for custom visualization of data such as absolute positioning

✨ Features

✔️ Easily track multiple objects at once
✔️ Easy chart and visualization creation
✔️ Wireless support

🚀 Technologies

The following tools were used in this project:

✅ Requirements

Before starting 🏁, you need to have Git installed and a PROS project.

🏁 Starting

To use the template in your PROS project, you must first download the template zip (pros-grafana-lib@1.0.0.zip) from the repository.

You can install it using the following commands in a terminal at the root of your project:

# Import the zip to the PROS depot - the zip must be in the same directory as your current terminal path
$ pros c fetch pros-grafana-lib@1.0.0.zip

# Apply the library to your project
$ pros c apply pros-grafana-lib --force-apply

📝 Usage

For an example in context, please see src/opcontrol.cpp.

To access the template, you can import the following header: #include "pros-grafana-lib/api.h"

First, you need to initialize the GUIManager:

auto manager = std::make_shared<grafanalib::GUIManager>();

// The interval in milliseconds at which data should be sent (default 20ms).
// A few disclaimers:
// - A rate too fast will cause data to be dropped
// - Wireless is significantly limited in its speed, requiring a refresh rate of > 100ms. 
manager->setRefreshRate(20);

For testing, a few dummy motor objects will be created. In reality, these can be any object you want to track.

// Standard motor declarations 
pros::Motor leftFrontMotor(1);
pros::Motor rightFrontMotor(2);
pros::Motor leftBackMotor(3);
pros::Motor rightBackMotor(4);

We then have to create Variable objects that are responsible for managing display names and 'getters':

// Declare the variables we'll be tracking 
grafanalib::Variable<pros::Motor> leftFrontMotorVar("Left Front Motor", leftFrontMotor);
grafanalib::Variable<pros::Motor> rightFrontMotorVar("Right Front Motor", rightFrontMotor);
grafanalib::Variable<pros::Motor> leftBackMotorVar("Left Back Motor", leftBackMotor);
grafanalib::Variable<pros::Motor> rightBackMotorVar("Right Back Motor", rightBackMotor);

// If you have a group of motors (e.g. chassis) that you want to track together, you can make a VariableGroup:
grafanalib::VariableGroup<pros::Motor> chassisVars({leftFrontMotorVar, rightFrontMotorVar, leftBackMotorVar, rightBackMotorVar});

Now that the variables are declared, we choose which methods from the objects to track and the name they'll be given in the Grafana dashboard:

// Getters added to a VariableGRroup will add getters to ALL of the Variables assigned to it 
// In this example, the GUI will track the temperature, actual velocity, efficiency, 
// and voltage for all 4 chassis motors.
// Format: add_getter(<what the property should display as>, <a reference to the function the getter will pull from>)
chassisVars.add_getter("Temperature", &pros::Motor::get_temperature);
chassisVars.add_getter("Actual Velocity", &pros::Motor::get_actual_velocity);
chassisVars.add_getter("Voltage", &pros::Motor::get_voltage);
chassisVars.add_getter("Efficiency", &pros::Motor::get_efficiency);

Finally, we register the Variables or VariableGroups to the GUIManager and start the task:

// Variable groups and variables must then be registered to the GUIManager:
manager->registerDataHandler(&chassisVars);

// You can start the data task at any time:
manager->startTask();

For using this tracking in conjunction with Grafana and the CLI, please navigate to the pros-grafana-cli repository for the next steps.


Made with ❤️ by Ryder

 

Back to top

About

A VEX PROS library for easily visualizing information.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published