mirror of
https://github.com/randybb/esphome-configs.git
synced 2026-12-06 09:06:52 +01:00
stackchan: robot_face component, moods and head spin, servo end stops
- face drawn by the robot_face component (moods, gaze, blinks; laugh/confused animations, wink, sleep/wake) instead of the display lambda and its globals - moods from touch, shake and NFC cards; HA actions for moods and spinning the head - head spin: yaw servo in wheel mode (angle limits 0/0), limits put back afterwards - pitch end stops written into the servo's angle limits, measured servo positions - per-task CPU time over 10 s (FreeRTOS run time stats)
This commit is contained in:
1 parent
bba78dbb17
commit
9a158bab19
1 file changed
+243
-151
+243
-151
@@ -56,6 +56,16 @@ esphome:
|
|||||||
- priority: 700
|
- priority: 700
|
||||||
then:
|
then:
|
||||||
- script.execute: bus_power_on
|
- script.execute: bus_power_on
|
||||||
|
# pitch end stops into the servo's own angle limits (no EEPROM unlock: until the next power cycle)
|
||||||
|
- priority: -100
|
||||||
|
then:
|
||||||
|
- delay: 2s
|
||||||
|
- lambda: |-
|
||||||
|
auto *bus = id(y_servo).get_parent();
|
||||||
|
bus->write_word(2, SCSCL_MIN_ANGLE_LIMIT_L, 645);
|
||||||
|
bus->write_word(2, SCSCL_MAX_ANGLE_LIMIT_L, 912);
|
||||||
|
ESP_LOGI("pitch", "Angle limits %d..%d", bus->read_word(2, SCSCL_MIN_ANGLE_LIMIT_L),
|
||||||
|
bus->read_word(2, SCSCL_MAX_ANGLE_LIMIT_L));
|
||||||
- priority: -100
|
- priority: -100
|
||||||
then:
|
then:
|
||||||
- light.turn_on:
|
- light.turn_on:
|
||||||
@@ -75,6 +85,11 @@ esp32:
|
|||||||
advanced:
|
advanced:
|
||||||
flash_chip: generic
|
flash_chip: generic
|
||||||
type: esp-idf
|
type: esp-idf
|
||||||
|
sdkconfig_options:
|
||||||
|
# per-task CPU time for the task_stats interval
|
||||||
|
CONFIG_FREERTOS_USE_TRACE_FACILITY: y
|
||||||
|
CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS: y
|
||||||
|
CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID: y
|
||||||
|
|
||||||
psram:
|
psram:
|
||||||
mode: quad
|
mode: quad
|
||||||
@@ -89,7 +104,7 @@ external_components:
|
|||||||
components: [axp2101, aw88298, aw9523b, si12t, ftservo, scs9009]
|
components: [axp2101, aw88298, aw9523b, si12t, ftservo, scs9009]
|
||||||
refresh: 0s
|
refresh: 0s
|
||||||
- source: github://randybb/esphome-components
|
- source: github://randybb/esphome-components
|
||||||
components: [audio_spectrum, m5ioe1]
|
components: [audio_spectrum, m5ioe1, robot_face]
|
||||||
refresh: 1h
|
refresh: 1h
|
||||||
# st25r upstream has SPI only, st25r_i2c is still on this branch
|
# st25r upstream has SPI only, st25r_i2c is still on this branch
|
||||||
- source: github://m5stack/esphome@feat-st25r3916
|
- source: github://m5stack/esphome@feat-st25r3916
|
||||||
@@ -97,38 +112,17 @@ external_components:
|
|||||||
refresh: 1d
|
refresh: 1d
|
||||||
|
|
||||||
globals:
|
globals:
|
||||||
- id: in_love
|
|
||||||
type: bool
|
|
||||||
initial_value: 'false'
|
|
||||||
- id: show_status
|
- id: show_status
|
||||||
type: bool
|
type: bool
|
||||||
initial_value: 'true'
|
initial_value: 'true'
|
||||||
- id: mouth_open
|
|
||||||
type: float
|
|
||||||
initial_value: '0.0'
|
|
||||||
- id: eyes_open
|
|
||||||
type: bool
|
|
||||||
initial_value: 'true'
|
|
||||||
- id: speaking
|
|
||||||
type: bool
|
|
||||||
initial_value: 'false'
|
|
||||||
- id: listening
|
- id: listening
|
||||||
type: bool
|
type: bool
|
||||||
initial_value: 'false'
|
initial_value: 'false'
|
||||||
- id: gaze_x
|
|
||||||
type: int
|
|
||||||
initial_value: '0'
|
|
||||||
- id: gaze_y
|
|
||||||
type: int
|
|
||||||
initial_value: '0'
|
|
||||||
- id: dizzy
|
|
||||||
type: bool
|
|
||||||
initial_value: 'false'
|
|
||||||
- id: surprised
|
|
||||||
type: bool
|
|
||||||
initial_value: 'false'
|
|
||||||
- id: speech
|
- id: speech
|
||||||
type: std::string
|
type: std::string
|
||||||
|
- id: spin_limits # yaw servo angle limits while spinning: max << 16 | min
|
||||||
|
type: int
|
||||||
|
initial_value: '0'
|
||||||
|
|
||||||
i2c:
|
i2c:
|
||||||
- id: i2c_bsp
|
- id: i2c_bsp
|
||||||
@@ -311,7 +305,6 @@ media_player:
|
|||||||
- platform: speaker
|
- platform: speaker
|
||||||
id: media_out
|
id: media_out
|
||||||
name: Player
|
name: Player
|
||||||
buffer_size: 14000
|
|
||||||
# AW88298 maps volume linearly to -96..0 dB, the lower half is inaudible
|
# AW88298 maps volume linearly to -96..0 dB, the lower half is inaudible
|
||||||
volume_min: 0.5
|
volume_min: 0.5
|
||||||
volume_max: 1.0
|
volume_max: 1.0
|
||||||
@@ -360,27 +353,33 @@ voice_assistant:
|
|||||||
- lambda: id(show_status) = true;
|
- lambda: id(show_status) = true;
|
||||||
- component.update: display_tft
|
- component.update: display_tft
|
||||||
on_listening:
|
on_listening:
|
||||||
|
# someone talks: a look with one eye, then with both
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
id(listening) = true;
|
id(listening) = true;
|
||||||
id(gaze_x) = 0;
|
id(face).peek(0);
|
||||||
id(gaze_y) = 0;
|
id(face).look(0, 0);
|
||||||
- component.update: display_tft
|
- component.update: display_tft
|
||||||
- light.turn_on: {id: light_bar, brightness: 60%, red: 0%, green: 60%, blue: 100%}
|
- light.turn_on: {id: light_bar, brightness: 60%, red: 0%, green: 60%, blue: 100%}
|
||||||
on_stt_end:
|
on_stt_end:
|
||||||
- lambda: id(listening) = false;
|
# thinking: looks up to the side
|
||||||
|
- lambda: |-
|
||||||
|
id(listening) = false;
|
||||||
|
id(face).look(0.6f, -0.8f);
|
||||||
- component.update: display_tft
|
- component.update: display_tft
|
||||||
- light.turn_on: {id: light_bar, brightness: 40%, red: 80%, green: 50%, blue: 0%}
|
- light.turn_on: {id: light_bar, brightness: 40%, red: 80%, green: 50%, blue: 0%}
|
||||||
on_tts_start:
|
on_tts_start:
|
||||||
- lambda: id(speaking) = true;
|
- lambda: |-
|
||||||
|
id(face).look(0, 0);
|
||||||
|
id(face).set_speaking(true);
|
||||||
- light.turn_on: {id: light_bar, brightness: 60%, red: 0%, green: 100%, blue: 20%}
|
- light.turn_on: {id: light_bar, brightness: 60%, red: 0%, green: 100%, blue: 20%}
|
||||||
on_end:
|
on_end:
|
||||||
- wait_until:
|
- wait_until:
|
||||||
not:
|
not:
|
||||||
media_player.is_announcing: media_out
|
media_player.is_announcing: media_out
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
id(speaking) = false;
|
|
||||||
id(listening) = false;
|
id(listening) = false;
|
||||||
id(mouth_open) = 0.0f;
|
id(face).set_speaking(false);
|
||||||
|
id(face).set_idle(true);
|
||||||
- component.update: display_tft
|
- component.update: display_tft
|
||||||
- light.turn_on: {id: light_bar, brightness: 20%, red: 0%, green: 0%, blue: 100%}
|
- light.turn_on: {id: light_bar, brightness: 20%, red: 0%, green: 0%, blue: 100%}
|
||||||
- wait_until:
|
- wait_until:
|
||||||
@@ -388,6 +387,10 @@ voice_assistant:
|
|||||||
- micro_wake_word.start:
|
- micro_wake_word.start:
|
||||||
on_error:
|
on_error:
|
||||||
- light.turn_on: {id: light_bar, brightness: 60%, red: 100%, green: 0%, blue: 0%}
|
- light.turn_on: {id: light_bar, brightness: 60%, red: 100%, green: 0%, blue: 0%}
|
||||||
|
- script.execute:
|
||||||
|
id: show_mood
|
||||||
|
mood: sad
|
||||||
|
seconds: 3
|
||||||
|
|
||||||
script:
|
script:
|
||||||
# Powers the 5 V BUS from the battery (as in m5stack/esphome-yaml stackchan base).
|
# Powers the 5 V BUS from the battery (as in m5stack/esphome-yaml stackchan base).
|
||||||
@@ -411,24 +414,53 @@ script:
|
|||||||
}
|
}
|
||||||
id(bus_out_en).turn_on();
|
id(bus_out_en).turn_on();
|
||||||
delay(100);
|
delay(100);
|
||||||
# shake: dizzy eyes for a while
|
# a mood for a while, then back to neutral (stroke: love, shake: dizzy, card: surprised)
|
||||||
- id: shake_reaction
|
- id: show_mood
|
||||||
mode: restart
|
mode: restart
|
||||||
|
parameters:
|
||||||
|
mood: string
|
||||||
|
seconds: int
|
||||||
then:
|
then:
|
||||||
- lambda: id(dizzy) = true;
|
- lambda: |-
|
||||||
- component.update: display_tft
|
if (id(face).is_sleeping())
|
||||||
- delay: 3s
|
id(face).peek(0);
|
||||||
- lambda: id(dizzy) = false;
|
id(face).set_mood(mood);
|
||||||
- component.update: display_tft
|
- delay: !lambda return seconds * 1000;
|
||||||
# a card laid on the head: big round eyes and an O mouth
|
- lambda: id(face).set_mood(robot_face::MOOD_NEUTRAL);
|
||||||
- id: surprise_reaction
|
# spins the head around (yaw servo, address 1) in wheel mode: angle limits 0/0 turn the SCS9009
|
||||||
mode: restart
|
# into a motor driven by PWM. The limits are written without unlocking the EEPROM, so they are
|
||||||
|
# only changed until the next power cycle, and they are put back once the spin is over.
|
||||||
|
- id: spin
|
||||||
|
mode: single
|
||||||
|
parameters:
|
||||||
|
seconds: float
|
||||||
|
power: int # -1000..1000, the sign is the direction
|
||||||
then:
|
then:
|
||||||
- lambda: id(surprised) = true;
|
- lambda: |-
|
||||||
- component.update: display_tft
|
auto *bus = id(x_servo).get_parent();
|
||||||
- delay: 3s
|
const int min = bus->read_word(1, SCSCL_MIN_ANGLE_LIMIT_L);
|
||||||
- lambda: id(surprised) = false;
|
const int max = bus->read_word(1, SCSCL_MAX_ANGLE_LIMIT_L);
|
||||||
- component.update: display_tft
|
if (min < 0 || max <= 0) {
|
||||||
|
ESP_LOGW("spin", "Angle limits not readable (%d/%d), not spinning", min, max);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
id(spin_limits) = (max << 16) | min;
|
||||||
|
ESP_LOGI("spin", "Spinning %.1f s at %d, limits %d..%d", seconds, power, min, max);
|
||||||
|
bus->enable_torque(1, 1);
|
||||||
|
bus->pwm_mode(1);
|
||||||
|
bus->write_pwm(1, clamp(power, -1000, 1000));
|
||||||
|
id(face).set_mood(robot_face::MOOD_DIZZY);
|
||||||
|
- delay: !lambda return (uint32_t) (seconds * 1000);
|
||||||
|
- lambda: |-
|
||||||
|
auto *bus = id(x_servo).get_parent();
|
||||||
|
bus->write_pwm(1, 0);
|
||||||
|
bus->enable_torque(1, 0);
|
||||||
|
// position mode again; torque is off, so the old goal position does not pull the head back
|
||||||
|
bus->write_word(1, SCSCL_MIN_ANGLE_LIMIT_L, id(spin_limits) & 0xFFFF);
|
||||||
|
bus->write_word(1, SCSCL_MAX_ANGLE_LIMIT_L, id(spin_limits) >> 16);
|
||||||
|
ESP_LOGI("spin", "Stopped, limits back to %d..%d", id(spin_limits) & 0xFFFF, id(spin_limits) >> 16);
|
||||||
|
- delay: 2s
|
||||||
|
- lambda: id(face).set_mood(robot_face::MOOD_NEUTRAL);
|
||||||
# text under the face with the mouth moving
|
# text under the face with the mouth moving
|
||||||
- id: say
|
- id: say
|
||||||
mode: restart
|
mode: restart
|
||||||
@@ -437,22 +469,11 @@ script:
|
|||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
id(speech) = message;
|
id(speech) = message;
|
||||||
id(speaking) = true;
|
id(face).set_speaking(true);
|
||||||
- component.update: display_tft
|
|
||||||
- delay: 8s
|
- delay: 8s
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
id(speech).clear();
|
id(speech).clear();
|
||||||
id(speaking) = false;
|
id(face).set_speaking(false);
|
||||||
- component.update: display_tft
|
|
||||||
# stroking the head shows the in-love face for a while
|
|
||||||
- id: head_stroke
|
|
||||||
mode: restart
|
|
||||||
then:
|
|
||||||
- lambda: id(in_love) = true;
|
|
||||||
- component.update: display_tft
|
|
||||||
- delay: 5s
|
|
||||||
- lambda: id(in_love) = false;
|
|
||||||
- component.update: display_tft
|
|
||||||
# mic and speaker share one I2S bus - the mic must be released before playback
|
# mic and speaker share one I2S bus - the mic must be released before playback
|
||||||
- id: release_i2s_bus
|
- id: release_i2s_bus
|
||||||
mode: single
|
mode: single
|
||||||
@@ -475,6 +496,41 @@ script:
|
|||||||
timeout: 2s
|
timeout: 2s
|
||||||
|
|
||||||
interval:
|
interval:
|
||||||
|
# CPU time of every task over the last 10 s (100 % = one core), busiest first
|
||||||
|
- interval: 10s
|
||||||
|
then:
|
||||||
|
- lambda: |-
|
||||||
|
struct Prev { std::string name; uint64_t run; };
|
||||||
|
static std::vector<Prev> prev;
|
||||||
|
static uint64_t prev_total = 0;
|
||||||
|
std::vector<TaskStatus_t> tasks(uxTaskGetNumberOfTasks() + 4);
|
||||||
|
configRUN_TIME_COUNTER_TYPE total;
|
||||||
|
tasks.resize(uxTaskGetSystemState(tasks.data(), tasks.size(), &total));
|
||||||
|
const uint64_t span = total - prev_total;
|
||||||
|
struct Row { const TaskStatus_t *t; uint64_t delta; };
|
||||||
|
std::vector<Row> rows;
|
||||||
|
std::vector<Prev> now;
|
||||||
|
for (auto &t : tasks) {
|
||||||
|
uint64_t before = 0;
|
||||||
|
for (auto &p : prev)
|
||||||
|
if (p.name == t.pcTaskName)
|
||||||
|
before = p.run;
|
||||||
|
rows.push_back({&t, t.ulRunTimeCounter - before});
|
||||||
|
now.push_back({t.pcTaskName, t.ulRunTimeCounter});
|
||||||
|
}
|
||||||
|
const bool first = prev_total == 0;
|
||||||
|
prev = std::move(now);
|
||||||
|
prev_total = total;
|
||||||
|
if (first || span == 0)
|
||||||
|
return;
|
||||||
|
std::sort(rows.begin(), rows.end(), [](const Row &a, const Row &b) { return a.delta > b.delta; });
|
||||||
|
for (auto &r : rows) {
|
||||||
|
const float pct = 100.0f * r.delta / span;
|
||||||
|
if (pct < 0.5f)
|
||||||
|
break;
|
||||||
|
ESP_LOGI("task_stats", "%-16s core %2d prio %2u %5.1f %%", r.t->pcTaskName,
|
||||||
|
r.t->xCoreID == tskNO_AFFINITY ? -1 : (int) r.t->xCoreID, (unsigned) r.t->uxCurrentPriority, pct);
|
||||||
|
}
|
||||||
- interval: 80ms # spectrum analyzer frame rate while music plays
|
- interval: 80ms # spectrum analyzer frame rate while music plays
|
||||||
then:
|
then:
|
||||||
- if:
|
- if:
|
||||||
@@ -544,7 +600,7 @@ interval:
|
|||||||
first_on[1] ? (int) (first_on[1] - earliest) : -1, first_on[2] ? (int) (first_on[2] - earliest) : -1);
|
first_on[1] ? (int) (first_on[1] - earliest) : -1, first_on[2] ? (int) (first_on[2] - earliest) : -1);
|
||||||
|
|
||||||
if (pads >= 2 && spread >= 150 && duration >= 400) {
|
if (pads >= 2 && spread >= 150 && duration >= 400) {
|
||||||
id(head_stroke).execute();
|
id(show_mood).execute(std::string("love"), 5);
|
||||||
}
|
}
|
||||||
- interval: 1s # status screen refresh until Home Assistant connects
|
- interval: 1s # status screen refresh until Home Assistant connects
|
||||||
then:
|
then:
|
||||||
@@ -553,32 +609,6 @@ interval:
|
|||||||
lambda: return id(show_status);
|
lambda: return id(show_status);
|
||||||
then:
|
then:
|
||||||
- component.update: display_tft
|
- component.update: display_tft
|
||||||
- interval: 90ms
|
|
||||||
then:
|
|
||||||
- lambda: |-
|
|
||||||
if (id(speaking)) {
|
|
||||||
id(mouth_open) = 0.15f + (esp_random() % 85) / 100.0f;
|
|
||||||
id(display_tft).update();
|
|
||||||
} else if (id(mouth_open) > 0) {
|
|
||||||
id(mouth_open) = 0;
|
|
||||||
id(display_tft).update();
|
|
||||||
}
|
|
||||||
- interval: 3s # blinking
|
|
||||||
then:
|
|
||||||
- delay: !lambda return esp_random() % 3000;
|
|
||||||
- lambda: id(eyes_open) = false;
|
|
||||||
- component.update: display_tft
|
|
||||||
- delay: 150ms
|
|
||||||
- lambda: id(eyes_open) = true;
|
|
||||||
- component.update: display_tft
|
|
||||||
- interval: 7s # looking around while idle
|
|
||||||
then:
|
|
||||||
- lambda: |-
|
|
||||||
if (!id(speaking) && !id(listening)) {
|
|
||||||
id(gaze_x) = (int) (esp_random() % 21) - 10;
|
|
||||||
id(gaze_y) = (int) (esp_random() % 11) - 5;
|
|
||||||
id(display_tft).update();
|
|
||||||
}
|
|
||||||
|
|
||||||
spi:
|
spi:
|
||||||
- id: spi_bus
|
- id: spi_bus
|
||||||
@@ -706,30 +736,26 @@ display:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stack-chan face: 2 eyes + mouth, 320x240
|
// stack-chan face (robot_face), 320x240
|
||||||
// the whole screen is cleared only once, then just the face areas, so that only the
|
// the whole screen is cleared only once, then just the face areas, so that only the
|
||||||
// changed region is sent over SPI instead of the whole 150 kB buffer
|
// changed region is sent over SPI instead of the whole 150 kB buffer
|
||||||
const bool love = id(in_love);
|
|
||||||
const bool music = id(media_out).state == media_player::MEDIA_PLAYER_STATE_PLAYING && !id(va).is_running();
|
const bool music = id(media_out).state == media_player::MEDIA_PLAYER_STATE_PLAYING && !id(va).is_running();
|
||||||
// switching between face, in-love face and spectrum repaints everything
|
// switching between face and spectrum repaints everything
|
||||||
static int last_mode = -1;
|
static bool last_music = false;
|
||||||
const int mode = music ? 2 : love ? 1 : 0;
|
if (music != last_music) {
|
||||||
if (mode != last_mode) {
|
last_music = music;
|
||||||
last_mode = mode;
|
|
||||||
first_draw = true;
|
first_draw = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the in-love face is drawn outside the partially cleared areas, so it always repaints everything
|
|
||||||
static bool spectrum_reset = true;
|
static bool spectrum_reset = true;
|
||||||
if (first_draw || love) {
|
if (first_draw) {
|
||||||
it.fill(id(face_bg));
|
it.fill(id(face_bg));
|
||||||
|
id(face).invalidate();
|
||||||
first_draw = false;
|
first_draw = false;
|
||||||
bar_drawn = false;
|
bar_drawn = false;
|
||||||
spectrum_reset = true;
|
spectrum_reset = true;
|
||||||
} else if (!music) {
|
} else if (!music) {
|
||||||
it.filled_rectangle(66, 74, 189, 39, id(face_bg)); // eyes including gaze range and surprised eyes
|
it.filled_rectangle(0, 216, 320, 22, id(face_bg)); // speech text
|
||||||
it.filled_rectangle(105, 130, 111, 38, id(face_bg)); // mouth
|
|
||||||
it.filled_rectangle(0, 184, 320, 30, id(face_bg)); // speech text
|
|
||||||
if (dot_shown && !id(listening)) {
|
if (dot_shown && !id(listening)) {
|
||||||
it.filled_rectangle(254, 2, 28, 28, id(face_bg));
|
it.filled_rectangle(254, 2, 28, 28, id(face_bg));
|
||||||
}
|
}
|
||||||
@@ -822,59 +848,33 @@ display:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int ex = id(gaze_x), ey = id(gaze_y);
|
id(face).draw(it);
|
||||||
const int eye_y = 93 + ey, eye_r = 8;
|
|
||||||
const int lx = 90 + ex, rx = 230 + ex;
|
|
||||||
|
|
||||||
if (love) {
|
|
||||||
// heart eyes, blush and a wide smile
|
|
||||||
for (int cx : {lx, rx}) {
|
|
||||||
it.filled_circle(cx - 6, eye_y - 3, 7, id(love_red));
|
|
||||||
it.filled_circle(cx + 6, eye_y - 3, 7, id(love_red));
|
|
||||||
it.filled_triangle(cx - 13, eye_y - 1, cx + 13, eye_y - 1, cx, eye_y + 14, id(love_red));
|
|
||||||
}
|
|
||||||
it.filled_circle(60 + ex, 130 + ey, 12, Color(90, 20, 40));
|
|
||||||
it.filled_circle(260 + ex, 130 + ey, 12, Color(90, 20, 40));
|
|
||||||
if (!id(speaking)) {
|
|
||||||
it.filled_circle(160 + ex / 2, 132 + ey / 2, 30, id(face_fg));
|
|
||||||
it.filled_circle(160 + ex / 2, 122 + ey / 2, 30, id(face_bg));
|
|
||||||
}
|
|
||||||
} else if (id(surprised)) {
|
|
||||||
it.filled_circle(lx, eye_y, 11, id(face_fg));
|
|
||||||
it.filled_circle(rx, eye_y, 11, id(face_fg));
|
|
||||||
} else if (id(dizzy)) {
|
|
||||||
// X eyes, 3 px thick
|
|
||||||
for (int cx : {lx, rx})
|
|
||||||
for (int d = -1; d <= 1; d++) {
|
|
||||||
it.line(cx - 9 + d, eye_y - 9, cx + 9 + d, eye_y + 9, id(face_fg));
|
|
||||||
it.line(cx - 9 + d, eye_y + 9, cx + 9 + d, eye_y - 9, id(face_fg));
|
|
||||||
}
|
|
||||||
} else if (id(eyes_open)) {
|
|
||||||
it.filled_circle(lx, eye_y, eye_r, id(face_fg));
|
|
||||||
it.filled_circle(rx, eye_y, eye_r, id(face_fg));
|
|
||||||
} else {
|
|
||||||
it.filled_rectangle(lx - eye_r, eye_y - 2, eye_r * 2, 4, id(face_fg));
|
|
||||||
it.filled_rectangle(rx - eye_r, eye_y - 2, eye_r * 2, 4, id(face_fg));
|
|
||||||
}
|
|
||||||
|
|
||||||
const float m = id(mouth_open);
|
|
||||||
if (id(surprised) && !id(speaking)) {
|
|
||||||
it.filled_circle(160 + ex / 2, 148 + ey / 2, 15, id(face_fg));
|
|
||||||
it.filled_circle(160 + ex / 2, 148 + ey / 2, 9, id(face_bg));
|
|
||||||
} else if (!love || id(speaking)) {
|
|
||||||
const int mw = 90 - (int) (40 * m);
|
|
||||||
const int mh = 4 + (int) (26 * m);
|
|
||||||
it.filled_rectangle(160 - mw / 2 + ex / 2, 148 - mh / 2 + ey / 2, mw, mh, id(face_fg));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!id(speech).empty()) {
|
if (!id(speech).empty()) {
|
||||||
it.print(160, 186, id(font_status), id(face_fg), TextAlign::TOP_CENTER, id(speech).c_str());
|
it.print(160, 218, id(font_status), id(face_fg), TextAlign::TOP_CENTER, id(speech).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id(listening)) {
|
if (id(listening)) {
|
||||||
it.image(254, 2, id(icon_listening), id(face_fg), id(face_bg)); // left of the wifi bars
|
it.image(254, 2, id(icon_listening), id(face_fg), id(face_bg)); // left of the wifi bars
|
||||||
}
|
}
|
||||||
|
|
||||||
|
robot_face:
|
||||||
|
id: face
|
||||||
|
display_id: display_tft
|
||||||
|
foreground: face_fg
|
||||||
|
background: face_bg
|
||||||
|
love_color: love_red
|
||||||
|
devil_color: status_low
|
||||||
|
# eyes only, centered between the status bar and the speech line
|
||||||
|
eyes_y: 120
|
||||||
|
eye_width: 72
|
||||||
|
eye_height: 84
|
||||||
|
eye_radius: 20
|
||||||
|
eye_spacing: 50
|
||||||
|
gaze_x: 34
|
||||||
|
gaze_y: 22
|
||||||
|
sleep_after: 5min
|
||||||
|
|
||||||
motion:
|
motion:
|
||||||
- platform: bmi270
|
- platform: bmi270
|
||||||
id: imu
|
id: imu
|
||||||
@@ -891,7 +891,10 @@ event:
|
|||||||
threshold: 1.5
|
threshold: 1.5
|
||||||
cooldown: 500ms
|
cooldown: 500ms
|
||||||
on_event:
|
on_event:
|
||||||
- script.execute: shake_reaction
|
- script.execute:
|
||||||
|
id: show_mood
|
||||||
|
mood: dizzy
|
||||||
|
seconds: 3
|
||||||
|
|
||||||
st25r_i2c:
|
st25r_i2c:
|
||||||
id: nfc_reader
|
id: nfc_reader
|
||||||
@@ -899,7 +902,10 @@ st25r_i2c:
|
|||||||
update_interval: never # polled from the head touch interval, see there
|
update_interval: never # polled from the head touch interval, see there
|
||||||
on_tag:
|
on_tag:
|
||||||
- lambda: id(speech) = x; // UID under the face while the card lies there
|
- lambda: id(speech) = x; // UID under the face while the card lies there
|
||||||
- script.execute: surprise_reaction
|
- script.execute:
|
||||||
|
id: show_mood
|
||||||
|
mood: surprised
|
||||||
|
seconds: 3
|
||||||
- text_sensor.template.publish:
|
- text_sensor.template.publish:
|
||||||
id: nfc_tag
|
id: nfc_tag
|
||||||
state: !lambda return x;
|
state: !lambda return x;
|
||||||
@@ -910,6 +916,14 @@ st25r_i2c:
|
|||||||
id: nfc_tag
|
id: nfc_tag
|
||||||
state: ""
|
state: ""
|
||||||
|
|
||||||
|
# an update needs the network to itself: playback, wake word and the assistant stop first
|
||||||
|
ota:
|
||||||
|
- id: !extend ota_esphome
|
||||||
|
on_begin:
|
||||||
|
- media_player.stop: media_out
|
||||||
|
- voice_assistant.stop:
|
||||||
|
- micro_wake_word.stop:
|
||||||
|
|
||||||
# the StackChan base right under the Core spoils the WiFi link (ping 160-250 ms, stuttering audio,
|
# the StackChan base right under the Core spoils the WiFi link (ping 160-250 ms, stuttering audio,
|
||||||
# m5stack/StackChan#119); 11 dB brings it to ~20 ms. A ~1 cm gap from the base fixes it fully.
|
# m5stack/StackChan#119); 11 dB brings it to ~20 ms. A ~1 cm gap from the base fixes it fully.
|
||||||
wifi:
|
wifi:
|
||||||
@@ -926,10 +940,47 @@ api:
|
|||||||
message: !lambda return message;
|
message: !lambda return message;
|
||||||
- action: stackchan_pet
|
- action: stackchan_pet
|
||||||
then:
|
then:
|
||||||
- script.execute: head_stroke
|
- script.execute:
|
||||||
|
id: show_mood
|
||||||
|
mood: love
|
||||||
|
seconds: 5
|
||||||
|
# spins the head around: seconds, power -1000..1000 (sign = direction)
|
||||||
|
- action: stackchan_spin
|
||||||
|
variables:
|
||||||
|
seconds: float
|
||||||
|
power: int
|
||||||
|
then:
|
||||||
|
- script.execute:
|
||||||
|
id: spin
|
||||||
|
seconds: !lambda return seconds;
|
||||||
|
power: !lambda return power;
|
||||||
- action: stackchan_shake
|
- action: stackchan_shake
|
||||||
then:
|
then:
|
||||||
- script.execute: shake_reaction
|
- script.execute:
|
||||||
|
id: show_mood
|
||||||
|
mood: dizzy
|
||||||
|
seconds: 3
|
||||||
|
# neutral, happy, sad, angry, tired, surprised, love, dizzy, puppy, devil, curious, suspicious;
|
||||||
|
# laugh and confused are short animations, sleep/wake close and open the eyes, wink winks
|
||||||
|
- action: stackchan_set_emotion
|
||||||
|
variables:
|
||||||
|
emotion: string
|
||||||
|
then:
|
||||||
|
- lambda: |-
|
||||||
|
if (emotion == "laugh")
|
||||||
|
id(face).laugh();
|
||||||
|
else if (emotion == "confused")
|
||||||
|
id(face).confused();
|
||||||
|
else if (emotion == "sleep")
|
||||||
|
id(face).set_eyes_open(false);
|
||||||
|
else if (emotion == "wake")
|
||||||
|
id(face).peek(0);
|
||||||
|
else if (emotion == "wink")
|
||||||
|
id(face).wink(1);
|
||||||
|
else {
|
||||||
|
id(show_mood).stop();
|
||||||
|
id(face).set_mood(emotion);
|
||||||
|
}
|
||||||
|
|
||||||
touchscreen:
|
touchscreen:
|
||||||
- platform: ft63x6
|
- platform: ft63x6
|
||||||
@@ -967,6 +1018,25 @@ esp32_camera:
|
|||||||
frame_buffer_location: PSRAM
|
frame_buffer_location: PSRAM
|
||||||
|
|
||||||
sensor:
|
sensor:
|
||||||
|
# raw servo positions, 1024 steps = 360 degrees (2.844 steps per degree, as in ftservo)
|
||||||
|
- platform: ftservo
|
||||||
|
id: servo_x_feedback
|
||||||
|
ftservo_id: x_servo
|
||||||
|
update_interval: 500ms
|
||||||
|
position:
|
||||||
|
name: Servo X Position
|
||||||
|
entity_category: diagnostic
|
||||||
|
filters:
|
||||||
|
- delta: 2
|
||||||
|
- platform: ftservo
|
||||||
|
id: servo_y_feedback
|
||||||
|
ftservo_id: y_servo
|
||||||
|
update_interval: 500ms
|
||||||
|
position:
|
||||||
|
name: Servo Y Position
|
||||||
|
entity_category: diagnostic
|
||||||
|
filters:
|
||||||
|
- delta: 2
|
||||||
- platform: axp2101
|
- platform: axp2101
|
||||||
id: axp2101_sensor
|
id: axp2101_sensor
|
||||||
battery_level:
|
battery_level:
|
||||||
@@ -1060,16 +1130,38 @@ ftservo:
|
|||||||
id: y_servo
|
id: y_servo
|
||||||
address: 2
|
address: 2
|
||||||
|
|
||||||
|
button:
|
||||||
|
- platform: template
|
||||||
|
name: Spin
|
||||||
|
icon: mdi:rotate-360
|
||||||
|
on_press:
|
||||||
|
- script.execute:
|
||||||
|
id: spin
|
||||||
|
seconds: 3
|
||||||
|
power: 600
|
||||||
|
|
||||||
number:
|
number:
|
||||||
- platform: ftservo
|
- platform: ftservo
|
||||||
ftservo_id: x_servo
|
ftservo_id: x_servo
|
||||||
|
# yaw: 0 = straight ahead = raw 461 (measured), 2.844 steps per degree
|
||||||
angle:
|
angle:
|
||||||
id: servo_x_angle
|
id: servo_x_angle
|
||||||
name: Servo X Angle
|
name: Servo X Angle
|
||||||
min_value: -164
|
min_value: -160
|
||||||
max_value: 164
|
max_value: 160
|
||||||
use_raw_angle: false
|
use_raw_angle: false
|
||||||
angle_offset: 164
|
angle_offset: 162.1
|
||||||
|
step: 5
|
||||||
|
# pitch: 0 = all the way down = raw 642, the top stop is raw 928 (~100 degrees, measured)
|
||||||
|
- platform: ftservo
|
||||||
|
ftservo_id: y_servo
|
||||||
|
angle:
|
||||||
|
id: servo_y_angle
|
||||||
|
name: Servo Y Angle
|
||||||
|
min_value: 0
|
||||||
|
max_value: 95
|
||||||
|
use_raw_angle: false
|
||||||
|
angle_offset: 225.7
|
||||||
step: 5
|
step: 5
|
||||||
|
|
||||||
light:
|
light:
|
||||||
|
|||||||
Reference in new issue
Block a user