changeset 276:3b91c5d76887 main

Add the pixy command
author Bob Cook <bob@bobcookdev.com>
date Mon, 30 May 2016 19:01:37 -0700
parents bf47051f7919
children 773f6e8a5842
files main/robots/cantool/CanToolApp.cpp main/robots/cantool/CmdPixy.cpp main/robots/cantool/Commands.h main/robots/cantool/jamfile
diffstat 4 files changed, 130 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/main/robots/cantool/CanToolApp.cpp	Sun May 01 14:22:14 2016 -0700
+++ b/main/robots/cantool/CanToolApp.cpp	Mon May 30 19:01:37 2016 -0700
@@ -7,7 +7,7 @@
 //
 //  Application object implementation for demonstrating the CANSocket class.    
 //
-//  Copyright (c) 2011-2014 Bob Cook
+//  Copyright (c) 2011-2016 Bob Cook
 //
 //  Permission is hereby granted, free of charge, to any person obtaining a copy
 //  of this software and associated documentation files (the "Software"), to deal
@@ -72,6 +72,7 @@
     m_commandDispatchTable[ "estop" ] = CommandEStop;
     m_commandDispatchTable[ "gps" ] = CommandGps;
     m_commandDispatchTable[ "listen" ] = CommandListen;
+    m_commandDispatchTable[ "pixy" ] = CommandPixy;
     m_commandDispatchTable[ "sonarfront" ] = CommandSonarFront;
     m_commandDispatchTable[ "speed" ] = CommandSpeed;
     m_commandDispatchTable[ "start" ] = CommandStartPgm;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/robots/cantool/CmdPixy.cpp	Mon May 30 19:01:37 2016 -0700
@@ -0,0 +1,122 @@
+// ----------------------------------------------------------------------------------------
+//
+//  robots/cantool/CmdPixy.cpp
+//    
+//  Bob Cook Development, Robotics Library
+//  http://www.bobcookdev.com/rl/
+//
+//  Command "pixy" implementation.
+//
+//  Copyright (c) 2016 Bob Cook
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a copy
+//  of this software and associated documentation files (the "Software"), to deal
+//  in the Software without restriction, including without limitation the rights
+//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//  copies of the Software, and to permit persons to whom the Software is
+//  furnished to do so, subject to the following conditions:
+//
+//  The above copyright notice and this permission notice shall be included in
+//  all copies or substantial portions of the Software.
+//
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//  THE SOFTWARE.
+//
+// ----------------------------------------------------------------------------------------
+
+#include <iostream>
+
+#include <Poco/Exception.h>
+#include <Poco/NumberFormatter.h>
+#include <Poco/NumberParser.h>
+
+#include "Commands.h"
+
+#include "packages/common/can/can_helpers.h"
+#include "packages/common/can/can_messages.h"
+#include "packages/common/can/can_nodes.h"
+
+#include "packages/linux/can/CANMessage.h"
+#include "packages/linux/can/CANMsgProcessor.h"
+
+// ----------------------------------------------------------------------------------------
+
+static void PrintHelp()
+{
+    std::cerr << "error: pixy [ track | off | grab ]" << std::endl;
+}
+
+// ----------------------------------------------------------------------------------------
+
+static void sendTrackMessage()
+{
+    uint32_t msgid = can_build_message_id( can_node_odr_manager,
+                                           can_node_odr_motion,
+                                           can_dataid_pixy_start_tracking );
+
+    CANMessage::QueueToSend( new CANMessage( msgid ) );
+
+    std::cout << "pixy tracking on" << std::endl;
+}
+
+// ----------------------------------------------------------------------------------------
+
+static void sendOffMessage()
+{
+    uint32_t msgid = can_build_message_id( can_node_odr_manager,
+                                           can_node_odr_motion,
+                                           can_dataid_pixy_stop_tracking );
+
+    CANMessage::QueueToSend( new CANMessage( msgid ) );
+
+    std::cout << "pixy tracking off" << std::endl;
+}
+
+// ----------------------------------------------------------------------------------------
+
+static void sendGrabFrameMessage()
+{
+    uint32_t msgid = can_build_message_id( can_node_odr_manager,
+                                           can_node_odr_motion,
+                                           can_dataid_pixy_grabframe );
+
+    CANMessage::QueueToSend( new CANMessage( msgid ) );
+
+    std::cout << "pixy grab frame" << std::endl;
+}
+
+// ----------------------------------------------------------------------------------------
+
+void CommandPixy( const std::vector< std::string >& args )
+{
+    if ( args.size() != 2 )
+    {
+        PrintHelp();
+        return;
+    }
+
+    if ( args[ 2 ] == "track" )
+    {
+        sendTrackMessage();
+    }
+    else if ( args[ 2 ] == "off" )
+    {
+        sendOffMessage();
+    }
+    else if ( args[ 2 ] == "grab" )
+    {
+        sendGrabFrameMessage();
+    }
+    else
+    {
+        PrintHelp();
+    }
+}
+
+// ----------------------------------------------------------------------------------------
+
--- a/main/robots/cantool/Commands.h	Sun May 01 14:22:14 2016 -0700
+++ b/main/robots/cantool/Commands.h	Mon May 30 19:01:37 2016 -0700
@@ -7,7 +7,7 @@
 //
 //  Command function prototypes.
 //
-//  Copyright (c) 2011-2014 Bob Cook
+//  Copyright (c) 2011-2016 Bob Cook
 //
 //  Permission is hereby granted, free of charge, to any person obtaining a copy
 //  of this software and associated documentation files (the "Software"), to deal
@@ -38,6 +38,8 @@
 
 void CommandListen( const std::vector< std::string >& args );
 
+void CommandPixy( const std::vector< std::string >& args );
+
 void CommandSpeed( const std::vector< std::string >& args );
 void CommandSteer( const std::vector< std::string >& args );
 
--- a/main/robots/cantool/jamfile	Sun May 01 14:22:14 2016 -0700
+++ b/main/robots/cantool/jamfile	Mon May 30 19:01:37 2016 -0700
@@ -5,7 +5,7 @@
 #   Bob Cook Development, Robotics Library
 #   http://www.bobcookdev.com/rl/
 #    
-#   Copyright (c) 2011-2013 Bob Cook
+#   Copyright (c) 2011-2016 Bob Cook
 #
 #   Permission is hereby granted, free of charge, to any person obtaining a copy
 #   of this software and associated documentation files (the "Software"), to deal
@@ -37,8 +37,8 @@
 COMMON_SOURCES = 
     main.cpp
     CanToolApp.cpp
-    CmdEStop.cpp CmdGps.cpp CmdListen.cpp CmdSpeed.cpp CmdSonarFront.cpp CmdSteer.cpp
-    CmdStartPgm.cpp
+    CmdEStop.cpp CmdGps.cpp CmdListen.cpp CmdPixy.cpp CmdSpeed.cpp CmdSonarFront.cpp
+    CmdSteer.cpp CmdStartPgm.cpp
     packages.common.can.pkg
     packages.linux.can.pkg
     ;