mk_test1.cpp
Go to the documentation of this file.
00001 /*
00002  * mk_test1.cpp
00003  *
00004  *  Created on: Nov 25, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <tk_mkinterface/MKInterfaceConnection.hpp>
00009 
00010 #include <tk_mkinterface/MKData.hpp>
00011 
00012 #include <telekyb_base/TeleKyb.hpp>
00013 
00014 #include <ros/ros.h>
00015 
00016 using namespace telekyb;
00017 
00018 
00019 
00020 int main(int argc, char **argv) {
00021 
00022 
00023         TeleKyb::init(argc,argv,"mk_test1");
00024 
00025 #ifdef __APPLE__
00026         MKInterfaceConnection* c = new MKInterfaceConnection("/dev/tty.usbserial-A600eG5l");
00027 #else
00028         MKInterfaceConnection* c = new MKInterfaceConnection("/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A600eG5l-if00-port0");
00029 #endif
00030         if (c->isOpen()) {
00031 
00032 
00033                 c->updateValue(MKDataDefines::FIRMWARE_REVISION);
00034 
00035                 MKValue* mkRobotID = c->getMKDataRef().getValueByID(MKDataDefines::ROBOT_ID);
00036                 ROS_INFO("PRE RobotID: %d", mkRobotID->getValue());
00037                 ROS_INFO_STREAM("PRE Time: " << mkRobotID->getStamp().dateTimeToString());
00038 
00039                 c->updateValue(MKDataDefines::ROBOT_ID);
00040 
00041                 ROS_INFO("Post RobotID: %d", mkRobotID->getValue());
00042                 ROS_INFO_STREAM("POST Time: " << mkRobotID->getStamp().dateTimeToString());
00043 
00044 
00045                 MKValue* motorState = c->getMKDataRef().getValueByID(MKDataDefines::MOTOR_STATE);
00046                 c->updateValue(MKDataDefines::MOTOR_STATE);
00047 
00048 
00049                 ROS_INFO("MotorState: %d", motorState->getValue());
00050 
00051                 MotorState state(motorState->getValue());
00052                 ROS_INFO("Current Motorstate: %s, %d", state.str(), state.value());
00053 
00054                 // set Init!
00055                 //motorState->setValue(MotorState::Init);
00056                 //MKSingleValuePacket motorState(MKDataDefines::MOTOR_STATE, MotorState::Init);
00057                 if ( c->setValue(motorState->getMKSingleValuePacketWithValue(MotorState::Init)) ) {
00058                         ROS_INFO("Set Successful!");
00059                 }
00060 
00061                 // update again
00062                 c->updateValue(MKDataDefines::MOTOR_STATE);
00063 
00064                 state = (MotorState)motorState->getValue();
00065                 ROS_INFO("Current Motorstate: %s, %d", state.str(), state.value());
00066 
00067                 sleep(5);
00068 
00069                 if ( c->setValue(motorState->getMKSingleValuePacketWithValue(MotorState::On)) ) {
00070                         ROS_INFO("Set Successful!");
00071                 }
00072 
00073                 sleep(10);
00074 
00075                 // set back
00076                 if ( c->setValue(motorState->getMKSingleValuePacketWithValue(MotorState::Off)) ) {
00077                         ROS_INFO("Set Successful!");
00078                 }
00079 
00080                 // update again
00081                 c->updateValue(MKDataDefines::MOTOR_STATE);
00082 
00083                 state = (MotorState)motorState->getValue();
00084                 ROS_INFO("Current Motorstate: %s, %d", state.str(), state.value());
00085 
00086         }
00087 
00088         delete c;
00089 
00090         TeleKyb::shutdown();
00091 
00092         return EXIT_SUCCESS;
00093 }
00094 
00095 
00096 
00097 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


tk_mkinterface
Author(s): Martin Riedel
autogenerated on Wed Apr 24 2013 11:29:54