rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
motor_draw.c File Reference

The MOTOR & ESC screen's drawing: the strip row, the rail with the readouts and the CONTROL card, LIVE's plot or table and the throttle, and the page of the task shown. motor_screen.c holds the state, the commands and the screen's interface (motor_screen.h); motor_live_int.h is what it shares with this file and motor_events.c. More...

#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include "motor_screen.h"
#include "ui_band.h"
#include "ui_hero.h"
#include "ui_plot.h"
#include "link_pages.h"
#include "settings.h"
#include "ui_slider.h"
#include "ui_tabs.h"
#include "outputs_screen.h"
#include "port_view.h"
#include "ui_text.h"
#include "ui_theme.h"
#include "ui_widgets.h"
#include "motor_live_int.h"

Macros

#define TABLE_ROW_Y(i)
 Channel row i's top, px.
#define ESC_RULE_Y   (TABLE_ROW_Y(S_COUNT) - 6)
 The rule over the ESC's rows, px.
#define ESC_ROW_Y(i)
 The ESC's row i's top, px: 0 voltage, 1 current.
#define TBL_VAL_DX   150
#define TBL_UNIT_DX   250
#define TBL_PK_DX   300

Enumerations

enum  { TAG_LIVE = 0 , TAG_HELD , TAG_IDLE , TAG_COUNT }

Functions

static gfx_color_t arm_fill (void)
 Green while it will arm, red by the time the fade completes, and white for the flash as the arm takes effect. With nothing held and nothing flashing this is the plain OK or WARN the button has always carried.
static void draw_arm (gfx_canvas_t *c)
 ARM, or DISARM while the bench is armed, in its fill of the moment, on the rail where SERVO has its ARM.
static void temp_text (char *out, size_t n, const char *label, float v, bool ok)
 A temperature as the header line says it: "ESC 44°C", or "ESC --" when nothing has answered.
static void draw_header (gfx_canvas_t *c, bool on_live)
 On LIVE, the poll rate and the link's errors right of PLOT | TABLE, and under them, while the IOmcu has refused a frame, how many; on every task, how hot the three things that get hot, on the line over the rail. MCU is the panel's own die, not the IOmcu's.
static void draw_derived (gfx_canvas_t *c)
 The rated kV, what the motor is actually turning per volt, and what the ratio of the two says about the drivetrain.
static void draw_esc_says (gfx_canvas_t *c)
 What the ESC says beside what the INA228 measures, while the INA228 is BENCH's source: the ESC's own telemetry voltage and current from the SENSE page, and how far each is from the INA228's, the ESC's less the INA228's. An ESC that reports a current with no sensor behind it shows here as a difference the size of the reading.
static void draw_table (gfx_canvas_t *c)
 Draws the readings table: a row per channel with its present value and its extreme.
static int num_text (gfx_canvas_t *c, int right, int y, int w, const char *t, gfx_color_t col)
 A reading's numerals in the 32 x 44 face, the 20 x 36 one where they are wider than w, right-aligned to right.
static void draw_rail_card (gfx_canvas_t *c, gfx_rect_t r, const ui_hero_def_t *def, float value, float peak)
 One card of the rail, HERO_H px high: the name and the extreme stacked on the left, the live value in the 32 x 44 numerals, right-aligned with its unit.
static void draw_heroes (gfx_canvas_t *c)
 The rail: one card per channel, live value over its extreme.
static void draw_totals (gfx_canvas_t *c)
 What the run has taken out of the pack, on the CONTROL card's title line, right of its tag: STEUERUNG's 9 cells of 8px and the tab's 26.
static const char * tag_text (uint8_t tag, char *buf, size_t n)
 Writes the tag's text, padded to the widest tag.
static uint8_t telemetry_tag (void)
 Returns the tag of the telemetry heading: LIVE while the plot is not shown or runs, HELD or IDLE otherwise.
static void draw_throttle (gfx_canvas_t *c, bool ctrl_moved)
 LIVE's throttle card: the readout on the title line, the step keys and the track. A throttle that moved on its own clears the readout's own box and the slider's painted region, not the card: a drag asks for it on every frame. The slider's region is what the widget reports rather than its track, because the thumb and its shadow stand proud of the track.
static void render_session (gfx_canvas_t *c, unsigned bit, int buf, const prog_page_set_t *ps)
 A session on PROGRAM, full width: the output strip in the strip row, on its text, and the session under it, on its revision.
static void render_body (gfx_canvas_t *c, unsigned bit, int buf)
 Draws the screen's body into the frame buffer buf: the strip, the page of the task and the rail.
void mo_render (gfx_canvas_t *c, int buffer_index)
 Draws the screen into frame buffer buffer_index.

Variables

static const ui_text_id_t k_extreme [S_COUNT]
 Voltage's interesting extreme is the minimum – what the pack does under load is how far down it goes – and every other channel's is the maximum.
static const ui_text_id_t k_tag [TAG_COUNT]
 Text of each telemetry tag: LIVE, HELD, IDLE.

Detailed Description

The MOTOR & ESC screen's drawing: the strip row, the rail with the readouts and the CONTROL card, LIVE's plot or table and the throttle, and the page of the task shown. motor_screen.c holds the state, the commands and the screen's interface (motor_screen.h); motor_live_int.h is what it shares with this file and motor_events.c.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ ESC_ROW_Y

#define ESC_ROW_Y ( i)
Value:
(ESC_RULE_Y + 8 + (i) * 28)
#define ESC_RULE_Y
The rule over the ESC's rows, px.
Definition motor_draw.c:239

The ESC's row i's top, px: 0 voltage, 1 current.

◆ TABLE_ROW_Y

#define TABLE_ROW_Y ( i)
Value:
(LEG_Y + 30 + (i) * 32)
#define LEG_Y
Definition motor_live_int.h:42

Channel row i's top, px.

◆ TBL_PK_DX

#define TBL_PK_DX   300

The extreme's column, under PEAK, px.

◆ TBL_UNIT_DX

#define TBL_UNIT_DX   250

The unit's column, px.

◆ TBL_VAL_DX

#define TBL_VAL_DX   150

The value's column, from the left, px.

Function Documentation

◆ draw_arm()

void draw_arm ( gfx_canvas_t * c)
static

ARM, or DISARM while the bench is armed, in its fill of the moment, on the rail where SERVO has its ARM.

Parameters
cthe canvas

◆ draw_derived()

void draw_derived ( gfx_canvas_t * c)
static

The rated kV, what the motor is actually turning per volt, and what the ratio of the two says about the drivetrain.

The arithmetic is sound and the number is still an estimate, which is why it is labelled EFF rather than efficiency. Terminal voltage splits into the resistive drop and the back-EMF, so rpm/V under load is the rated kV scaled by the fraction of the voltage reaching the back-EMF, and in an ideal motor that fraction is the conversion efficiency exactly.

This motor is not that one. The figure counts copper loss only, so iron loss, friction and windage are missing and it is an upper bound rather than a value. The bench measures pack voltage rather than the motor's terminals, so the ESC's losses are inside it and it describes the drivetrain. And it is only as good as the rated kV, an error in which maps straight into the percentage. docs/Screens.md says so in the words an operator reads.

The rated value comes from the connected ESC when it reports one, and from SET_MOTOR_KV when it does not. Nothing is assumed: with neither, the field is drawn empty and no efficiency is shown, because a guessed kV produces a plausible-looking percentage that is wrong.

◆ draw_header()

void draw_header ( gfx_canvas_t * c,
bool on_live )
static

On LIVE, the poll rate and the link's errors right of PLOT | TABLE, and under them, while the IOmcu has refused a frame, how many; on every task, how hot the three things that get hot, on the line over the rail. MCU is the panel's own die, not the IOmcu's.

Parameters
cthe canvas
on_livewhether LIVE is shown

◆ draw_rail_card()

void draw_rail_card ( gfx_canvas_t * c,
gfx_rect_t r,
const ui_hero_def_t * def,
float value,
float peak )
static

One card of the rail, HERO_H px high: the name and the extreme stacked on the left, the live value in the 32 x 44 numerals, right-aligned with its unit.

Parameters
cthe canvas
rthe card
defthe channel's name, unit, colour and decimals
valuethe live value, NAN for none
peakthe extreme, NAN for none

◆ draw_throttle()

void draw_throttle ( gfx_canvas_t * c,
bool ctrl_moved )
static

LIVE's throttle card: the readout on the title line, the step keys and the track. A throttle that moved on its own clears the readout's own box and the slider's painted region, not the card: a drag asks for it on every frame. The slider's region is what the widget reports rather than its track, because the thumb and its shadow stand proud of the track.

Parameters
cthe canvas
ctrl_movedwhether a control changed its look: the card under the title line is cleared whole

◆ mo_render()

void mo_render ( gfx_canvas_t * c,
int buffer_index )

Draws the screen into frame buffer buffer_index.

Parameters
ccanvas drawn on
buffer_indexthe frame buffer

◆ num_text()

int num_text ( gfx_canvas_t * c,
int right,
int y,
int w,
const char * t,
gfx_color_t col )
static

A reading's numerals in the 32 x 44 face, the 20 x 36 one where they are wider than w, right-aligned to right.

Parameters
cthe canvas
righttheir right edge, px
ytheir top, px
wthe width they may take, px
tthe numerals
coltheir colour
Returns
their left edge, px

◆ temp_text()

void temp_text ( char * out,
size_t n,
const char * label,
float v,
bool ok )
static

A temperature as the header line says it: "ESC 44°C", or "ESC --" when nothing has answered.

Parameters
outtakes the text
nbytes at out
labelwhat it is the temperature of
vthe temperature, °C
okwhether v was read

Variable Documentation

◆ k_extreme

const ui_text_id_t k_extreme[S_COUNT]
static
Initial value:
= { TX_HERO_MIN, TX_HERO_PEAK,
TX_HERO_PEAK, TX_HERO_PEAK }

Voltage's interesting extreme is the minimum – what the pack does under load is how far down it goes – and every other channel's is the maximum.

◆ k_tag

const ui_text_id_t k_tag[TAG_COUNT]
static
Initial value:
= {
TX_MO_TAG_LIVE, TX_MO_TAG_HELD, TX_MO_TAG_IDLE,
}

Text of each telemetry tag: LIVE, HELD, IDLE.