Ask Your Question

Julia Callback Unhandled Error

asked 2018-05-21 17:03:33 -0500

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
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
    # 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;
        pwm = 155.0;

function callback(msg::Float32Msg, pub_obj::Publisher{UInt8Msg})
    # Extract the data from rwheel_vtarget msg
    velocity =
    # Calculate the PWM
    pwm = calc_pwm(velocity)
    # Convert to ROS message
    pwm = UInt8Msg(pwm)
    # Publish the data
    publish(pub_obj, pwm)

function main()
    #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)

if ! isinteractive()

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!

edit retag flag offensive close merge delete


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?

ahendrix gravatar image ahendrix  ( 2018-05-21 18:28:43 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-21 18:49:55 -0500

jdlangs gravatar image

The issue is that your callback returns the pwm signal as a Float64 but then you try to to put it into a UInt8Msg. Julia tries to convert it and fails when it discovers the number isn't exactly an integer from 0-255. An explicit conversion such as return round(UInt8, pwm) at the end of calc_pwm should fix it.

edit flag offensive delete link more


Thank you!! This is the second Julia script I have ever written so rookie mistake.

cmfuhrman gravatar image cmfuhrman  ( 2018-05-21 19:35:30 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-05-21 17:03:33 -0500

Seen: 140 times

Last updated: May 21 '18