Julia Callback Unhandled Error
All, I am attempting to use RobotOS on Ubuntu 16.04 LTS with ROS Kinetic and Julia 0.4.5. I want to do something pretty simple - publish PWM from velocity commands. I have written the following code:
#!/usr/bin/env julia
using RobotOS
@rosimport std_msgs.msg: UInt8, Float32
rostypegen()
using std_msgs.msg
# Constants:
wheel_radius = 128.95e-3; # meters
gear_ratio = 1.0/12.0; # wheel turns/motor turns
max_rot = 2000.0; # maximum rpm of motors
function calc_pwm(target)
target = convert(Float64, target) # make sure data types are OK
# Calculate desired RPM
rpm = abs(target)*60.0/(2.0*pi*wheel_radius*gear_ratio);
if rpm > max_rot
rpm = max_rot
end
# Calculte the PWM based off of RPM
if target > 0.0
pwm = (92.0/max_rot)*rpm+160.0;
elseif target < 0.0
pwm = 153.0-(92.0*rpm)/max_rot;
else
pwm = 155.0;
end
end
function callback(msg::Float32Msg, pub_obj::Publisher{UInt8Msg})
# Extract the data from rwheel_vtarget msg
velocity = msg.data
# Calculate the PWM
pwm = calc_pwm(velocity)
# Convert to ROS message
pwm = UInt8Msg(pwm)
# Publish the data
publish(pub_obj, pwm)
end
function main()
init_node("speed_to_pwm")
#r_pub = Publisher{UInt8Msg}("Duty_Cycle_Right", queue_size=10)
#r_sub = Subscriber{Float32Msg}("rwheel_vtarget", callback, (r_pub,), queue_size=10)
l_pub = Publisher{UInt8Msg}("Duty_Cycle_Left", queue_size=10)
l_sub = Subscriber{Float32Msg}("lwheel_vtarget", callback, (l_pub,), queue_size=20)
spin()
end
if ! isinteractive()
main()
end
When I run this script and use the rostopic pub
command it works perfectly, but when I integrate (joy --> teleop_twist_joy-->twist_to_vel-->Julia Node) it gives the following error:
ERROR (unhandled task failure): InexactError()
in call at ./no file:4294967295
in callback at /home/connorfuhrman/catkin_ws/src/speed_to_pwm/scripts/pwm_gen.jl:67
Honestly, I am not very experienced in ROS or Julia so any help would be appreciated!
I'm not very familiar with Julia, but it looks like your callback is getting called and is throwing some kind of error about loss of precision. Maybe try
rostopic pub
with various decimal values to try to reproduce the issue?