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

Revision history [back]

click to hide/show revision 1
initial version

Hi, You are not able to simulate in Gazebo using youbot_ros_hello_world because that file is publishing arm and gripper data on the topic [1], [2] respectively which is given below (you could check this in youbot_ros_hello_world code): [1] arm_1/arm_controller/position_command [2] arm_1/gripper_controller/position_command Whereas no such topic exist while running simulation in Gazebo. You could check it by running following command: //run gazebo:

$ roslaunch youbot_gazebo_robot youbot.launch

//check topics

$ rostopic list

Topics on which you need to publish data are as give below: For arm: /arm_1/arm_controller/command For gripper: /arm_1/gripper_controller/command

Also, these topics have different message type associated with it which could be checked using following command:

$ rostopic info <topic_name>

You can check the data you need to publish for above msg type using following command:

$ rosmsg show <msg_type>

Hence, all you need to do is to publish right data (in the format of message type associated with the right topic) on right topic. REPLACE the code in youbot_ros_hello_world file with the code given below and enjoy the simulation.

// // Simple demo program that calls the youBot ROS wrapper //

include "ros/ros.h"

include "boost/units/systems/si.hpp"

include "boost/units/io.hpp"

include "brics_actuator/JointPositions.h"

include "geometry_msgs/Twist.h"

include "trajectory_msgs/JointTrajectory.h"

ros::Publisher platformPublisher; ros::Publisher armPublisher; ros::Publisher gripperPublisher;

// create a brics actuator message with the given joint position values trajectory_msgs::JointTrajectory createArmPositionCommand(std::vector<double>& newPositions) { int numberOfJoints = 5; trajectory_msgs::JointTrajectory msg;

if (newPositions.size() < numberOfJoints)
    return msg; // return empty message if not enough values provided

trajectory_msgs::JointTrajectoryPoint point;

for (int i = 0; i < 5; i++) { // 5 DOF
    point.positions.push_back(newPositions[i]);
    point.velocities.push_back(0);
    point.accelerations.push_back(0);
}
point.time_from_start = ros::Duration(1);
msg.points.push_back(point);

// set joint names
for (int i = 0; i < 5; i++) {
    std::stringstream jointName;
    jointName << "arm_joint_" << (i + 1);
    msg.joint_names.push_back(jointName.str());
}

// fill message header and sent it out
msg.header.frame_id = "arm_link_0";
msg.header.stamp = ros::Time::now();

return msg;

}

// create a brics actuator message for the gripper using the same position for both fingers trajectory_msgs::JointTrajectory createGripperPositionCommand(double newPosition) {

trajectory_msgs::JointTrajectory msg;

trajectory_msgs::JointTrajectoryPoint point;

for (int i = 0; i < 2; i++) { // 5 DOF
    point.positions.push_back(newPosition);
    point.velocities.push_back(0);
    point.accelerations.push_back(0);
}
point.time_from_start = ros::Duration(0.3);
msg.points.push_back(point);

// set joint names
for (int i = 0; i < 2; i++) {
    std::stringstream jointName;
    if(i==0)
        jointName << "gripper_finger_joint_l";
    else
        jointName << "gripper_finger_joint_r";

    msg.joint_names.push_back(jointName.str());
}

// fill message header and sent it out
msg.header.frame_id = "gripper_finger_joint_l";
msg.header.stamp = ros::Time::now();

return msg;

}

// move platform a little bit back- and forward and to the left and right void movePlatform() { geometry_msgs::Twist twist;

// forward
twist.linear.x = 0.05;  // with 0.05 m per sec
platformPublisher.publish(twist);
ros::Duration(2).sleep();

// backward
twist.linear.x = -0.05;
platformPublisher.publish(twist);
ros::Duration(2).sleep();

// to the left
twist.linear.x = 0;
twist.linear.y = 0.05;
platformPublisher.publish(twist);
ros::Duration(2).sleep();

// to the right
twist.linear.y = -0.05;
platformPublisher.publish(twist);
ros::Duration(2).sleep();

// stop
twist.linear.y = 0;
platformPublisher.publish(twist);

}

// move arm once up and down void moveArm() { trajectory_msgs::JointTrajectory msg;

std::vector<double> jointvalues(5);

// move arm straight up. values were determined empirically
jointvalues[0] = 2.95;
jointvalues[1] = 1.05;
jointvalues[2] = -2.44;
jointvalues[3] = 1.73;
jointvalues[4] = 2.95;
msg = createArmPositionCommand(jointvalues);
armPublisher.publish(msg);
ros::Duration(5).sleep();

// move arm back close to calibration position
jointvalues[0] = 0.11;
jointvalues[1] = 0.11;
jointvalues[2] = -0.11;
jointvalues[3] = 0.11;
jointvalues[4] = 0.111;
msg = createArmPositionCommand(jointvalues);
armPublisher.publish(msg);
ros::Duration(5).sleep();

}

// open and close gripper void moveGripper() { trajectory_msgs::JointTrajectory msg;

// open gripper
msg = createGripperPositionCommand(0.011);
gripperPublisher.publish(msg);

ros::Duration(3).sleep();

// close gripper
msg = createGripperPositionCommand(0);
gripperPublisher.publish(msg);

}

int main(int argc, char **argv) { ros::init(argc, argv, "youbot_ros_hello_world"); ros::NodeHandle n;

platformPublisher = n.advertise<geometry_msgs::Twist>("cmd_vel", 1);
armPublisher = n.advertise<trajectory_msgs::JointTrajectory>("arm_1/arm_controller/command", 1);
gripperPublisher = n.advertise<trajectory_msgs::JointTrajectory>("arm_1/gripper_controller/command", 1);
sleep(1);

movePlatform();
moveArm();
moveGripper();

sleep(1);
ros::shutdown();

return 0;

}

Hi, You are not able to simulate in Gazebo using youbot_ros_hello_world because that file is publishing arm and gripper data on the topic [1], [2] respectively which is given below (you could check this in youbot_ros_hello_world code): [1] arm_1/arm_controller/position_command [2] arm_1/gripper_controller/position_command Whereas no such topic exist while running simulation in Gazebo. You could check it by running following command: //run gazebo:

$ roslaunch youbot_gazebo_robot youbot.launch

//check topics

$ rostopic list

Topics on which you need to publish data are as give below: For arm: /arm_1/arm_controller/command For gripper: /arm_1/gripper_controller/command

Also, these topics have different message type associated with it which could be checked using following command:

$ rostopic info <topic_name>

You can check the data you need to publish for above msg type using following command:

$ rosmsg show <msg_type>

Hence, all you need to do is to publish right data (in the format of message type associated with the right topic) on right topic. REPLACE the code in youbot_ros_hello_world file with the code Code given in the link below and enjoy the simulation.

// // Simple demo program that calls the youBot ROS wrapper //

include "ros/ros.h"

include "boost/units/systems/si.hpp"

include "boost/units/io.hpp"

include "brics_actuator/JointPositions.h"

include "geometry_msgs/Twist.h"

include "trajectory_msgs/JointTrajectory.h"

ros::Publisher platformPublisher; ros::Publisher armPublisher; ros::Publisher gripperPublisher;

// create a brics actuator message with the given joint position values trajectory_msgs::JointTrajectory createArmPositionCommand(std::vector<double>& newPositions) { int numberOfJoints = 5; trajectory_msgs::JointTrajectory msg;

if (newPositions.size() < numberOfJoints)
    return msg; // return empty message if not enough values provided

trajectory_msgs::JointTrajectoryPoint point;

for (int i = 0; i < 5; i++) { // 5 DOF
    point.positions.push_back(newPositions[i]);
    point.velocities.push_back(0);
    point.accelerations.push_back(0);
}
point.time_from_start = ros::Duration(1);
msg.points.push_back(point);

// set joint names
for (int i = 0; i < 5; i++) {
    std::stringstream jointName;
    jointName << "arm_joint_" << (i + 1);
    msg.joint_names.push_back(jointName.str());
}

// fill message header and sent it out
msg.header.frame_id = "arm_link_0";
msg.header.stamp = ros::Time::now();

return msg;

}

// create a brics actuator message for the gripper using the same position for both fingers trajectory_msgs::JointTrajectory createGripperPositionCommand(double newPosition) {

trajectory_msgs::JointTrajectory msg;

trajectory_msgs::JointTrajectoryPoint point;

for (int i = 0; i < 2; i++) { // 5 DOF
    point.positions.push_back(newPosition);
    point.velocities.push_back(0);
    point.accelerations.push_back(0);
}
point.time_from_start = ros::Duration(0.3);
msg.points.push_back(point);

// set joint names
for (int i = 0; i < 2; i++) {
    std::stringstream jointName;
    if(i==0)
        jointName << "gripper_finger_joint_l";
    else
        jointName << "gripper_finger_joint_r";

    msg.joint_names.push_back(jointName.str());
}

// fill message header and sent it out
msg.header.frame_id = "gripper_finger_joint_l";
msg.header.stamp = ros::Time::now();

return msg;

}

// move platform a little bit back- and forward and to the left and right void movePlatform() { geometry_msgs::Twist twist;

// forward
twist.linear.x = 0.05;  // with 0.05 m per sec
platformPublisher.publish(twist);
ros::Duration(2).sleep();

// backward
twist.linear.x = -0.05;
platformPublisher.publish(twist);
ros::Duration(2).sleep();

// to the left
twist.linear.x = 0;
twist.linear.y = 0.05;
platformPublisher.publish(twist);
ros::Duration(2).sleep();

// to the right
twist.linear.y = -0.05;
platformPublisher.publish(twist);
ros::Duration(2).sleep();

// stop
twist.linear.y = 0;
platformPublisher.publish(twist);

}

// move arm once up and down void moveArm() { trajectory_msgs::JointTrajectory msg;

std::vector<double> jointvalues(5);

// move arm straight up. values were determined empirically
jointvalues[0] = 2.95;
jointvalues[1] = 1.05;
jointvalues[2] = -2.44;
jointvalues[3] = 1.73;
jointvalues[4] = 2.95;
msg = createArmPositionCommand(jointvalues);
armPublisher.publish(msg);
ros::Duration(5).sleep();

// move arm back close to calibration position
jointvalues[0] = 0.11;
jointvalues[1] = 0.11;
jointvalues[2] = -0.11;
jointvalues[3] = 0.11;
jointvalues[4] = 0.111;
msg = createArmPositionCommand(jointvalues);
armPublisher.publish(msg);
ros::Duration(5).sleep();

}

// open and close gripper void moveGripper() { trajectory_msgs::JointTrajectory msg;

// open gripper
msg = createGripperPositionCommand(0.011);
gripperPublisher.publish(msg);

ros::Duration(3).sleep();

// close gripper
msg = createGripperPositionCommand(0);
gripperPublisher.publish(msg);

}

int main(int argc, char **argv) { ros::init(argc, argv, "youbot_ros_hello_world"); ros::NodeHandle n;

platformPublisher = n.advertise<geometry_msgs::Twist>("cmd_vel", 1);
armPublisher = n.advertise<trajectory_msgs::JointTrajectory>("arm_1/arm_controller/command", 1);
gripperPublisher = n.advertise<trajectory_msgs::JointTrajectory>("arm_1/gripper_controller/command", 1);
sleep(1);

movePlatform();
moveArm();
moveGripper();

sleep(1);
ros::shutdown();

return 0;

}

simulation:

https://github.com/vijendra1125/youbot_gazebo_publisher

Hi, You are not able to simulate in Gazebo using youbot_ros_hello_world because that file is publishing arm and gripper data on the topic [1], [2] "arm_1/arm_controller/position_command" and "arm_1/gripper_controller/position_command" respectively which is given below (you you could check this in youbot_ros_hello_world code): [1] arm_1/arm_controller/position_command [2] arm_1/gripper_controller/position_command Whereas code) whereas no such topic exist while running simulation in Gazebo. You could check it by running following command: //run gazebo:

$ roslaunch youbot_gazebo_robot youbot.launch

//check topics

$ rostopic list

Topics on which you need to publish data are as give below: For arm: /arm_1/arm_controller/command For gripper: /arm_1/gripper_controller/command

Also, these topics have different message type associated with it which could be checked using following command:

$ rostopic info <topic_name>

You can check the data you need to publish for above msg type using following command:

$ rosmsg show <msg_type>

Hence, all you need to do is to publish right data (in the format of message type associated with the right topic) on right topic. Code given in the link below and enjoy simulation:

https://github.com/vijendra1125/youbot_gazebo_publisher

You are not able to simulate in Gazebo using youbot_ros_hello_world because that file is publishing arm and gripper data on the topic "arm_1/arm_controller/position_command" and "arm_1/gripper_controller/position_command" respectively you (you could check this in youbot_ros_hello_world code) whereas no such topic exist while running simulation in Gazebo. You could check it by running following command: //run gazebo:

$ roslaunch youbot_gazebo_robot youbot.launch

//check topics

$ rostopic list

Topics on which you need to publish data are as give below: For arm: /arm_1/arm_controller/command For gripper: /arm_1/gripper_controller/command

Also, these topics have different message type associated with it which could be checked using following command:

$ rostopic info <topic_name>

You can check the data you need to publish for above msg type using following command:

$ rosmsg show <msg_type>

Hence, all you need to do is to publish right data (in the format of message type associated with the right topic) on right topic. Code Use code given in the link below and enjoy simulation:

https://github.com/vijendra1125/youbot_gazebo_publisher

You are not able to simulate in Gazebo using youbot_ros_hello_world because that file is publishing arm and gripper data on the topic "arm_1/arm_controller/position_command" and "arm_1/gripper_controller/position_command" respectively (you could check this in youbot_ros_hello_world code) whereas no such topic exist while running simulation in Gazebo. You could check it by running following command: command:

//run gazebo:

$ roslaunch youbot_gazebo_robot youbot.launch

//check topics

$ rostopic list

Topics on which you need to publish data are as give below: For arm: /arm_1/arm_controller/command /arm_1/arm_controller/command

For gripper: /arm_1/gripper_controller/command

Also, these topics have different message type associated with it which could be checked using following command:

$ rostopic info <topic_name>

You can check the data you need to publish for above msg type using following command:

$ rosmsg show <msg_type>

Hence, all you need to do is to publish right data (in the format of message type associated with the right topic) on right topic. Use code given in the link below and enjoy simulation:

https://github.com/vijendra1125/youbot_gazebo_publisher

You are not able to simulate in Gazebo using youbot_ros_hello_world because that file is publishing arm and gripper data on the topic "arm_1/arm_controller/position_command" and "arm_1/gripper_controller/position_command" respectively (you could check this in youbot_ros_hello_world code) whereas no such topic exist while running simulation in Gazebo. You could check it by running following command:

//run gazebo:

$ roslaunch youbot_gazebo_robot youbot.launch

//check topics

$ rostopic list

Topics on which you need to publish data are as give below: below:

For arm: /arm_1/arm_controller/command

For gripper: /arm_1/gripper_controller/command

Also, these topics have different message type associated with it which could be checked using following command:

$ rostopic info <topic_name>

You can check the data you need to publish for above msg type using following command:

$ rosmsg show <msg_type>

Hence, all you need to do is to publish right data (in the format of message type associated with the right topic) on right topic. Use code given in the link below and enjoy simulation:

https://github.com/vijendra1125/youbot_gazebo_publisher

You are not able to simulate in Gazebo using youbot_ros_hello_world because that file is publishing arm and gripper data on the topic "arm_1/arm_controller/position_command" and "arm_1/gripper_controller/position_command" respectively (you could check this in youbot_ros_hello_world code) whereas no such topic exist while running simulation in Gazebo. You could check it by running following command:

//run gazebo:

$ roslaunch youbot_gazebo_robot youbot.launch

//check topics

$ rostopic list

Topics on which you need to publish data are as give below:

For arm: arm:

/arm_1/arm_controller/command

For gripper: gripper:

/arm_1/gripper_controller/command

Also, these topics have different message type associated with it which could be checked using following command:

$ rostopic info <topic_name>

You can check the data you need to publish for above msg type using following command:

$ rosmsg show <msg_type>

Hence, all you need to do is to publish right data (in in the format of message type associated with the right topic) on right topic. Use code the package given in the link below and enjoy simulation:below:

https://github.com/vijendra1125/youbot_gazebo_publisher

You are not able to simulate in Gazebo using youbot_ros_hello_world because that file is publishing arm and gripper data on the topic "arm_1/arm_controller/position_command" and "arm_1/gripper_controller/position_command" respectively (you could check this in youbot_ros_hello_world code) whereas no such topic exist while running simulation in Gazebo. You could check it by running following command:

//run gazebo:

$ roslaunch youbot_gazebo_robot youbot.launch

//check topics

$ rostopic list

Topics on which you need to publish data are as give below:

For arm:

arm: /arm_1/arm_controller/command

For gripper:

gripper: /arm_1/gripper_controller/command

Also, these topics have different message type associated with it which could be checked using following command:

$ rostopic info <topic_name>

You can check the data you need to publish for above msg type using following command:

$ rosmsg show <msg_type>

Hence, all you need to do is to publish right data in the format of message type associated with the right topic. Use the package given in the link below:

https://github.com/vijendra1125/youbot_gazebo_publisher

You are not able to simulate in Gazebo using youbot_ros_hello_world because that file is publishing arm and gripper data on the topic "arm_1/arm_controller/position_command" and "arm_1/gripper_controller/position_command" respectively (you could check this in youbot_ros_hello_world code) whereas no such topic exist while running simulation in Gazebo. You could check it by running following command:

//run gazebo:

$ roslaunch youbot_gazebo_robot youbot.launch

//check topics

$ rostopic list

Topics on which you need to publish data are as give below:

For arm: /arm_1/arm_controller/command

For gripper: /arm_1/gripper_controller/command

Also, these topics have different message type associated with it which could be checked using following command:

$ rostopic info <topic_name>

You can check the data you need to publish for above msg type using following command:

$ rosmsg show <msg_type>

Hence, all you need to do is to publish right data in the format of message type associated with the right topic. Use the package given in the link below:following link:

https://github.com/vijendra1125/youbot_gazebo_publisher

You are not able to simulate in Gazebo using youbot_ros_hello_world because that file is publishing arm and gripper data on the topic "arm_1/arm_controller/position_command" and "arm_1/gripper_controller/position_command" respectively (you could check this in youbot_ros_hello_world code) whereas no such topic exist while running simulation in Gazebo. You could check it by running following command:

//run gazebo:

$ roslaunch youbot_gazebo_robot youbot.launch

//check topics

$ rostopic list

Topics on which you need to publish data are as give below:

For arm: /arm_1/arm_controller/command

For gripper: /arm_1/gripper_controller/command

Also, these topics have different message type associated with it which could be checked using following command:

$ rostopic info <topic_name>

You can check the data you need to publish for above msg type using following command:

$ rosmsg show <msg_type>

Hence, all you need to do is to publish right data in the format of message type associated with the right topic. Use the package given in the following link:

https://github.com/vijendra1125/youbot_gazebo_publisher