Examples
The driver ships with Python and C++ examples for every component, plus standalone C++ examples that run without ROS2.
Running Examples​
- Python
- C++
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
Build first:
colcon build --packages-select studica_control
source install/setup.bash
Then run any example:
ros2 run studica_control titan_example
ros2 run studica_control imu_example
ros2 run studica_control ultrasonic_example
ros2 run studica_control servo_example
ros2 run studica_control encoder_example
ros2 run studica_control dc_encoder_example
ros2 run studica_control dio_example
ros2 run studica_control sharp_example
ros2 run studica_control cobra_example
ros2 run studica_control light_tower_example
ros2 run studica_control gamepad_example
ros2 run studica_control parsec_example
info
The gamepad example requires ros2 run joy joy_node running in a separate terminal.
What Each Example Does​
| Example | Behaviour |
|---|---|
titan_example | Publishes duty cycle, subscribes to encoder/RPM. Runs motor 0 at 80% for 3 s, stops for 2 s, repeats 3 times. |
imu_example | Prints orientation quaternion, angular velocity, and linear acceleration at 20 Hz. |
ultrasonic_example | Prints range readings in metres as they arrive. |
servo_example | Moves a standard servo through 90°, −90°, 0°. |
encoder_example | Prints encoder count and direction at 20 Hz. |
dc_encoder_example | Prints absolute angle, rollover count, and total rotation at 20 Hz. |
dio_example | Reads and prints digital pin state at 10 Hz. |
sharp_example | Prints IR distance readings in metres as they arrive. |
cobra_example | Prints reflectance voltage for all 4 channels at 20 Hz. |
light_tower_example | Cycles through all light states every 3 seconds via service. |
gamepad_example | Prints cmd_vel output as you move the joystick (requires joy node). |
parsec_example | Prints 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
| Example | Description |
|---|---|
titan_example | Configure encoders, enable, spin all 4 motors |
imu_example | Print pitch, yaw, roll, and quaternion |
servo_example | Three sub-examples: standard, continuous, linear |
ultrasonic_example | Print range readings in a loop |
sharp_example | Print IR distance readings in a loop |
cobra_example | Print reflectance voltage for all 4 channels |
light_tower_example | Cycle through solid, hardware blink, and off states |
parsec_example | Print 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.