JuliaPy / PyCall.jl

Package to call Python functions from the Julia language
MIT License
1.45k stars 186 forks source link

How can I use rospy through PyCall directly? #1076

Open wly2014 opened 5 months ago

wly2014 commented 5 months ago

The code I have can only be able to run the callback once.

using PyCall

function solve_callback(data)
    println("solve_callback.")
end

rospy = pyimport("rospy")
msg = pyimport("geometry_msgs.msg")
WrenchStamped = msg.WrenchStamped

rospy.init_node("solver_interface_sub", disable_signals = false)
println("init_node solver_interface_sub.")

solver_sub = rospy.Subscriber("/solver_input", WrenchStamped, solve_callback, queue_size=1)

if rospy.is_shutdown()
    @warn "rospy.is_shutdown()"
end

rospy.spin()

println("stop.")

I am aware that RobotOS.jl is one method to accomplish this, but I want to know how can I call rospy directly using PyCall.

Thank you very much.

ngharrison commented 2 months ago

I've tried to get rospy callbacks to work too. It doesn't even run the callback once. It seems to run up until the first function call (such as a print statement) within the callback and then hangs. The rest of the code in the function gets ignored. No luck finding a solution.