# bigpill.py
# No copyright, 2026 Garth Zeglin.  This file is explicitly placed in the public domain.
# Sample Webots controller file for driving an inertially-actuated capsule with internal reaction mass.

print("bigpill.py waking up.")

# Import standard Python libraries.
import math

# Import the Webots simulator API.
from controller import Robot

# Define the time step in milliseconds between controller updates.
EVENT_LOOP_DT = 20

# Request a proxy object representing the robot to control.
robot = Robot()
robot_name = robot.getName()
print("%s: controller connected." % (robot_name))
print("%s has %d devices." % (robot_name, robot.getNumberOfDevices()))

# Fetch handles for the motor.
motor = robot.getDevice('motor')

# Set time constants for the overall oscillation.
period = 4.0

# Run loop to execute a periodic script until the simulation quits.
# If the controller returns -1, the simulator is quitting.
while robot.step(EVENT_LOOP_DT) != -1:
    # Read simulator clock time.
    t = robot.getTime()

    # Cycle the mass back and forth.
    phase = t / period
    if phase % 1.0 < 0.5:
        motor.setPosition(-0.1)
    else:
        motor.setPosition( 0.1)
