• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pybricks / pybricks-micropython / 6675885095

28 Oct 2023 08:38AM UTC coverage: 56.053% (+10.0%) from 46.074%
6675885095

push

github

laurensvalk
pybricks.hubs.MoveHub: Use standard hub init.

The Move Hub cannot have true vector axes, but we can still use this API to initialize the hub using numeric indices.

This ensures we can use the custom orientation not just in tilt, but also in acceleration like we do on other hubs.

3616 of 6451 relevant lines covered (56.05%)

20895680.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.47
/lib/pbio/src/motor_process.c
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) 2018-2023 The Pybricks Authors
3

4
#include <pbio/battery.h>
5
#include <pbio/control.h>
6
#include <pbio/drivebase.h>
7
#include <pbio/servo.h>
8

9
#include <contiki.h>
10

11
#if PBIO_CONFIG_MOTOR_PROCESS != 0
12

13
PROCESS(pbio_motor_process, "servo");
14

15
PROCESS_THREAD(pbio_motor_process, ev, data) {
8,242✔
16
    static struct etimer timer;
3,218✔
17

18
    PROCESS_BEGIN();
8,242✔
19

20
    // Initialize battery voltage.
21
    pbio_battery_init();
25✔
22

23
    // Initialize motors in stopped state.
24
    pbio_dcmotor_stop_all(true);
25✔
25

26
    etimer_set(&timer, PBIO_CONFIG_CONTROL_LOOP_TIME_MS);
25✔
27

28
    for (;;) {
8,196✔
29
        PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER && etimer_expired(&timer));
16,438✔
30

31
        // Update battery voltage.
32
        pbio_battery_update();
8,196✔
33

34
        // Update drivebase
35
        pbio_drivebase_update_all();
8,196✔
36

37
        // Update servos
38
        pbio_servo_update_all();
8,196✔
39

40
        clock_time_t now = clock_time();
8,196✔
41

42
        // If polling was delayed too long, we need to ensure that the next
43
        // poll is a minimum of 1ms in the future. If we don't, the poll loop
44
        // will not yield until and the next update will be called with a 0 time
45
        // diff which causes issues.
46
        if (now - etimer_start_time(&timer) >= 2 * PBIO_CONFIG_CONTROL_LOOP_TIME_MS) {
8,196✔
47
            timer.timer.start = now - (PBIO_CONFIG_CONTROL_LOOP_TIME_MS - 1);
×
48
        }
49

50
        // Reset timer to wait for next update. Using etimer_reset() instead
51
        // of etimer_restart() makes average update period closer to the expected
52
        // PBIO_CONFIG_CONTROL_LOOP_TIME_MS when occasional delays occur.
53
        etimer_reset(&timer);
8,196✔
54
    }
55

56
    PROCESS_END();
×
57
}
58

59
void pbio_motor_process_start(void) {
25✔
60
    process_start(&pbio_motor_process);
25✔
61
}
25✔
62

63
#endif // PBIO_CONFIG_MOTOR_PROCESS
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc