Skip to content

Telemetry Overhaul using Class Object Reference Arrays and toString() #42

@MGross21

Description

@MGross21

Priority Level: Low

Refactor the telemetry system to pass objects directly instead of manually defining individual telemetry fields. See current implementation example:

private fun addTelemetryData() {
telemetry.addData("Drive Power", driver1.drivePower)
telemetry.addData("Flywheel TPS", bot.flywheel?.velocity)
telemetry.addData("Flywheel Speed", driver2.flywheelSpeed)
telemetry.addData("Field Centric", driver1.fieldCentric)
telemetry.addData("Pose", bot.pinpoint!!.pose)
telemetry.addData("Velocity", "vx: %.2f, vy: %.2f".format(bot.pinpoint?.pose?.vx, bot.pinpoint?.pose?.vy))
telemetry.addData("Voltage", bot.batteryMonitor?.voltage)
telemetry.addData("Flywheel Motor Current", bot.flywheel?.motor?.getCurrent(CurrentUnit.MILLIAMPS))
}

Each hardware or subsystem class will implement a structured toString() method, similar to the example below:

Example implementation:

override fun toString(): String {
val (r, g, b) = normalizedRGBA
val (h, s, v) = normalizedHSV
val d = distance
return "R: %.1f G: %.1f B: %.1f H: %.1f S: %.1f V: %.1f D: %.1f cm".format(
r,
g,
b,
h,
s,
v,
d
)
}

Proposed usage:

val telemetryArgs = mutableListOf<Any>(Object1, Object2, Object3)

Telemetry addition:

fun addLines(objs: List<Any?>) {
    for (obj in objs) {
        if (obj != null) { // check against nulled hardware objects
            phone.addLine(obj::class.simpleName, obj.toString())
            // plus other code as needed
        }
    }
}

Running:

telemetry.addLines(telemetryArgs)
telemetry.update()

Appending new objects later:

telemetryArgs += ObjN

Goal is to simplify telemetry definitions in opmodes. This can be placed in bot (ideally) or OpMode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions