problem : In the use of osqp Library writing MPC After procedure , Trolley coordinates need tf transformation , and tf Libraries can only be used in python2 Environmental use , It's caused python Environmental conflict
Solutions : The safer idea is , Create a new workspace , Configure to python3 After the environment ,source Take a look at this workspace , You can run dual environments .
Here is a workspace that has been created :
link :py3_ws
Extraction code :pyws
sudo apt install python3-catkin-pkg-modules python3-rospkg-modules python3-empy ipython3
pip3 install numpy
Because it's in my Linux On the system , therefore CMakeLists.txt The path inside will conflict with your system path , So delete , Recompile
cd py3_ws/src
sudo rm CMakeLists.txt
If python3 The version is 3.5 Or something , First, install other versions python, And then 3.6 Change it to your own python edition .
catkin_make --cmake-args -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
source py3_ws/devel/setup.bash
Every time you need to mix two versions source Take a look at this workspace , If it's too much trouble , You can add this command to .bashrc In file .
sudo gedit ~/.bashrc
Add the full path at the bottom
source /home/zhz/gzrobot_ws/devel/setup.bash # Original workspace
source /home/zhz/py3_ws/devel/setup.bash # New workspace
There is an existing workspace in our system ( example :gzrobot_ws), There is also a newly created workspace py3_ws, We only need to operate in the former , Writing python When you file , Interpreter selection python3. The test procedure is as follows :
#!/usr/bin/env python3
# -*- coding=utf-8 -*-
import osqp
import rospy
import tf
if __name__ == "__main__":
rospy.init_node('test', anonymous=True)
while not rospy.is_shutdown():
rate = rospy.Rate(1)
br = tf.TransformBroadcaster()
br.sendTransform((0.0, 0.0, 1.0),
tf.transformations.quaternion_from_euler(0, 0, 3.1415926/2),
rospy.Time.now(),'camera','map')
rate.sleep()
The completed function is to call osqp library , establish tf Coordinate transformation , stay rviz Observe the relationship between the camera and the map
Just run this program , give the result as follows :
Can run python2 Of tf, It can also run python3 Of osqp