somehow managed to implement rotation cleanly
This commit is contained in:
@@ -1,14 +1,27 @@
|
|||||||
#ifndef _UTILS_HPP_
|
#ifndef _UTILS_HPP_
|
||||||
#define _UTILS_HPP_
|
#define _UTILS_HPP_
|
||||||
|
|
||||||
|
#define PI 3.14159265358979323846
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template<typename T> inline std::string stuff_to_str(T i) {
|
template<typename T> inline std::string stuff_to_str(T i) {
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << i;
|
ss << i;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double radians(double degrees) {
|
||||||
|
return degrees / 180 * PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
double degrees(double radians) {
|
||||||
|
return radians / PI * 180;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ def inform_controller_factory(who):
|
|||||||
|
|
||||||
|
|
||||||
def handle_request(r):
|
def handle_request(r):
|
||||||
|
global STATE
|
||||||
module = r.module
|
module = r.module
|
||||||
message = r.message
|
message = r.message
|
||||||
_state_old = STATE
|
_state_old = STATE
|
||||||
permission = False
|
permission = False
|
||||||
global STATE
|
|
||||||
|
|
||||||
if module == 'walker':
|
if module == 'walker':
|
||||||
if message == 'move':
|
if message == 'move':
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ from controller import inform_controller_factory
|
|||||||
|
|
||||||
|
|
||||||
#min #max
|
#min #max
|
||||||
FW = 1.65, 1.45
|
FW = -1.65, -1.45
|
||||||
BK = 2.20, 2.40
|
BK = -2.20, -2.40
|
||||||
LT = -0.35, -0.53
|
LT = 0.35, 0.53
|
||||||
RT = 0.35, 0.53
|
RT = -0.35, -0.53
|
||||||
|
LR = 0.45, 0.85
|
||||||
|
RR = -0.45, -0.85
|
||||||
|
|
||||||
VMIN = 0.3
|
VMIN = 0.3
|
||||||
VMAX = 1.0
|
VMAX = 1.0
|
||||||
@@ -39,34 +41,42 @@ if __name__ == '__main__':
|
|||||||
rospy.wait_for_service('inform_controller')
|
rospy.wait_for_service('inform_controller')
|
||||||
ll = tf.TransformListener()
|
ll = tf.TransformListener()
|
||||||
mp = ALProxy('ALMotion', os.environ['NAO_IP'], 9559)
|
mp = ALProxy('ALMotion', os.environ['NAO_IP'], 9559)
|
||||||
mp.wakeUp()
|
# mp.wakeUp()
|
||||||
mp.moveInit()
|
mp.moveInit()
|
||||||
mp.setMoveArmsEnabled(False, False)
|
mp.setMoveArmsEnabled(False, False)
|
||||||
|
|
||||||
while not rospy.is_shutdown():
|
while not rospy.is_shutdown():
|
||||||
sleep(0.3)
|
sleep(0.3)
|
||||||
try:
|
try:
|
||||||
trans, rot = ll.lookupTransform('Aruco_0_frame',
|
trans, q = ll.lookupTransform('odom',
|
||||||
'odom',
|
'Aruco_0_frame',
|
||||||
rospy.Time(0))
|
rospy.Time(0))
|
||||||
|
rot = tf.transformations.euler_from_quaternion(q)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
mp.stopMove()
|
mp.stopMove()
|
||||||
_inform_controller('stop')
|
_inform_controller('stop')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# print trans
|
# print trans
|
||||||
|
# print rot
|
||||||
# continue
|
# continue
|
||||||
|
|
||||||
movement = [0, 0, 0]
|
movement = [0, 0, 0]
|
||||||
#-1 1 -1 1
|
ref_vec = trans[:2] + rot[2:]
|
||||||
for i, dr in enumerate((BK, FW, RT, LT)):
|
#-1 1 -1 1 -1 1
|
||||||
|
for i, dr in enumerate((BK, FW, RT, LT, RR, LR)):
|
||||||
idx = i // 2
|
idx = i // 2
|
||||||
sign = 1 if (i % 2) else -1
|
sign = 1 if (i % 2) else -1
|
||||||
speed = _speed(trans[idx], dr)
|
speed = _speed(ref_vec[idx], dr)
|
||||||
if speed:
|
if speed:
|
||||||
movement[idx] = sign * speed
|
movement[idx] = sign * speed
|
||||||
break
|
break
|
||||||
|
|
||||||
|
rospy.loginfo('WALKER: TRANS: {}'.format(trans))
|
||||||
|
rospy.loginfo('WALKER: ROTTN: {}'.format(rot))
|
||||||
|
rospy.loginfo('WALKER: MOVMT: {}\n'.format(movement))
|
||||||
|
|
||||||
if not any(movement):
|
if not any(movement):
|
||||||
rospy.logdebug('WALKER: STOP')
|
rospy.logdebug('WALKER: STOP')
|
||||||
_inform_controller('stop')
|
_inform_controller('stop')
|
||||||
@@ -77,10 +87,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
if not permission:
|
if not permission:
|
||||||
mp.stopMove()
|
mp.stopMove()
|
||||||
continue
|
else:
|
||||||
|
# mp.moveToward(*movement) # DON'T DELETE THIS ONE
|
||||||
rospy.loginfo('WALKER: TRANS: {}'.format(trans))
|
pass
|
||||||
rospy.loginfo('WALKER: MOVMT: {}'.format(movement))
|
|
||||||
mp.moveToward(*movement)
|
|
||||||
|
|
||||||
mp.rest()
|
mp.rest()
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <opencv2/highgui/highgui.hpp>
|
#include <opencv2/highgui/highgui.hpp>
|
||||||
#include <opencv2/video/tracking.hpp>
|
#include <opencv2/video/tracking.hpp>
|
||||||
#include <aruco/aruco.h>
|
#include <aruco/aruco.h>
|
||||||
|
#include <teleoperation/utils.hpp>
|
||||||
|
|
||||||
static const std::string ARUCO_WINDOW = "Aruco window";
|
static const std::string ARUCO_WINDOW = "Aruco window";
|
||||||
|
|
||||||
@@ -25,9 +26,6 @@ class ImageConverter {
|
|||||||
ImageConverter() :
|
ImageConverter() :
|
||||||
it_(nh_)
|
it_(nh_)
|
||||||
{
|
{
|
||||||
ros::Rate loop_rate(0.1);
|
|
||||||
loop_rate.sleep();
|
|
||||||
|
|
||||||
// Subscribe to input video feed
|
// Subscribe to input video feed
|
||||||
image_sub_ = it_.subscribe("/usb_cam/image_raw", 1,
|
image_sub_ = it_.subscribe("/usb_cam/image_raw", 1,
|
||||||
&ImageConverter::imageCb, this);
|
&ImageConverter::imageCb, this);
|
||||||
@@ -75,39 +73,48 @@ class ImageConverter {
|
|||||||
// Draw and print aruco
|
// Draw and print aruco
|
||||||
cv::Mat aruco_demo = cv_ptr->image.clone();
|
cv::Mat aruco_demo = cv_ptr->image.clone();
|
||||||
for (int i = 0; i < markers.size(); i++) {
|
for (int i = 0; i < markers.size(); i++) {
|
||||||
markers[i].draw(aruco_demo, cv::Scalar(0, 0, 255), 2);
|
|
||||||
float x = -markers[i].Tvec.at<float>(2);
|
|
||||||
float y = markers[i].Tvec.at<float>(0);
|
|
||||||
float z = -markers[i].Tvec.at<float>(1);
|
|
||||||
|
|
||||||
// cv::Mat rot_mat;
|
markers[i].draw(aruco_demo, cv::Scalar(0, 0, 255), 2);
|
||||||
// cv::Rodrigues(markers[i].Rvec, rot_mat);
|
|
||||||
// float roll = atan2(
|
cv::Mat rot_cv;
|
||||||
// rot_mat.at<float>(2,1),
|
cv::Rodrigues(markers[i].Rvec, rot_cv);
|
||||||
// rot_mat.at<float>(2,2));
|
|
||||||
// float pitch = -atan2(
|
tf::Matrix3x3 rot(
|
||||||
// rot_mat.at<float>(2,0),
|
rot_cv.at<float>(0, 0),
|
||||||
// sqrt(
|
rot_cv.at<float>(0, 1),
|
||||||
// pow(rot_mat.at<float>(2,1),2) +
|
rot_cv.at<float>(0, 2),
|
||||||
// pow(rot_mat.at<float>(2,2),2)));
|
rot_cv.at<float>(1, 0),
|
||||||
// float yaw = atan2(
|
rot_cv.at<float>(1, 1),
|
||||||
// rot_mat.at<float>(1,0),
|
rot_cv.at<float>(1, 2),
|
||||||
// rot_mat.at<float>(0,0));
|
rot_cv.at<float>(2, 0),
|
||||||
|
rot_cv.at<float>(2, 1),
|
||||||
|
rot_cv.at<float>(2, 2)
|
||||||
|
);
|
||||||
|
tf::Vector3 trans(
|
||||||
|
markers[i].Tvec.at<float>(0),
|
||||||
|
markers[i].Tvec.at<float>(1),
|
||||||
|
markers[i].Tvec.at<float>(2)
|
||||||
|
);
|
||||||
|
tf::Matrix3x3 hmat(
|
||||||
|
0, 0, -1,
|
||||||
|
1, 0, 0,
|
||||||
|
0, -1, 0
|
||||||
|
);
|
||||||
|
tf::Matrix3x3 another(
|
||||||
|
0, 0, -1,
|
||||||
|
1, 0, 0,
|
||||||
|
0, -1, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
rot = hmat * rot * another; // This all somehow works as expected
|
||||||
|
trans = hmat * trans;
|
||||||
|
|
||||||
|
tf::Transform aruco_tf(rot, trans);
|
||||||
|
|
||||||
std::string id = "Aruco_";
|
std::string id = "Aruco_";
|
||||||
|
id += stuff_to_str(markers[i].id);
|
||||||
// int to str basically
|
|
||||||
std::ostringstream ss;
|
|
||||||
ss << markers[i].id;
|
|
||||||
id += ss.str();
|
|
||||||
|
|
||||||
id += "_frame";
|
id += "_frame";
|
||||||
tf::Transform aruco_tf;
|
|
||||||
aruco_tf.setIdentity();
|
|
||||||
// tf::Quaternion q;
|
|
||||||
// q.setRPY(roll, pitch, yaw);
|
|
||||||
aruco_tf.setOrigin(tf::Vector3(x, y, z));
|
|
||||||
// aruco_tf.setRotation(q);
|
|
||||||
this->aruco_pub.sendTransform(tf::StampedTransform(
|
this->aruco_pub.sendTransform(tf::StampedTransform(
|
||||||
aruco_tf, ros::Time::now(), "odom",
|
aruco_tf, ros::Time::now(), "odom",
|
||||||
id.c_str()));
|
id.c_str()));
|
||||||
|
|||||||
Reference in New Issue
Block a user