```
For example, to view the interface definition for the canopen_interfaces/srv/COTargetDouble
type which is used for the /kd240/target service, run the command below.
This will print the input (target) and output (success).
```bash
ubuntu@KR260:~$ ros2 interface show canopen_interfaces/srv/COTargetDouble
float64 target
---
bool success
```
* Use service calls to control the motor.
The services available and their descriptions can be found in the
[Cia402 Driver documentation](https://ros-industrial.github.io/ros2_canopen/manual/humble/user-guide/cia402-driver.html).
Reset:
```bash
ros2 service call /kd240/nmt_reset_node std_srvs/srv/Trigger
```
Init:
```bash
ros2 service call /kd240/init std_srvs/srv/Trigger
```
Change to velocity mode:
```bash
ros2 service call /kd240/velocity_mode std_srvs/srv/Trigger
```
Change target speed:
```bash
ros2 service call /kd240/target canopen_interfaces/srv/COTargetDouble "target: 3000"
```
> **Note**: For the Anaheim motor kit, the speed range is 250 to 10000 rpm in
both directions. If the motor does not spin at 250 rpm, try a faster speed.
The minimum speed can vary by motor.
#### Run a ROS2 Control based example
* Reset the Pmod CAN interface using the following commands on KR260 board:
```bash
sudo ip link set can0 down
sudo ip link set can0 up
```
* In the docker run terminal start the canopen 402 control system host using the launch file
```bash
ros2 launch kria_motor_control kd240.ros2_control.launch.py
```
> **Reminder**: Ensure that the motor server on the KD240 is running before executing the script on the KR260.
* Open a new terminal, start another session of the the same container.
```bash
docker exec -it motor_control bash
```
* List the available controllers using ros2 control cli utility
```bash
ros2 control list_controllers
```
The output should look similar to this:
```bash
ubuntu@KR260:~$ ros2 control list_controllers
forward_velocity_controller[velocity_controllers/JointGroupVelocityController] active
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
```
* To view the available hardware interfaces, use:
```bash
ros2 control list_hardware_interfaces
```
The output should look similar to this:
```bash
ubuntu@KR260:~$ ros2 control list_hardware_interfaces
command interfaces
wheel_joint/velocity [available] [claimed]
state interfaces
wheel_joint/position
wheel_joint/velocity
```
* List the Ros2 Topics
```bash
ubuntu@KR260:~$ ros2 topic list
/dynamic_joint_states
/forward_velocity_controller/commands
/forward_velocity_controller/transition_event
/joint_state_broadcaster/transition_event
/joint_states
/kd240_wheel/joint_states
/kd240_wheel/nmt_state
/kd240_wheel/rpdo
/kd240_wheel/tpdo
/parameter_events
/robot_description
/rosout
/tf
/tf_static
```
* Observe the live state of the system using dynamic_joint_states
```bash
ros2 topic echo /dynamic_joint_states
```
This continuously updates the current state of the system and shows the position and speed of the motor.
* Open a new terminal, start another session of the the same container.
```bash
docker exec -it motor_control bash
```
* Update the speed of the motor using velocity controller in a new terminal
```bash
ros2 topic pub --once /forward_velocity_controller/commands std_msgs/msg/Float64MultiArray "data: [5000]"
```

## Run One Wire Temperature Sensor Demo
* In this demo, the lm-sensors utility probes the One Wire Temperature sensor, reads and displays the captured temperature value on the serial terminal.
* Ensure to load the motor-ctrl-qei firmware before running the demo
```bash
sudo xmutil unloadapp
sudo xmutil loadapp kd240-motor-ctrl-qei
```
* Run a sanity check to verify if the 1-wire slave sensor has been probed successfully.
```bash
ubuntu@kria:~$ sudo dmesg | grep 'w1'
[ 247.023403] w1_master_driver w1_bus_master1: Attaching one wire slave 28.00000f0559bc crc dc
```
* You can also check if the slave entry is added under `/sys/bus/w1/devices` and if master bus also registers this slave.
```bash
ubuntu@kria:/sys/bus/w1/devices$ ls
28-00000f0559bc w1_bus_master1
ubuntu@kria:/sys/bus/w1/devices$ cat 28-00000f0559bc/name
28-00000f0559bc
ubuntu@kria:/sys/bus/w1/devices$ ls 28-00000f0559bc
alarms eeprom_cmd hwmon power temperature
conv_time ext_power id resolution uevent
driver features name subsystem w1_slave
ubuntu@kria:/sys/bus/w1/devices/w1_bus_master1$ cat w1_master_slave_count
1
ubuntu@kria:/sys/bus/w1/devices/w1_bus_master1$ cat w1_master_slaves
28-00000f0559bc
```
* You can also read the temperature through the filesystem
```bash
ubuntu@kria:~$ ls /sys/class/hwmon/
hwmon0 hwmon1 hwmon2 hwmon3
ubuntu@kria:~$ cat /sys/class/hwmon/hwmon3/name
w1_slave_temp
ubuntu@kria:~$ cat /sys/class/hwmon/hwmon3/temp1_input
20618
```
* The sensor read through the filesystem provides temperature in millidegrees Celsius
* The `lm_sensors` utility's `sensors` command gathers information from the kernel interfaces provided by `hwmon` subsystem, aggregates this raw data,
applies scaling and calibration and presents it in a human-readable format.
* Run the 1-wire demo to measure temperature.
```bash
# Output should be the following
ubuntu@kria:~$ sensors
ina260_u3-isa-0000
Adapter: ISA adapter
in1: 5.06 V
power1: 2.46 W
curr1: 487.00 mA
ams-isa-0000
Adapter: ISA adapter
in1: 1.21 V
in2: 0.00 V
in3: 720.00 mV
in4: 848.00 mV
in5: 1.79 V
in6: 1.79 V
in7: 852.00 mV
in8: 848.00 mV
in9: 849.00 mV
in10: 1.80 V
in11: 1.09 V
in12: 1.79 V
in13: 1.79 V
in14: 1.79 V
in15: 1.79 V
in16: 850.00 mV
in17: 1.80 V
in18: 598.00 mV
in19: 718.00 mV
in20: 1.80 V
in21: 1.25 V
in22: 0.00 V
in23: 846.00 mV
in24: 846.00 mV
in25: 852.00 mV
in26: 1.80 V
in27: 601.00 mV
temp1: +25.1°C
temp2: +26.5°C
temp3: +27.1°C
w1_slave_temp-virtual-0
Adapter: Virtual device
temp1: +20.6°C
```
* The output will have multiple sensors and `w1_slave_temp-virtual` is the desired One Wire Temperature Sensor value that is connected to KD240.
## Next Steps
* Go back to the [KD240 FOC Motor Control Application Start Page](../foc_motor_control_landing)
Copyright© 2023-2025 Advanced Micro Devices, Inc