{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/track_ctrl/tracking_tests.ipynb 1959 2019-07-10 08:00:15Z depa $\n",
    "import Nice\n",
    "import SharknirDrot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "shdrot = SharknirDrot.DROT.connectWithEndpoint(\"drot\", \"[ALIAS=drot1]\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "shdrot.startDerotationHereStart(Nice.Date.now()+Nice.Time.seconds(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "shdrot.startDerotationHereWait(Nice.Time.seconds(210))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Analysis\n",
    "~~In loading the external trajctory to the MoCon module, the **gear resolution** play an important part.\n",
    "To be clarified. \n",
    "In simulation, derotation on TCS trajectory works, **but** the resolution is different from the real one.~~ \n",
    "THe interplay between **gear resolution** and **samples per segment** play an important part when creating and loading to MoCon module the trajectory profile. Which is the interplay is not clarified.\n",
    "```\n",
    "Exception: ::Basda::MoCon::SegmentLengthUnderrunException: The segment length (3) will be smaller than the allowed minimum segment length (5) to decrease the maximal error deviation. (31.2734). Velocity is 3626051\n",
    "```\n",
    "error thrown by `fitExternalProfile` method in `Profile.cc`\n",
    "\n",
    " - Consider `m_minSamplesPerSegment` hard-coded to `5` in default constructor\n",
    " ```\n",
    " /************************\n",
    "* @brief Constructor\n",
    "*/\n",
    "Basda::MoConModuleProfile::MoConModuleProfile()\n",
    "{\n",
    "//    m_trajectory.reserve(0);\n",
    "    m_maxSamplesPerSegment = 5;\n",
    "    m_minSamplesPerSegment = 5; // <<<\n",
    "    m_faultTolerance = 0;\n",
    "    m_deviation = 0;\n",
    "    m_maxDeviation = 0;\n",
    "}\n",
    "```\n",
    "\n",
    "- From `SharknirDrotServiceWorker.h`\n",
    "```\n",
    "#include <Basda/Mocca/NServiceWorkerCore.h>\n",
    "#include <Basda/Device.h>\n",
    "#include <Sharknir/Drot/SharknirDrotServiceWorkerSkeleton.h>\n",
    "```\n",
    "\n",
    "- Gear resolution is extracted from service CFG file from `PropertyName.h` by `datasheetResolution()` method and  stored in:\n",
    " + `m_resolutionProperty` \n",
    " + `resolution`\n",
    " + `m_stepsPerRad    = (double)resolution / (2.0 * M_PI);`\n",
    " + `m_stepsPerDegree = m_stepsPerRad / DR2D ;`\n",
    " + `ang_step = m_direction * ang_rad * m_stepsPerRad;`\n",
    " + `m_positionSequence.push_back(ang_step);`\n",
    " + `m_device->startExternalProfile(_startDate, m_positionSequence, frequency, samplesPerSegment, faultTolerance, deviceCmdAsyncImpl());`\n",
    " + `NDevice::startExternalProfile` in `NDevice.cc` calls `generateExternalProfile` in the same class\n",
    " + `NDevice::generateExternalProfile` calls 3 methods from `module` class:\n",
    "     - `Basda::MoConModule::calculateTransition`\n",
    "     - `Basda::MoConModule::fitTrajectory`\n",
    "     - `Basda::MoConModule::validateExternalProfile`\n",
    " + `Profile::fitTrajectory` calls `fitExternalProfile` from `Profile` class, which throws\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shdrot.isMoving()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
