view main/robots/cantool/CmdPixy.cpp @ 276:3b91c5d76887 main

Add the pixy command
author Bob Cook <bob@bobcookdev.com>
date Mon, 30 May 2016 19:01:37 -0700
parents
children
line wrap: on
line source

// ----------------------------------------------------------------------------------------
//
//  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();
    }
}

// ----------------------------------------------------------------------------------------