Skip to main content

Examples

The driver ships with Python and C++ examples for every component, plus standalone C++ examples that run without ROS2.

Running Examples​

ros2 run studica_control titan_example.py
ros2 run studica_control imu_example.py
ros2 run studica_control ultrasonic_example.py
ros2 run studica_control servo_example.py
ros2 run studica_control encoder_example.py
ros2 run studica_control dc_encoder_example.py
ros2 run studica_control dio_example.py
ros2 run studica_control sharp_example.py
ros2 run studica_control cobra_example.py
ros2 run studica_control light_tower_example.py
ros2 run studica_control gamepad_example.py
ros2 run studica_control parsec_example.py
info

The gamepad example requires ros2 run joy joy_node running in a separate terminal.

What Each Example Does​

ExampleBehaviour
titan_examplePublishes duty cycle, subscribes to encoder/RPM. Runs motor 0 at 80% for 3 s, stops for 2 s, repeats 3 times.
imu_examplePrints orientation quaternion, angular velocity, and linear acceleration at 20 Hz.
ultrasonic_examplePrints range readings in metres as they arrive.
servo_exampleMoves a standard servo through 90°, −90°, 0°.
encoder_examplePrints encoder count and direction at 20 Hz.
dc_encoder_examplePrints absolute angle, rollover count, and total rotation at 20 Hz.
dio_exampleReads and prints digital pin state at 10 Hz.
sharp_examplePrints IR distance readings in metres as they arrive.
cobra_examplePrints reflectance voltage for all 4 channels at 20 Hz.
light_tower_exampleCycles through all light states every 3 seconds via service.
gamepad_examplePrints cmd_vel output as you move the joystick (requires joy node).
parsec_examplePrints a compact zone grid and nearest valid zone for 100 frames, then exits. Polls get_min_distance via service every 5 seconds.

Standalone Driver Examples​

The drivers/examples/ folder contains C++ examples that work without ROS2, useful for isolating hardware tests.

cd drivers/examples/titan_example
make
sudo ./titan_example
ExampleDescription
titan_exampleConfigure encoders, enable, spin all 4 motors
imu_examplePrint pitch, yaw, roll, and quaternion
servo_exampleThree sub-examples: standard, continuous, linear
ultrasonic_examplePrint range readings in a loop
sharp_examplePrint IR distance readings in a loop
cobra_examplePrint reflectance voltage for all 4 channels
light_tower_exampleCycle through solid, hardware blink, and off states
parsec_examplePrint zone grid and nearest valid zone over CAN or USB. Accepts can [id] or usb [port] as arguments.
note

Run standalone examples with sudo — they access hardware directly without ROS2.