File size: 3,018 Bytes
68ce2fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/* -*- 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):	Balazs Vagvolgyi, Simon DiMaio, Anton Deguet
  Created on:	2008-05-23

  (C) Copyright 2008 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 <cisst3DUserInterface/ui3SlaveArm.h>

#include <cisstMultiTask/mtsTaskManager.h>
#include <cisstMultiTask/mtsInterfaceRequired.h>
#include <cisst3DUserInterface/ui3Manager.h>


CMN_IMPLEMENT_SERVICES(ui3SlaveArm)


ui3SlaveArm::ui3SlaveArm(const std::string & name):
    Name(name)
{
}

ui3SlaveArm::~ui3SlaveArm()
{
}


bool ui3SlaveArm::SetInput(mtsDevice * positionDevice, const std::string & positionInterface)
{
    return this->SetInput(positionDevice->GetName(), positionInterface);
}


bool ui3SlaveArm::SetInput(const std::string & positionDevice, const std::string & positionInterface)
{
    if (this->Manager == 0) {
        CMN_LOG_CLASS_INIT_ERROR << "SetInput: can not setup input for master arm \""
                                 << this->Name << "\" before adding it to a ui3Manager"
                                 << std::endl;
        return false;
    }

    // add required interface for master arm to Manager
    mtsInterfaceRequired * requiredInterface;

    // setup master arm required interface 
    requiredInterface = this->Manager->AddInterfaceRequired(this->Name);
    if (requiredInterface) {
        // bound the mtsFunction to the command provided by the interface 
        requiredInterface->AddFunction("measured_cp", this->GetCartesianPositionFunction, MTS_REQUIRED);
    } else {
        CMN_LOG_CLASS_INIT_ERROR << "SetInput: failed to add \""
                                 << this->Name
                                 << "\" interface, are you trying to set this arm twice?"
                                 << std::endl;
        return false;
    }
    // connect the master device to the master required interface
    this->Manager->ComponentManager->Connect(this->Manager->GetName(), this->Name,
                                             positionDevice, positionInterface);
    return true;
}


bool ui3SlaveArm::SetTransformation(const vctFrm3 & transformation,
                                     double scale)
{
    // keep the transformation and scale
    this->Transformation.Assign(transformation);
    this->Scale = scale;
    return true;
}


void ui3SlaveArm::GetCartesianPosition(prmPositionCartesianGet & position)
{
    vctFrm3 temporary;
    this->GetCartesianPositionFunction(position);
    this->Transformation.ApplyTo(position.Position(), temporary);
    position.Position().Assign(temporary);
    position.Position().Translation().Multiply(this->Scale);
}