Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Teleop #16

Open
jnisa opened this issue Nov 3, 2017 · 3 comments
Open

Android Teleop #16

jnisa opened this issue Nov 3, 2017 · 3 comments

Comments

@jnisa
Copy link

jnisa commented Nov 3, 2017

Like we said during our presentation, we're trying to control our Pioneer 3DX with a mobile phone. To do that, we installed the application ROS All Sensors Driver (https://play.google.com/store/apps/details?id=org.ros.android.android_all_sensors_driver) and we used a ROS tutorial (http://wiki.ros.org/ROSARIA/Tutorials/Android%20teleop%20Pioneer%203at). So, as you can see in the tutorial, we make android_teleop.cpp, that contains all the instructions and we run this code with the CMakeLists.txt when we add the (rosbuild_add_executable(android_teleop android_teleop.cpp)) line to the CMakeLists.txt, but we are getting an error (as you can see in the image) and we don't know how to solve this. We already tried to add to the CMakeLists file the (add_executable(android_teleop android_teleop.cpp)) line, but that didn't solve the problem either. It seems like the executable line is not recognizable. Can you help us?
23262151_1953919528200524_712562983_o
CMakeLists.txt

The android_teleop.cpp file:
` /*
2 * Copyright (c) 2013, Anas Alhashimi LTU.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Willow Garage, Inc. nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 * Anas W. Alhahsimi
29 */

#include <ros/ros.h>
#include "geometry_msgs/Twist.h"
#include "ROSARIA/BumperState.h"
#include "sensor_msgs/Imu.h"
#include <signal.h>
#include <termios.h>

using geometry_msgs::Twist;
using namespace std;

ros::Publisher chatter_pub;
ros::Time t1;
Twist vel;
int kfd = 0;
struct termios cooked, raw;
unsigned int temp=0;
float x;
float y;
float z;

void quit(int sig)
{
tcsetattr(kfd, TCSANOW, &cooked);
ros::shutdown();
exit(0);
}

void anCallback(const sensor_msgs::Imu::ConstPtr& ansmsg)
{
x=ansmsg->angular_velocity.x;
y=ansmsg->angular_velocity.y;
z=ansmsg->angular_velocity.z;

}

int main(int argc, char** argv)
{
int ther=5;

ros::init(argc, argv, "android_teleop");
ros::NodeHandle n;
chatter_pub = n.advertise("/cmd_vel", 1);
signal(SIGINT,quit);
ros::Rate r(5);
char c;
bool dirty=false;
t1=ros::Time::now();

tcgetattr(kfd, &cooked);
memcpy(&raw, &cooked, sizeof(struct termios));
raw.c_lflag &=~ (ICANON | ECHO);
raw.c_cc[VEOL] = 1;
raw.c_cc[VEOF] = 2;
tcsetattr(kfd, TCSANOW, &raw);

//subscribe to android imu sensor msgs
ros::Subscriber imu_pub = n.subscribe<sensor_msgs::Imu>("/android/imu", 1, anCallback);

while (ros::ok())
{

if(x > ther)
{
vel.linear.x = 0.2;
vel.linear.y=0;
vel.linear.z=0;
vel.angular.x = 0;
vel.angular.y = 0;
vel.angular.z = 0;
ROS_INFO("forward");

}
if(x < -ther)
{
vel.linear.x = -0.2;
vel.linear.y=0;
vel.linear.z=0;
vel.angular.x = 0;
vel.angular.y = 0;
vel.angular.z = 0;
ROS_INFO("Backward");
}

if(z > ther)
{
vel.linear.x = 0;
vel.linear.y=0;
vel.linear.z=0;
vel.angular.x = 0;
vel.angular.y = 0;
vel.angular.z = 0.5;
ROS_INFO("Turnleft");
}
if(z < -ther)
{
vel.linear.x = 0;
vel.linear.y=0;
vel.linear.z=0;
vel.angular.x = 0;
vel.angular.y = 0;
vel.angular.z = -0.5;
ROS_INFO("Turnright");
}
if(y < -ther)
{
vel.linear.x = 0;
vel.linear.y=0;
vel.linear.z=0;
vel.angular.x = 0;
vel.angular.y = 0;
vel.angular.z = 0;
ROS_INFO("stop");
}
if(y > ther)
{
vel.linear.x = 0;
vel.linear.y=0;
vel.linear.z=0;
vel.angular.x = 0;
vel.angular.y = 0;
vel.angular.z = 0;
ROS_INFO("stop");
}

    chatter_pub.publish(vel);

ros::Duration(0.1).sleep(); // sleep for one tenth of a second

 ros::spinOnce();

}//while
return(0);
}
`

@jnisa
Copy link
Author

jnisa commented Nov 3, 2017

Maybe we are adding the executable line in the wrong space.

@oscar-lima
Copy link
Collaborator

if it is a python node it needs to be executable.
make sure that you have runned:

chmod +x filename.py

@oscar-lima
Copy link
Collaborator

Also please consider to use the teleop keyboard, since your project is not about moving the robot with cellphone or joypad but just to make it move by any means, (in the fastest possible way)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants