2019-02-07 15:52:57 -0500 | received badge | ● Taxonomist
|
2015-06-09 16:28:39 -0500 | received badge | ● Famous Question
(source)
|
2015-06-09 00:49:42 -0500 | received badge | ● Famous Question
(source)
|
2015-05-27 11:57:47 -0500 | received badge | ● Famous Question
(source)
|
2015-05-23 14:57:18 -0500 | received badge | ● Famous Question
(source)
|
2015-05-19 04:51:24 -0500 | received badge | ● Famous Question
(source)
|
2015-04-29 07:39:26 -0500 | received badge | ● Notable Question
(source)
|
2015-04-22 10:32:40 -0500 | received badge | ● Notable Question
(source)
|
2015-03-24 12:47:33 -0500 | received badge | ● Notable Question
(source)
|
2015-03-24 07:29:48 -0500 | received badge | ● Popular Question
(source)
|
2015-03-23 05:14:55 -0500 | received badge | ● Popular Question
(source)
|
2015-03-19 21:36:57 -0500 | received badge | ● Notable Question
(source)
|
2015-03-19 08:47:35 -0500 | received badge | ● Popular Question
(source)
|
2015-03-19 04:05:23 -0500 | commented question | turtlebot odom |
2015-03-19 04:03:39 -0500 | asked a question | Navigation of turtlebot (Moving 1m forward, 1m left) I want to move my turtlebot 2 a fixed set of distances such as 1m forward, 1m right and etc accurately using odometry. This is the C++ code i have currently. However, it does not seem to be using the odometry. How should I change the code to enable myself to move the robot accurately ? Below is the code that I currently have. What it does is enable me to move the turtlebot as well as received odometry data on the console. class TurtleMoveAvoid;
class TurtleMoveAvoid {
public:
TurtleMoveAvoid() {
_pub = _n.advertise<geometry_msgs::Twist>("/mobile_base/commands/velocity", 1);
_sub = _n.subscribe("/odom", 1, &TurtleMoveAvoid::odomCallback, this);
_left = true;
_right = true;
}
void publish() {
if (_left && _right) {
forward();
} else if (_right) {
turnRight();
} else if (_left) {
turnLeft();
} else {
reverse();
}
}
void forward() {
geometry_msgs::Twist vel;
vel.linear.x = 0.2;
vel.angular.z = 0.0;
_pub.publish(vel);
}
void reverse() {
geometry_msgs::Twist vel;
vel.linear.x = -0.2;
vel.angular.z = 0.0;
_pub.publish(vel);
}
void turnLeft() {
geometry_msgs::Twist vel;
vel.linear.x = 0.0;
vel.angular.z = 0.7;
_pub.publish(vel);
}
void turnRight() {
geometry_msgs::Twist vel;
vel.linear.x = 0.0;
vel.angular.z = -0.7;
_pub.publish(vel);
}
void odomCallback(const nav_msgs::Odometry::ConstPtr& odom) {
ROS_INFO("I received odom: [%f,%f,%f]", odom->twist.twist.linear.x, odom->pose.pose.position.y,odom->pose.pose.orientation.z);
double xpos = odom->twist.twist.linear.x;
if(xpos < 0.2) //assuming 0.2 is the end
{
_right = true;
_left = true;
}
else
{
_right = false;
_left = false;
}
publish();
}
private:
ros::NodeHandle _n;
ros::Publisher _pub;
ros::Subscriber _sub;
bool _right, _left;
};// End of class TurtleMoveAvoid
int main(int argc, char **argv) {
ros::init(argc, argv, "turtle_move_odom");
TurtleMoveAvoid turtle;
ros::Rate loop_rate(10);
while (ros::ok())
{
ros::spinOnce(); //get new callback, adjust publish then publish again.
loop_rate.sleep();
}
return 0;
}
|
2015-03-19 02:54:12 -0500 | asked a question | turtlebot odom I want to make a node that moves the turtlebot2 accurately for certain distances. This is my code currently. However, it is not working and I know there are many errors. Please do help. The code covers what i intend to do which is:
1) subscribe to the /odom topic to get the turtlebot's current location
2) compare the location to its desired end point location (x_epos)
3) move towards the end point
4) keep moving until the current location from odometry is equal to the end location This is the code that I have: #include "ros/ros.h"
#include "std_msgs/String.h"
#include "nav_msgs/Odometry.h"
void odomCallback(const nav_msgs::Odometry::ConstPtr& odom)
{
ROS_INFO("I received odom: [%f,%f,%f]", odom->twist.twist.linear.x, odom->pose.pose.position.y,odom->pose.pose.position.z); //store x,y,z position values
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle nh;
ros::Subscriber sub_odom = nh.subscribe("odom", 1000, odomCallback);
double x_pos = odom.pose.pose.position.x;
double y_pos = odom.pose.pose.position.y;
double z_pos = odom.pose.pose.position.z;
double x_epos = 0.2; //desired end position
while (x_pos < x_epos && ros::ok()) //while robot is not at the end position
{
//move the robot towards the end position
ros::Publisher movement_pub = nh.advertise<geometry_msgs::Twist>("/mobile_base/commands/velocity", 10);
geometry_msgs::Twist vel;
vel.linear.x = 2.0;
vel.angular.z = 0.0;
movement_pub.publish(vel);
}
ros::spin();
return 0;
}
|
2015-03-18 13:51:02 -0500 | received badge | ● Popular Question
(source)
|
2015-03-17 21:30:17 -0500 | asked a question | nav_msgs/Odometry not running turtlebot Link to tutorial that I am following I've created a catkin package with a node with the code from that tutorial inside. I am able to catkin_make and build the cpp file. However, when i use rosrun to run it, my TurtleBot2 does not move. What is the problem? |
2015-03-16 21:51:35 -0500 | commented question | Move a certain distance, turn, then move (Odometry topic) http://answers.ros.org/question/20513... I was able to find a python script in a library book that achieves this. However, I dont know how to replicate as a ROS C++ node, I posted it as a separate question. |
2015-03-16 21:48:56 -0500 | asked a question | Odometry based out-and-back script (py to c++) I am a beginner learning about ROS. I want to create a similar script to this in C++. I got this from a book called "ROS-by-example" and it is in python. I am not fluent with python and ROS so I am unable to "translate" the language. Can anybody help to translate this into a C++ ROS node equivalent? Maybe just the ROS commands, I can convert the structures such as loops/variable declaration. I know C++, but I am unfamiliar with the ROS commands such as those with the rospy.(function name). I will be able to replicate the structures (for loops and class) in C++. Your help is greatly appreciated. #!/usr/bin/env python
""" odom_out_and_back.py - Version 1.1 2013-12-20
A basic demo of using the /odom topic to move a robot a given distance
or rotate through a given angle.
Created for the Pi Robot Project: http://www.pirobot.org
Copyright (c) 2012 Patrick Goebel. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.5
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details at:
http://www.gnu.org/licenses/gpl.html
"""
import rospy
from geometry_msgs.msg import Twist, Point, Quaternion
import tf
from rbx1_nav.transform_utils import quat_to_angle, normalize_angle
from math import radians, copysign, sqrt, pow, pi
class OutAndBack():
def __init__(self):
# Give the node a name
rospy.init_node('out_and_back', anonymous=False)
# Set rospy to execute a shutdown function when exiting
rospy.on_shutdown(self.shutdown)
# Publisher to control the robot's speed
self.cmd_vel = rospy.Publisher('/cmd_vel', Twist, queue_size=5)
# How fast will we update the robot's movement?
rate = 20
# Set the equivalent ROS rate variable
r = rospy.Rate(rate)
# Set the forward linear speed to 0.2 meters per second
linear_speed = 0.2
# Set the travel distance in meters
goal_distance = 1.0
# Set the rotation speed in radians per second
angular_speed = 1.0
# Set the angular tolerance in degrees converted to radians
angular_tolerance = radians(2.5)
# Set the rotation angle to Pi radians (180 degrees)
goal_angle = pi
# Initialize the tf listener
self.tf_listener = tf.TransformListener()
# Give tf some time to fill its buffer
rospy.sleep(2)
# Set the odom frame
self.odom_frame = '/odom'
# Find out if the robot uses /base_link or /base_footprint
try:
self.tf_listener.waitForTransform(self.odom_frame, '/base_footprint', rospy.Time(), rospy.Duration(1.0))
self.base_frame = '/base_footprint'
except (tf.Exception, tf.ConnectivityException, tf.LookupException):
try:
self.tf_listener.waitForTransform(self.odom_frame, '/base_link', rospy.Time(), rospy.Duration(1.0))
self.base_frame = '/base_link'
except (tf.Exception, tf.ConnectivityException, tf.LookupException):
rospy.loginfo("Cannot find transform between /odom and /base_link or /base_footprint")
rospy.signal_shutdown("tf Exception")
# Initialize the position variable as a Point ... (more) |
2015-03-16 20:52:57 -0500 | received badge | ● Notable Question
(source)
|
2015-03-16 20:47:48 -0500 | asked a question | Move a certain distance, turn, then move (Odometry topic) Currently, I am able to have my robot move forward for a certain distance, turn right by a certain degree, then move forward again. However, it is extremely inaccurate as highlighted in ahendrix's answer here "http://answers.ros.org/question/204973/robot-pose-slightly-off-when-publishing-to-cmd_vel/". I want to re-make this program by using the odometry topic. This is the current code that I have, I am currently working on the TurtleBot 2. #include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <math.h>
int main(int argc, char **argv)
{
const double PI = 3.14159265358979323846;
ros::init(argc, argv, "move_pub");
ros::NodeHandle n;
ros::Publisher movement_pub = n.advertise<geometry_msgs::Twist>("mobile_base/commands/velocity",1); //for sensors the value after , should be higher to get a more accurate result (queued)
ros::Rate rate(10); //the larger the value, the "smoother" , try value of 1 to see "jerk" movement
//move forward
ros::Time start = ros::Time::now();
while(ros::Time::now() - start < ros::Duration(5.0))
{
geometry_msgs::Twist move;
//velocity controls
move.linear.x = 0.1; //speed value m/s
move.angular.z = 0;
movement_pub.publish(move);
ros::spinOnce();
rate.sleep();
}
//turn right
ros::Time start_turn = ros::Time::now();
while(ros::Time::now() - start_turn < ros::Duration(4.0))
{
geometry_msgs::Twist move;
//velocity controls
move.linear.x = 0; //speed value m/s
move.angular.z = -2.25;
movement_pub.publish(move);
ros::spinOnce();
rate.sleep();
}
//move forward again
ros::Time start2 = ros::Time::now();
while(ros::Time::now() - start2 < ros::Duration(5.0))
{
geometry_msgs::Twist move;
//velocity controls
move.linear.x = 0.1; //speed value m/s
move.angular.z = 0;
movement_pub.publish(move);
ros::spinOnce();
rate.sleep();
}
return 0;
}
How should I go about replicating this program using the odometry topic? I am a beginner at ROS, all of your help will be greatly appreciated. I am currently on my school holidays and I am feeling great joy learning something new :) |
2015-03-16 20:20:33 -0500 | commented answer | Move a certain distance (geometry_msg:Twist) I appreciate your help very much. Thank you |
2015-03-16 20:20:15 -0500 | received badge | ● Scholar
(source)
|
2015-03-16 20:20:12 -0500 | received badge | ● Supporter
(source)
|
2015-03-16 20:20:06 -0500 | commented answer | Move a certain distance (geometry_msg:Twist) Thank you dornhege for teaching me about the ros::Time & ros::Duration function. However, i've taken a look at "http://answers.ros.org/question/204973/robot-pose-slightly-off-when-publishing-to-cmd_vel/" and realized that my method is prone to inaccuracy! I'll try publishing to /odom. |
2015-03-16 09:21:54 -0500 | received badge | ● Popular Question
(source)
|
2015-03-16 07:29:57 -0500 | received badge | ● Student
(source)
|
2015-03-16 05:03:45 -0500 | asked a question | Move a certain distance (geometry_msg:Twist) Currently this is the code that I have, and I am able to get the robot moving by editing the linear x or angular z values (speed). #include <ros/ros.h>
#include <geometry_msgs/Twist.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "move_pub");
ros::NodeHandle n;
ros::Publisher movement_pub = n.advertise<geometry_msgs::Twist>("mobile_base/commands/velocity",1);
ros::Rate rate(10);
while (ros::ok())
{
geometry_msgs::Twist move;
//velocity controls
move.linear.x = -0.1; //speed value m/s
move.angular.z = 0;
movement_pub.publish(move);
ros::spinOnce();
rate.sleep();
}
return 0;
}
Is there a time control in ROS? Whereby I can do something like while time <= 5s, publish linear x velocity of 0.2m/s. Thus, covering 1 meter. I am new to ROS and it is my first week into it. Im working on the TurtleBot 2. |