ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

cannot get multiple nodes running

asked 2018-10-06 07:51:21 -0600

renanmb gravatar image

updated 2022-01-22 16:16:23 -0600

Evgeny gravatar image

I wrote a package with 2 nodes in python exactly how I have always done before, and it compiles without errors with catkin_make, but one of the nodes does not work. It does not publish or subscribe anything or give errors at all.

This is really confusing for me. I am posting my github:

All the code is there, I just want to get the to work

The node should simply get the messages from and make it compatible to VESC and respect the motor limits.

I would appreciate any help.

#!/usr/bin/env python

# Python
import sys
from math import pi

import rospy
import tf
from dynamic_reconfigure.server import Server 
#from boat_controller.cfg import *
from boat_controller.cfg import YawDynamicConfig
from boat_controller.cfg import TwistDynamicConfig

from boat_controller.msg import Diagnose
#from boat_pid_controller.msg import *

from geometry_msgs.msg import Vector3
from geometry_msgs.msg import Twist
from std_msgs.msg import Float64
from nav_msgs.msg import Odometry 
from boat_controller.msg import Drive
from boat_controller.msg import Course
from sensor_msgs.msg import Imu 
#from std_srvs.srv import SetBool, SetBoolResponse, SetBoolRequest
from std_srvs.srv import Empty, EmptyResponse

import pypid

class Node():
    def __init__(self, engaged=False, yaw_cntrl=True,vel_cntrl=True):
        # Detup Yaw Pid
        self.engaged = engaged
        self.yaw_cntrl = yaw_cntrl
        self.vel_cnrtl = vel_cntrl
        self.ypid = pypid.Pid(0.0, 0.0, 0.0)
        fc = 20; #cutoff freq in Hz
        wc = fc*(2.0*pi) #cutoff freq in rad/s
        self.ypid.set_derivfilter(1, wc)
        # Setup Velocity Pid
        self.vpid = pypid.Pid(0.0, 0.0, 0.0)
        fc = 20; # cutoff freq in Hz
        wc = fc*(2.0*pi) # cutoff freq in rad/s
        # Initialize as none for now
        self.drivemsg = None
        self.publisher = None
        self.lasttime = None
        # For tuning PID
        self.vpubdebug = None
        self.ypubdebug = None

        # Type of yaw control
        self.yaw_type = 'yaw'

    def toggle_engaged_callback(self,req):
        self.engaged = not self.engaged
        rospy.loginfo('Toggling engaged status - new status is...')

        if self.engaged:
            self.ypid.I = 0.0
            self.vpid.I = 0.0
        return EmptyResponse()

    def twist_callback(self,msg):

    def course_callback(self,msg):

    def odom_callback(self,msg):
        # calculate time step
        now = rospy.get_time()
        if self.lasttime is None:
            self.lasttime = now
        dt = now-self.lasttime
        self.lasttime = now
        # Yaw control
        if self.yaw_cntrl:
            if self.yaw_type=='yaw_rate':
                yaw_fdbk = msg,twist.twist.angular.z
            elif self.yaw_type=='yaw':
                euler = tf.transformations.euler_from_quaternion(
                yaw_fdbk = euler[2] # yaw
            yout = self.ypid.execute(dt,yaw_fdbk)
            torque = yout ...
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-10-06 09:42:23 -0600

gvdhoorn gravatar image has a rospy.spin() in the constructor. I don't think that is how it's supposed to be.

edit flag offensive delete link more



gvdhoom: +1 for going to github to see her/his code.

billy gravatar image billy  ( 2018-10-06 15:25:44 -0600 )edit

In my opinion github makes the post much clear. But yeah, thanks. rospy.spin() is not the answer

renanmb gravatar image renanmb  ( 2018-10-07 14:04:24 -0600 )edit

@renanmb: I don't understand what you write in your comment.

Also: please just include and in your question. That way it becomes self-contained.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-08 01:13:41 -0600 )edit

I simply does know what I made wrong. It should be working. I also see that there are better ways to create a controller structure. Recently I have been thinking to use ros_control and its whole structure.

renanmb gravatar image renanmb  ( 2018-10-09 12:27:43 -0600 )edit

You still have a rospy.spin() in your constructor (via _run(..)).

I'm not saying it's necessarily the problem, but spin() is a blocking call. Afaik blocking calls in your ctor are a bad idea.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-09 14:36:29 -0600 )edit

Your edit seems to suggest that things now work but you're trying to retrieve a parameter that was not set.

That would seem to be a different problem.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-10 07:34:14 -0600 )edit

According to dos not seem to have a problem. I am setting a global parameter on VESC.yaml on my config folder.

I might be a little lost on the parameters thing.

renanmb gravatar image renanmb  ( 2018-10-10 07:45:22 -0600 )edit

Question Tools



Asked: 2018-10-06 07:51:21 -0600

Seen: 208 times

Last updated: Oct 10 '18