Setting up CAN connection with TI Evaluation Board

Hello,

We currently have a TI evaluation board set up, and have successfully been able to run the mw_dual_motor_torque_ctrl package through USB connection. We have gotten the virtual spring mode working for one motor and have also found a way to get the motor to spin at a constant torque. Next, we are looking to set up the CAN connection so we can send real time position and current updates but we are a little lost. It is our first time using CAN so we aren’t quite sure where to start. We have the wired connection set up with a PEAK CAN - USB connector. Our software setup is a Linux computer running Ubuntu 20.04 and Code Composer Studio v10.

Is there a specific CAN driver we need to install before running? Or some CAN interface software? Once we have the CAN connection set up, do we upload code to the TI Board the same way by flashing it? Or is it something different? Any insights or help would be much appreciated, thank you!

Zac

Hi Zac,

I am personally not using the CAN interface anymore, but hopefully the following helps you

Is there a specific CAN driver we need to install before running?

The PEAK CAN - USB device should be supported by the default linux driver by now. To check if the device gets detected you can unplug the device, plug the device and then check for the output of dmesg. There you should see a message about the CAN device being detected.

Or some CAN interface software?

With the blmc_drivers 1 package we support talking to ti development board via can if that’s what you are asking about.

There are also some examples/demos in the demos folder. Maybe you want to try to run the demo_1_motor.cpp one 4.

Also, there is a script 2 in the repo which you should run to setup your CAN devices. Once you ran the script and have the ti boards flashed and connected, you can check for received messages via the netstate -i command.

Once we have the CAN connection set up, do we upload code to the TI Board the same way by flashing it?

Yes, you need to flash the TI boards using the Code Composer Studio like you did before. Make sure to change the toggle once you flashed the device 3, such that the devices starts from flash the next time they start.

Hello,

Thanks for the quick response. We’ve successfully established a CAN connection with the TI board, and we are consistently receiving a status update from the board every second or so with a single byte of 07 indicating that we have one motor enabled and ready (we only have one connected). Next, we are trying to transmit specific commands to the board according to this document

How do we structure the data we want to send to get the results we want? We’re just a little confused what the MDL and MDH values refer to. For example, if I want to enable the virtual spring mode for one motor, I know that I need to send data with the MDH = 4 and MDL = 1. To do this, how should I structure the 8 bytes of data in hex? Would it just be 00 00 00 04 00 00 00 01? Or something else? Is it a different data length?

Secondly, if I am trying to send a specific current or encoder position, I know I need to convert to IQ values by multiplying by 2^24. How do these values convert to the bytes we need to send to the board?

Thanks for all the help

Hi Zac,

I don’t know the answers to your questions. However, I was wondering if you could just use the blmc_drivers package I pointed to you before to do the communication parts? Then you wouldn’t need to worry about encoding and decoding the sent messages yourself.

GitHub - open-dynamic-robot-initiative/blmc_drivers

Best,
Julian

Julian,

Thanks, I’ll be sure to implement the blmc_drivers package next. Just a quick question: is it already set up to run in Code Composer Studio like the mw_dual_motor_torque_ctrl package is? Or is there some set up we need to do to run it in Code Composer Studio?

Thanks,
Zac

Hi Zac,

no, the blmc_driver package is not setup for Code Composer Studio. You need to use a different code editor for the files. To build the project you would first setup a workspace by pulling the required dependencies using treep and build the project using colcon (as it’s a ros2 package).

Does that make sense to you? If not, I can explain the steps you need to follow for this. Let me know what your setup is (do you have ros2 installed?).

Best,
Julian

Hi Julian,

That makes sense, thank you. Yes we do have ros2 installed on a linux machine running Ubuntu 20.04. Could you please explain the steps to set up the project? That would be incredibly helpful.

Thanks so much,
Zac

Hello,

we just revised the documentation of blmc_drivers and added a page with instructions on how to setup and build a workspace.

Unfortunately there is a problem with our build pipeline at the moment which results in the C++ API section is not being built properly. Until this is fixed, you may look at the doxygen comments directly in the code. Sorry for the inconvenience!

We don’t yet have an explicit documentation on how to use the package but there is a collection of demos.

Best,
Felix

Hello,

I was following along these steps and then ran into an issue at the very end when I was trying to build the workspaces. When I ran colcon build, I got this error:

— stderr: yaml_utils
CMake Error at CMakeLists.txt:23 (find_package):
Could not find a package configuration file provided by “yaml-cpp” with any
of the following names:

yaml-cppConfig.cmake
yaml-cpp-config.cmake

Add the installation prefix of “yaml-cpp” to CMAKE_PREFIX_PATH or set
“yaml-cpp_DIR” to a directory containing one of the above files. If
“yaml-cpp” provides a separate development package or SDK, be sure it has
been installed.

Am I supposed to go into the CMake file and edit the package line? Or did I do something wrong cloning the project onto the computer? In the build summary at the end, it says that 3 packages were finished, 4 packages aborted, 4 packages had stderr output, and 3 packages were not processed. How can I fix the build so I can try to run the projects?

Thanks,
Zac

Hi Zac,

we assume yaml-cpp to be installed globally. To do that you can run

sudo apt-get install libyaml-cpp-dev

Afterwards, the error message should go away. If not, let me know and I will dig deeper.

Best,
Julian

Hello,

Thank you for all your help on the issues we keep having, we just have one more question. We are still trying to use colcon build to build the package, and now we are having an issue with building the blmc_drivers package specifically with ament_cmake. Here is the commands we are running and the output we get:

kodlab@kodlab-desktop:~/workspace$ source /opt/ros/foxy/setup.bash
kodlab@kodlab-desktop:~/workspace$ colcon build
Starting >>> googletest-distribution
Starting >>> mpi_cmake_modules
Starting >>> pybind11
Finished <<< mpi_cmake_modules [0.18s]
Finished <<< googletest-distribution [0.25s]
Starting >>> yaml_utils
Starting >>> serialization_utils
Finished <<< pybind11 [0.29s]
Starting >>> real_time_tools
Starting >>> shared_memory
Starting >>> signal_handler
Finished <<< yaml_utils [0.22s]
Starting >>> package_template
Finished <<< serialization_utils [0.31s]
Finished <<< signal_handler [0.30s]
Finished <<< real_time_tools [0.42s]
Finished <<< package_template [0.45s]
Finished <<< shared_memory [0.74s]
Starting >>> time_series
Finished <<< time_series [0.38s]
Starting >>> blmc_drivers
— stderr: blmc_drivers
CMake Error at CMakeLists.txt:27 (find_package):
By not providing “Findament_cmake.cmake” in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
“ament_cmake”, but CMake did not find one.

Could not find a package configuration file provided by “ament_cmake” with
any of the following names:

ament_cmakeConfig.cmake
ament_cmake-config.cmake

Add the installation prefix of “ament_cmake” to CMAKE_PREFIX_PATH or set
“ament_cmake_DIR” to a directory containing one of the above files. If
“ament_cmake” provides a separate development package or SDK, be sure it
has been installed.


Failed <<< blmc_drivers [0.10s, exited with code 1]

Summary: 10 packages finished [1.65s]
1 package failed: blmc_drivers
1 package had stderr output: blmc_drivers

We have tried sourcing various files (setup.sh, local_setup.bash, local_setup.sh, as well as a few other setup files in different locations) and kept getting the same error. We’ve also tried to download a ament_cmake repository from github here, but we’re not sure what directory to put it in and it doesn’t seem to have made a difference anyway. We’re not quite sure what to do to get the ament_cmake build to work. Please let us know if we are sourcing it wrong or if there’s something else we should do to fix the problem. Thank you again for all your help!

Zac

hi Zac,

this is very strange - after sourcing source /opt/ros/foxy/setup.bash it should find ament.

What you can do is pull the ament packages into the workspace and build them as well with colcon. You can do this by running

treep --seq-clone AMENT

Let me know if that works.

Note that colcon build will build you a debug build. You might want to build a release build via colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release

Best,
Julian

sorry for the late reply, but this solution seemed to work! We grabbed the ament packages with the treep command, then we had to delete the current build folder in the workspace and then build again from scratch, but then it successfully built. Now we are just trying to set up the CAN connection in ros2 so we can run the blmc_drivers demos. Thank you very much for all your help!

Zac

Hello,

Sorry for all the questions, but we have had a bit of trouble trying to figure out how to setup the CAN connection and run some of the blmc_drivers demos. Here are the steps we do to try to run the demos:

source /opt/ros/foxy/setup.bash
. ~/ros2_foxy/ros2-linux/setup.bash
source install/local_setup.bash
colcon build
sudo ./src/blmc_drivers/scripts/initialize_can_bus.sh
ros2 run blmc_drivers demo_1_motor_print_everything

We have a TI board connected with a PCAN-USB adapter, and the board is successfully flashed with the mw_dual_motor_torque_ctrl firmware. However, we always get the same output when trying to run the demos:

rt_dev_ioctl GET_IFINDEX: Operation not permitted
Couldn’t setup CAN connection. Exit.

We seem to have some trouble recognizing the CAN bus? Here is the output of the initialize_can_bus script:

We are not quite sure what to do about this situation. rt_dev_ioctl seems to be a xenomai function? But we are running this on a RT-PREEMPT kernel. We had successfully controlled a motor over CAN with this same adapter using the mw_dual_motor_torque_ctrl package. Is it an issue with ros2 that it can’t recognize the CAN bus? Or is it something else? We are a little lost on how to solve this issue, so any help would be appreciated.

Thanks,
Zac

Hi Zac,

I am not 100% sure what is going on at your end. Can you share the output of uname -r with us please? If this string is not correctly set when running the rt-preempt kernel, then things won’t compile properly. That said, I am still a bit confused how you come across the Xenomai api…

Also, when you plug the PCAN-USB adapter and run dmsg, you should see a message that the adapter got registered on a CAN port.

Best,
Julian

The output of uname -r is 5.10.35-rt39, which is the correct RT_PREEMPT kernel we attempted to download.

The dmsg command doesn’t seem to work, the computer doesn’t recognize the command. Did you mean dmesg? This spits out an incredible amount of information that is difficult to read and understand, so I’m not sure if the adapter is being registered as a CAN port. We can however control a motor over the mw_dual_motor_torque_ctrl firmware over CAN using a pcanview API and the commands listed in the blmc_drivers documentation.

Thanks,
Zac

Hi Zac,

the output from uname -r should contain the string “-preempt-rt”. That’s what we use to check that you are running an rt-preempt kernel and compile the code differently for this case.

When you compiled the kernel, did you make sure to configure the local version as described here?

ubuntu_installation_scripts/install_rt_preempt_kernel.sh at master · machines-in-motion/ubuntu_installation_scripts · GitHub

As said, our code expects this prefix to be available on the kernel string. So you might have to recompile the kernel.

You are right, I meant to write dmesg. You can use dmesg | tail -n 20 to get the output from the last 20 lines. That should be enough to see a message from the CAN adapter if you run the command just after you plug your can USB adapter in.

Best,
Julian

Hi Julian,

When compiling the kernel, we had a slight error that was caused by appending “-preempt-rt” to the kernel name. We thought it was simply for readability and we could get away with not including it, but I see that’s not the case. Let me rebuild the kernel with making sure to include the “-preempt-rt” and hopefully this will fix the problem, thanks

Zac

Hello,

I updated the kernel and added the “-preempt-rt” at the end of the kernel name. The output of uname -r is 5.10.47-rt45-preempt-rt. Here is the output of dmesg | tail -n 20:

It looks like it recognizes the PCAN-USB device we have plugged in. However, when I follow all the same steps listed before and try to run one of the blmc_drivers demos, I still get the same rt_dev_ioctl error. I’m not at all sure what is happening now and why it still seems to be trying to run Xenomai commands when we are operating on a rt-preempt kernel. Is the kernel name still formatted incorrectly and thus the code can’t recognize it correctly? Or is it something else now?

Thanks for all the help,
Zac

Hi Zac,

your setup looks all good. I am not sure why you are getting the

rt_dev_ioctl GET_IFINDEX: Operation not permitted
Couldn’t setup CAN connection. Exit.

message. Which demo do you try to run exactly? I don’t have a CAN setup right now but I can try to run the demo on my setup and see if I am getting the same error or not.

Best,
Julian