Ask Your Question
0

Differential drive getting ValueError: data_class [type] is not a message data class

asked 2017-07-30 01:51:39 -0600

renanmb gravatar image

I started to practice with python, and I am getting a few errors that I does not understand very well.

This is my code:

#!/usr/bin/python
import rospy
import roslib

# Messages
from std_msgs.msg import Float32
from std_msgs.msg import Bool

# Issue commands to the GoPiGo motors to achieve the target velocity
# Use a PID that compares the error based on encoder readings
class ControlsToMotors:
  def __init__(self):
    rospy.init_node('surp_controller')
    self.rate = rospy.get_param('~rate', 50)

    # Wheel can turn ~17 ticks per second which is approx 5.34 rad / s when motor_cmd = 255 ******Modify - calibrate according to the Stepper motor
    self.motor_max_angular_vel = rospy.get_param('~motor_max_angular_vel',5.32) 
    # Wheel can turn ~6 ticks per second which is approx 5.34 rad / s when motor_cmd = 125  ******Modify - calibrate according to the Stepper motor
    self.motor_min_angular_vel = rospy.get_param('~motor_min_angular_vel',1.28)
    # Corresponding motor commands
    self.motor_cmd_max = rospy.get_param('~motor_cmd_max',255)
    self.motor_cmd_min = rospy.get_param('~motor_cmd_min',110)

    self.R = rospy.get_param('~robot_wheel_radius', 0.03)
    self.gopigo_on = rospy.get_param('~gopigo_on',False)
    if self.gopigo_on:
      import gopigo
      import atexit
      atexit.register(gopigo.stop)
    # (Optional) Publish the computed angular velocity targets
    self.lwheel_angular_vel_target_pub = rospy.Publisher('lwheel_angular_vel_target', Float32, queue_size=10)
    self.rwheel_angular_vel_target_pub = rospy.Publisher('rwheel_angular_vel_target', Float32, queue_size=10)

    # (Optional) Publish the computed angular velocity control command
    self.lwheel_angular_vel_control_pub = rospy.Publisher('lwheel_angular_vel_control', Float32, queue_size=10)
    self.rwheel_angular_vel_control_pub = rospy.Publisher('rwheel_angular_vel_control', Float32, queue_size=10)

    # (Optional) Publish the computed angular velocity motor command
    self.lwheel_angular_vel_motor_pub = rospy.Publisher('lwheel_angular_vel_motor', Float32, queue_size=10)
    self.rwheel_angular_vel_motor_pub = rospy.Publisher('rwheel_angular_vel_motor', Float32, queue_size=10)

    # Publish commands to the arduino ***************************************
    self.motor1_cmd_pub = rospy.Publisher("motor1_cmd", Float32, queue_size=10)
    self.motor2_cmd_pub = rospy.Publisher("motor2_cmd", Float32, queue_size=10)

    # Publish motor direction to robot******************************
    self.motor1_dir_pub = rospy.Publisher("motor1_dir", bool, queue_size=10)
    self.motor2_dir_pub = rospy.Publisher("motor2_dir", bool, queue_size=10)

    # Read in encoders for PID control
    self.lwheel_angular_vel_enc_sub = rospy.Subscriber('lwheel_angular_vel_enc', Float32, self.lwheel_angular_vel_enc_callback)    
    self.rwheel_angular_vel_enc_sub = rospy.Subscriber('rwheel_angular_vel_enc', Float32, self.rwheel_angular_vel_enc_callback)    

    # Read in tangential velocity targets
    self.lwheel_tangent_vel_target_sub = rospy.Subscriber('lwheel_tangent_vel_target', Float32, self.lwheel_tangent_vel_target_callback)
    self.rwheel_tangent_vel_target_sub = rospy.Subscriber('rwheel_tangent_vel_target', Float32, self.rwheel_tangent_vel_target_callback)


    # Tangential velocity target
    self.lwheel_tangent_vel_target = 0;
    self.rwheel_tangent_vel_target = 0;

    # Angular velocity target
    self.lwheel_angular_vel_target = 0
    self.rwheel_angular_vel_target = 0

    # Angular velocity encoder readings
    self.lwheel_angular_vel_enc = 0
    self.rwheel_angular_vel_enc = 0

    # motor_cmd I dont know if it is necessary
    self.motor1_cmd = 0
    self.motor2_cmd = 0
    self.motor1_dir = True
    self.motor2_dir = True

  # ==================================================
  # Publish motor cmd to the robot
  # ==================================================
  def motor1_cmd_pub(self, msg):
    self.motor1_cmd = msg.data
  def motor2_cmd_pub(self, msg):
    self.motor2_cmd = msg.data
  def motor1_dir_pub(self, msg):
    self.motor1_dir = msg.data
  def motor2_dir_pub(self, msg):
    self.motor2_dir = msg.data

  # ==================================================
  # Read in tangential velocity targets
  # ==================================================
  def lwheel_tangent_vel_target_callback(self, msg):
      self.lwheel_tangent_vel_target = msg.data

  def rwheel_tangent_vel_target_callback(self, msg):
      self.rwheel_tangent_vel_target = msg.data

  # ==================================================
  # Read in encoder readings for PID
  # Consider for future iterations- modify for Back EMF, or use motor with encoder, or rely only on IMU
  # ==================================================
  def lwheel_angular_vel_enc_callback(self, msg):
    self.lwheel_angular_vel_enc = msg.data

  def rwheel_angular_vel_enc_callback(self, msg):
    self.rwheel_angular_vel_enc = msg.data

  # ==================================================
  # Update motor commands
  # ==================================================

  # Compute angular velocity target
  def tangentvel_2_angularvel(self,tangent_vel):
    # v = wr
    # v - tangential velocity (m/s ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-07-30 08:41:03 -0600

gvdhoorn gravatar image
 File "/home/rmb/gopigo_ws/src/gopigo_controller/src/surp_controller.py", line 47, in __init__
    self.motor1_dir_pub = rospy.Publisher("motor1_dir", bool, queue_size=10)

bool is not a message type.

Bool is.

edit flag offensive delete link more

Comments

Thanks. So every time I have a ValueError msg it is because I wrote something wrong? But how do I know what I wrote wrong?

renanmb gravatar imagerenanmb ( 2017-07-30 09:30:35 -0600 )edit
1

every time I have a ValueError msg it is because I wrote something wrong

no. ValueError is a Python exception. You should probably read up on those.

how do I know what I wrote wrong?

By running your script. Python is an interpreted language, so no compiler to help you.

gvdhoorn gravatar imagegvdhoorn ( 2017-07-30 09:41:52 -0600 )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

1 follower

Stats

Asked: 2017-07-30 01:51:39 -0600

Seen: 700 times

Last updated: Jul 30 '17