File size: 3,960 Bytes
ef17c16 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
/*
Author(s): Anton Deguet
Created on: 2017-12-18
(C) Copyright 2017-2025 Johns Hopkins University (JHU), All Rights Reserved.
--- begin cisst license - do not edit ---
This software is provided "as is" under an open source license, with
no warranty. The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.
--- end cisst license ---
*/
#include <sawIntuitiveResearchKit/mtsDaVinciHeadSensor.h>
#include <cisstMultiTask/mtsInterfaceRequired.h>
#include <cisstMultiTask/mtsInterfaceProvided.h>
CMN_IMPLEMENT_SERVICES_DERIVED_ONEARG(mtsDaVinciHeadSensor, mtsTaskFromSignal, mtsTaskConstructorArg)
mtsDaVinciHeadSensor::mtsDaVinciHeadSensor(const std::string & componentName):
mtsTaskFromSignal(componentName)
{
Init();
}
mtsDaVinciHeadSensor::mtsDaVinciHeadSensor(const mtsTaskConstructorArg & arg):
mtsTaskFromSignal(arg)
{
Init();
}
void mtsDaVinciHeadSensor::Init(void)
{
// default values
mSensors.SetAll(0);
mOperatorPresent = false;
// Robot IO
mtsInterfaceRequired * interfaceRequired = AddInterfaceRequired("head_sensor_turn_off");
if (interfaceRequired) {
interfaceRequired->AddFunction("SetValue", RobotIO.TurnOff);
}
interfaceRequired = AddInterfaceRequired("dv_head_sensor_1");
if (interfaceRequired) {
interfaceRequired->AddEventHandlerWrite(&mtsDaVinciHeadSensor::HeadSensor1EventHandler,
this, "Button");
}
interfaceRequired = AddInterfaceRequired("dv_head_sensor_2");
if (interfaceRequired) {
interfaceRequired->AddEventHandlerWrite(&mtsDaVinciHeadSensor::HeadSensor2EventHandler,
this, "Button");
}
interfaceRequired = AddInterfaceRequired("dv_head_sensor_3");
if (interfaceRequired) {
interfaceRequired->AddEventHandlerWrite(&mtsDaVinciHeadSensor::HeadSensor3EventHandler,
this, "Button");
}
interfaceRequired = AddInterfaceRequired("dv_head_sensor_4");
if (interfaceRequired) {
interfaceRequired->AddEventHandlerWrite(&mtsDaVinciHeadSensor::HeadSensor4EventHandler,
this, "Button");
}
mInterface = AddInterfaceProvided("operator_present");
if (mInterface) {
mInterface->AddEventWrite(MessageEvents.OperatorPresent,
"Button", prmEventButton());
}
}
void mtsDaVinciHeadSensor::Configure(const std::string & CMN_UNUSED(filename))
{
}
void mtsDaVinciHeadSensor::Startup(void)
{
RobotIO.TurnOff(false);
}
void mtsDaVinciHeadSensor::Run(void)
{
ProcessQueuedEvents();
ProcessQueuedCommands();
}
void mtsDaVinciHeadSensor::Cleanup(void)
{
RobotIO.TurnOff(true);
}
void mtsDaVinciHeadSensor::HeadSensorEventHandler(const size_t sensorNumber,
const prmEventButton & event)
{
if (event.Type() == prmEventButton::PRESSED) {
mSensors.at(sensorNumber) = 1;
} else {
mSensors.at(sensorNumber) = 0;
}
// for now use a simple test, at least two sensors triggered
const bool operatorPresent = (mSensors.SumOfElements() >= 3);
// nothing has changed, don't do anything
if (mOperatorPresent == operatorPresent) {
return;
}
// changed
prmEventButton payload;
payload.SetValid(true);
payload.SetTimestamp(StateTable.GetTic());
if (operatorPresent) {
payload.SetType(prmEventButton::PRESSED);
MessageEvents.OperatorPresent(payload);
} else {
payload.SetType(prmEventButton::RELEASED);
MessageEvents.OperatorPresent(payload);
}
mOperatorPresent = operatorPresent;
}
|