Skip to content
Snippets Groups Projects
Commit 4f836caa authored by bucyril's avatar bucyril
Browse files

ViconDataNode now working, added license, started PPSClient

parent d7afa9a4
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ project(d_fall_pps) ...@@ -8,6 +8,7 @@ project(d_fall_pps)
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages ## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS find_package(catkin REQUIRED COMPONENTS
message_generation
roscpp roscpp
rospy rospy
std_msgs std_msgs
...@@ -53,6 +54,11 @@ find_package(catkin REQUIRED COMPONENTS ...@@ -53,6 +54,11 @@ find_package(catkin REQUIRED COMPONENTS
# Message2.msg # Message2.msg
# ) # )
add_message_files(
FILES
ViconData.msg
)
## Generate services in the 'srv' folder ## Generate services in the 'srv' folder
# add_service_files( # add_service_files(
# FILES # FILES
...@@ -72,6 +78,10 @@ find_package(catkin REQUIRED COMPONENTS ...@@ -72,6 +78,10 @@ find_package(catkin REQUIRED COMPONENTS
# DEPENDENCIES # DEPENDENCIES
# std_msgs # std_msgs
# ) # )
generate_messages(
DEPENDENCIES
std_msgs
)
################################################ ################################################
## Declare ROS dynamic reconfigure parameters ## ## Declare ROS dynamic reconfigure parameters ##
...@@ -136,6 +146,7 @@ include_directories( ...@@ -136,6 +146,7 @@ include_directories(
## The recommended prefix ensures that target names across packages don't collide ## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/d_fall_pps_node.cpp) # add_executable(${PROJECT_NAME}_node src/d_fall_pps_node.cpp)
add_executable(ViconDataNode src/ViconDataNode.cpp) add_executable(ViconDataNode src/ViconDataNode.cpp)
add_executable(PPSClient src/PPSClient.cpp)
## Rename C++ executable without prefix ## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the ## The above recommended prefix causes long target names, the following renames the
...@@ -157,6 +168,8 @@ find_library(VICON_LIBRARY ViconDataStreamSDK_CPP HINTS lib/vicon) ...@@ -157,6 +168,8 @@ find_library(VICON_LIBRARY ViconDataStreamSDK_CPP HINTS lib/vicon)
target_link_libraries(ViconDataNode ${catkin_LIBRARIES}) target_link_libraries(ViconDataNode ${catkin_LIBRARIES})
target_link_libraries(ViconDataNode ${VICON_LIBRARY}) target_link_libraries(ViconDataNode ${VICON_LIBRARY})
target_link_libraries(PPSClient ${catkin_LIBRARIES})
############# #############
## Install ## ## Install ##
############# #############
......
this is copied from dusan and might therefore need modification
also you need to add this file in the CMakeLists.txt
float32 roll
float32 pitch
float32 yaw
uint16 thrust
uint16 motorCmd1
uint16 motorCmd2
uint16 motorCmd3
uint16 motorCmd4
uint8 onboardControllerType
string crazyflieName
float64 x
float64 y
float64 z
float64 roll
float64 pitch
float64 yaw
float64 acquiringTime
// ROS node that manages the student's setup.
// Copyright (C) 2017 Cyrill Burgener, Marco Mueller, Philipp Friedli
//
// 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 3 of the License, or
// (at your option) any later version.
//
// 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.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ros/ros.h"
int main(int argc, char* argv[]) {
ROS_INFO_STREAM("fdsafsfdsalj");
}
...@@ -12,136 +12,108 @@ ...@@ -12,136 +12,108 @@
#include <string.h> #include <string.h>
#include "DataStreamClient.h" #include "DataStreamClient.h"
#include "ros/ros.h" #include "ros/ros.h"
#include "d_fall_pps/ViconData.h"
using namespace ViconDataStreamSDK::CPP; using namespace ViconDataStreamSDK::CPP;
void connect(Client* client) { int main(int argc, char* argv[]) {
ros::init(argc, argv, "ViconDataNode");
ros::NodeHandle nodeHandle("~");
ros::Time::init();
ros::Publisher viconDataPublisher =
nodeHandle.advertise<d_fall_pps::ViconData>("ViconData", 1);
Client client;
//connect client to Vicon computer
std::string hostName = "10.42.00.15:801"; std::string hostName = "10.42.00.15:801";
ROS_INFO_STREAM("Connecting to " << hostName << " ..."); ROS_INFO_STREAM("Connecting to " << hostName << " ...");
while( !client->IsConnected().Connected ) while (!client.IsConnected().Connected) {
{ bool ok = (client.Connect(hostName).Result == Result::Success);
bool ok =( client->Connect( hostName ).Result == Result::Success );
if (!ok) {
if(!ok) ROS_ERROR("Error - connection failed...");
{
ROS_ERROR("Warning - connection failed...");
ros::Duration(1.0).sleep(); ros::Duration(1.0).sleep();
} } else {
else
{
ROS_INFO("Connected successfully"); ROS_INFO("Connected successfully");
} }
} }
}
void setupDataStream(Client* client) { //set data stream parameters
// Enable some different data types client.SetStreamMode(ViconDataStreamSDK::CPP::StreamMode::ClientPull);
ROS_INFO_STREAM("ClientPull stream mode enabled3");
client->EnableSegmentData();
client->EnableMarkerData();
client->EnableUnlabeledMarkerData();
client->EnableDeviceData();
ROS_INFO_STREAM("ClientPull stream mode enabled4");
// Set the streaming mode
client->SetStreamMode( ViconDataStreamSDK::CPP::StreamMode::ClientPull );
ROS_INFO_STREAM("ClientPull stream mode enabled");
// Set the global up axis
client->SetAxisMapping( Direction::Forward,
Direction::Left,
Direction::Up ); // Z-up
// client->SetGlobalUpAxis( Direction::Forward,
// Direction::Up,
// Direction::Right ); // Y-up
}
int main( int argc, char* argv[] )
{
ros::init(argc, argv, "ViconDataStreamSDK");
ROS_INFO_STREAM("Okili dokili");
ros::NodeHandle nodeHandle("~");
ros::Time::init();
Client client; client.EnableSegmentData();
connect(&client); client.EnableMarkerData();
setupDataStream(&client); client.EnableUnlabeledMarkerData();
client.EnableDeviceData();
while(ros::ok()) {
// Get a frame
while( client.GetFrame().Result != Result::Success )
{
// Sleep a little so that we don't lumber the CPU with a busy poll
ros::Duration(0.001).sleep();
}
// Count the number of subjects
unsigned int subjectCount = client.GetSubjectCount().SubjectCount;
// //Process the data and publish on topic // Set the global up axis
for(int index = 0 ; index < subjectCount ; index++ ) client.SetAxisMapping(Direction::Forward,
{ Direction::Left,
std::string subjName = client.GetSubjectName( index ).SubjectName; Direction::Up);
std::string segName = client.GetSegmentName( subjName, index ).SegmentName;
ROS_INFO_STREAM(subjName); while (ros::ok()) {
ROS_INFO_STREAM(segName); // Get a frame
ROS_INFO_STREAM("------"); while (client.GetFrame().Result != Result::Success) {
} // Sleep a little so that we don't lumber the CPU with a busy poll
ros::Duration(0.001).sleep();
}
} unsigned int subjectCount = client.GetSubjectCount().SubjectCount;
/*
while( ros::ok()) // //Process the data and publish on topic
{ for (int index = 0; index < subjectCount; index++) {
// Get a frame std::string subjectName = client.GetSubjectName(index).SubjectName;
while( client.GetFrame().Result != Result::Success ) std::string segmentName = client.GetSegmentName(subjectName, index).SegmentName;
{
// Sleep a little so that we don't lumber the CPU with a busy poll Output_GetSegmentGlobalTranslation outputTranslation =
ros::Duration(0.001).sleep(); client.GetSegmentGlobalTranslation(subjectName, segmentName);
Output_GetSegmentGlobalRotationQuaternion outputRotation =
client.GetSegmentGlobalRotationQuaternion(subjectName, segmentName);
//calculate position and rotation of Crazyflie
double quat_x = outputRotation.Rotation[0];
double quat_y = outputRotation.Rotation[1];
double quat_z = outputRotation.Rotation[2];
double quat_w = outputRotation.Rotation[3];
//TODO check whether this transformation is correct
double roll = atan2(2 * (quat_w * quat_x + quat_y * quat_z), 1 - 2 * (quat_x * quat_x + quat_y * quat_y));
double pitch = asin(2 * (quat_w * quat_y - quat_z * quat_x));
double yaw = atan2(2 * (quat_w * quat_z + quat_x * quat_y), 1 - 2 * (quat_y * quat_y + quat_z * quat_z));
//calculate time until frame data was received
Output_GetLatencyTotal outputLatencyTotal = client.GetLatencyTotal();
double totalViconLatency;
if (outputLatencyTotal.Result == Result::Success) {
totalViconLatency = outputLatencyTotal.Total;
} else {
totalViconLatency = 0;
} }
//Get frame rate //build and publish message
// Output_GetFrameRate OutputFrameRate = client.GetFrameRate (); d_fall_pps::ViconData viconData;
// if(OutputFrameRate.Result==Result::Success) viconData.crazyflieName = subjectName;
// std::cout<<"Frame Rate= "<<OutputFrameRate.FrameRateHz<<std::endl; viconData.x = outputTranslation.Translation[0];
// else viconData.y = outputTranslation.Translation[1];
// std::cout<<"Frame Rate not fetched ERROR"<<std::endl; viconData.z = outputTranslation.Translation[2];
viconData.roll = roll;
// //Get latency viconData.pitch = pitch;
// OutputLatencyTotal = client.GetLatencyTotal(); viconData.yaw = yaw;
// if(OutputLatencyTotal.Result==Result::Success) viconData.acquiringTime = totalViconLatency;
// totalViconLatency=OutputLatencyTotal.Total;
// else viconDataPublisher.publish(viconData);
// totalViconLatency=0;
// //std::cout<<"Total latency: "<<totalViconLatency;
// dataAcquiringTime=loopStartTime-ros::Duration(totalViconLatency);
// Count the number of subjects
int subjectCount = client.GetSubjectCount().SubjectCount;
ROS_INFO_STREAM();
// //Process the data and publish on topic
// for( SubjectIndex = 0 ; SubjectIndex < SubjectCount ; ++SubjectIndex )
// {
// // Get the subject's name
// subjectName = client.GetSubjectName( subjectIndex ).SubjectName;
// segmentName = client.GetSegmentName( subjectName, subjectIndex ).SegmentName;
// ROS_INFO_STREAM();
// }
} }
client.DisableSegmentData(); }
client.DisableMarkerData();
client.DisableUnlabeledMarkerData();
client.DisableDeviceData();
client.DisableSegmentData();
client.DisableMarkerData();
client.DisableUnlabeledMarkerData();
client.DisableDeviceData();
// Disconnect and dispose client.Disconnect();
ROS_WARN_STREAM(" Disconnecting..." << std::endl);
client.Disconnect();
ROS_WARN_STREAM(" Disconnected" << std::endl);
*/
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment