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

Maulik_Bhatt's profile - activity

2020-05-11 02:34:25 -0500 received badge  Famous Question (source)
2019-05-06 08:28:32 -0500 received badge  Famous Question (source)
2019-05-06 08:28:32 -0500 received badge  Notable Question (source)
2019-04-25 01:49:37 -0500 received badge  Notable Question (source)
2019-03-19 07:47:01 -0500 received badge  Famous Question (source)
2018-12-02 02:07:49 -0500 received badge  Famous Question (source)
2018-09-13 03:55:36 -0500 marked best answer How to use data of subscriber to publish and command the robot?

My main aim is to turn the robot to a specific angle. So, what I am trying to do is I have defined a subscriber and publisher in single node and then I will subscribe to the odometry data of the gazebo model through which I will calculate the yaw of the robot and until the robot gain the specific yaw I will command it a specific angular velocity. But the problem is when I define yaw in odometryCb it is not local variable so I can't use it in publisher part so tried defining variables in publisher it self but it is showing that sub has no attribute subscriber. Can anyone help me to find out how to deal it with?

#!/usr/bin/env python
import rospy
import roslib; roslib.load_manifest('firstrobot')
from std_msgs.msg import String
from nav_msgs.msg import Odometry
from std_msgs.msg import Header
from geometry_msgs.msg import Twist
import time
import math

TEXTFILE = open("data_pub.csv", "w")
TEXTFILE.truncate()

def odometryCb(msg):
   import csv
   #csvData=[['pose_x','pose_y','twist_x','twist_z', 'Orientation' ,'time']]
   x = msg.pose.pose.position.x
   y = msg.pose.pose.position.y
   v_x = msg.twist.twist.linear.x
   w = msg.twist.twist.angular.z
   q0 = msg.pose.pose.orientation.w
   q1 = msg.pose.pose.orientation.x
   q2 = msg.pose.pose.orientation.y
   q3 = msg.pose.pose.orientation.z
   yaw = math.degrees(math.atan2( 2.0*(q0*q3 + q1*q2),(1.0-2.0*(q2*q2 + q3*q3))))
   t= 1.0*msg.header.stamp.secs + 1.0*(msg.header.stamp.nsecs)/1000000000
   row = [ v_x, w, yaw, t]
   with open('data.csv', 'a') as csvFile:
      writer = csv.writer(csvFile)
      writer.writerow(row)
   csvFile.close()

def publisher():

pub = rospy.Publisher('robot_diff_drive_controller/cmd_vel', Twist, queue_size=10)
sub = rospy.Subscriber("robot_diff_drive_controller/odom", Odometry, odometryCb)
rospy.init_node('publisher', anonymous=True)
rate = rospy.Rate(10) # 10hz
cmd_vel = Twist()
odom = Odometry()
cmd_vel.linear.x=0.0
cmd_vel.angular.z=0.3
now = time.time()
du =  time.time()

x = sub.subscribe(odom.pose.pose.position.x)
y = sub.subscribe(odom.pose.pose.position.y)
v_x = sub.subscribe(odom.twist.twist.linear.x)
w = sub.subscribe(odom.twist.twist.angular.z)
q0 = sub.subscribe(odom.pose.pose.orientation.w)
q1 = sub.subscribe(odom.pose.pose.orientation.x)
q2 = sub.subscribe(odom.pose.pose.orientation.y)
q3 = sub.subscribe(odom.pose.pose.orientation.z)
yaw = math.degrees(math.atan2( 2.0*(q0*q3 + q1*q2),(1.0-2.0*(q2*q2 + q3*q3))))

while(yaw < 90):
    pub.publish(cmd_vel)
    rate.sleep()
# In ROS, nodes are uniquely named. If two nodes with the same
# node are launched, the previous one is kicked off. The
# anonymous=True flag means that rospy will choose a unique
# name for our 'listener' node so that multiple listeners can
# run simultaneously.

# spin() simply keeps python from exiting until this node is stopped
if __name__ == '__main__':
  publisher()
2018-09-03 04:10:30 -0500 received badge  Popular Question (source)
2018-09-02 13:00:44 -0500 received badge  Notable Question (source)
2018-08-31 03:20:19 -0500 commented answer Model not rotating to commanded yaw.

Nope actually I have tried that but that doesn't help. Robot is not even rotating up to 90%. I have subscribed to the ya

2018-08-30 05:17:40 -0500 received badge  Notable Question (source)
2018-08-30 02:29:06 -0500 answered a question How to use data of subscriber to publish and command the robot?

I finally got my code working with the code bellow. #!/usr/bin/env python import rospy import roslib; roslib.load_mani

2018-08-30 02:17:55 -0500 asked a question Model not rotating to commanded yaw.

Model not rotating to commanded yaw. I have written a publisher to rotate the robot to a specific angle but when I run t

2018-08-27 05:52:50 -0500 received badge  Popular Question (source)
2018-08-27 03:25:09 -0500 commented question How to use data of subscriber to publish and command the robot?

I tried that by putting this code in subscriber. still code is not working. rospy.init_node('publisher', anonymous=True

2018-08-27 03:22:49 -0500 commented question How to use data of subscriber to publish and command the robot?

rospy.init_node('publisher', anonymous=True) rate = rospy.Rate(10) cmd_vel = Twist() cmd_vel.linear.x=0.0

2018-08-27 03:22:09 -0500 commented question How to use data of subscriber to publish and command the robot?

rospy.init_node('publisher', anonymous=True) rate = rospy.Rate(10) cmd_vel = Twist() cmd_vel.linear.x=0.0

2018-08-27 03:18:31 -0500 commented question How to use data of subscriber to publish and command the robot?

I tried doing that by changing the code to the following but nothing happens after a run the code !/usr/bin/env python

2018-08-26 04:43:56 -0500 commented question How to use data of subscriber to publish and command the robot?

Actually, I found no tutorial which explains how to use data of the subscriber in the publisher of the same node. Can yo

2018-08-26 04:37:03 -0500 commented question How to use data of subscriber to publish and command the robot?

Then, what should I be the code instead of it?

2018-08-26 04:02:36 -0500 edited question How to use data of subscriber to publish and command the robot?

How to use data of subscriber to publish and command the robot? My main aim is to turn the robot to a specific angle. So

2018-08-26 03:58:53 -0500 asked a question How to use data of subscriber to publish and command the robot?

How to use data of subscriber to publish and command the robot? My main aim is to turn the robot to a specific angle. So

2018-08-26 02:01:30 -0500 commented answer How to subscribe to odom properly in python

Can you please explain what happens exactly when we run this code. This will help me in understanding the code better

2018-08-22 07:23:37 -0500 received badge  Famous Question (source)
2018-08-20 03:13:37 -0500 marked best answer Trajectory Tracking of URDF/ROS model in Gazebo

Hello,

I have a made a URDF model of a robot and currently spawning it in Gazebo. I have used diff_drive_controller to spawn it. Now, I want to track the model in a particular trajectory. Are there any tutorial available on internet? Can anyone help me regarding this?

2018-08-20 03:13:37 -0500 received badge  Scholar (source)
2018-08-20 02:28:14 -0500 commented answer Trajectory Tracking of URDF/ROS model in Gazebo

Thank you for the help.

2018-08-20 02:27:03 -0500 received badge  Popular Question (source)
2018-08-20 01:18:54 -0500 commented question Trajectory Tracking of URDF/ROS model in Gazebo

Hello, With tracking I meant I should be able to control where the robot should go, using a path with changing positions

2018-08-19 11:06:14 -0500 asked a question Trajectory Tracking of URDF/ROS model in Gazebo

Trajectory Tracking of URDF/ROS model in Gazebo Hello, I have a made a URDF model of a robot and currently spawning it

2018-06-25 01:02:17 -0500 received badge  Enthusiast
2018-06-13 04:17:38 -0500 received badge  Popular Question (source)
2018-06-12 23:46:01 -0500 asked a question Is it possible to launch a urdf file in gazebo without using xacro and clean up urdf file

Is it possible to launch a urdf file in gazebo without using xacro and clean up urdf file I am using this launch file to

2018-05-29 15:38:54 -0500 received badge  Notable Question (source)
2018-05-29 07:42:08 -0500 received badge  Popular Question (source)
2018-05-29 05:05:41 -0500 asked a question Invoking "make -j4 -l4" failed

Invoking "make -j4 -l4" failed Base path: /home/maulik/catkin_ws Source space: /home/maulik/catkin_ws/src Build space: /

2018-05-29 05:05:41 -0500 asked a question Invoking "make -j4 -l4" failed

Invoking "make -j4 -l4" failed Base path: /home/maulik/catkin_ws Source space: /home/maulik/catkin_ws/src Build space: /