Ignore:
Timestamp:
12/12/01 13:26:34 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy/main
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/main/MCosy.cc

    r926 r1111  
    2222//#include <sys/resource.h>  // PRIO_PROCESS
    2323
     24ClassImp(MCosy);
     25
    2426typedef struct tm tm_t;
    2527
     
    3234double Rad2SE(double rad)
    3335{
    34     return 16384.0/D2PI*rad;
     36    return 16384.0/k2Pi*rad;
    3537}
    3638
    3739double Rad2ZdRE(double rad)
    3840{
    39     return 16384.0/D2PI*rad*kGearRatio.X();
     41    return 16384.0/k2Pi*rad*kGearRatio.X();
    4042}
    4143
    4244double Rad2AzRE(double rad)
    4345{
    44     return 16384.0/D2PI*rad*kGearRatio.Y();
     46    return 16384.0/k2Pi*rad*kGearRatio.Y();
    4547}
    4648
     
    6870
    6971    ZdAz source = src * 360.0/16384.0;
    70     ZdAz dest   = dst * 360.0/D2PI;
     72    ZdAz dest   = dst * kRad2Deg;
    7173
    7274    if (dest.Zd()>-1e-6 && dest.Zd()<1e-6)
    73         return dst*(16384.0/D2PI);
     75        return dst*(16384.0/k2Pi);
    7476
    7577    const float fZdMin = -67;
     
    122124}
    123125
    124 
     126// --------------------------------------------------------------------------
     127//
     128//  GetSePos, reads the Shaftencoder positions from the Can-drivers
     129//  for the shaftencoders. The two shaft encoders at the elevation axis
     130//  are avaraged. The values are returned as a ZdAz object.
     131//
     132//  The positions are alway up-to-date because the shaftencoders are
     133//  sending all changes immediatly.
     134//
    125135ZdAz MCosy::GetSePos()
    126136{
     137    //
     138    // Get the values
     139    //
    127140    const int p0 = fZd1->GetPos();
    128141    const int p1 = fZd2->GetPos();
     
    144157}
    145158
     159// --------------------------------------------------------------------------
     160//
     161// request the current positions from the rotary encoders.
     162// use GetRePos to get the psotions. If the request fails the function
     163// returns kFALSE, otherwise kTRUE
     164//
     165Bool_t MCosy::RequestRePos()
     166{
     167    //
     168    // Send request
     169    //
     170    fMac2->RequestSDO(0x6004);
     171    fMac1->RequestSDO(0x6004);
     172
     173    //
     174    // Wait until the objects are received.
     175    //
     176    WaitForSdos();
     177
     178    //
     179    // If waitng was not interrupted everything is ok. return.
     180    //
     181    if (!StopWaitingForSDO())
     182        return kTRUE;
     183
     184    //
     185    // If the waiting was interrupted due to a network error,
     186    // print some logging message.
     187    //
     188    if (HasError())
     189        lout << "Error #6004 (requesting re pos from Macs) happened." << endl;
     190
     191    return kFALSE;
     192}
     193
     194// --------------------------------------------------------------------------
     195//
     196//  reads the Rotary encoder positions from the last request of the Macs.
     197//
     198//  The positions are returned as a ZdAz object. Use RequestRePos to request
     199//  the current positions first.
     200//
    146201ZdAz MCosy::GetRePos()
    147202{
     
    149204}
    150205
     206// --------------------------------------------------------------------------
     207//
     208//  reads the Rotary encoder positions from the Macs.
     209//
     210//  The positions are returned as a ZdAz object. The positions are the ones
     211//  which are send as PDOs to the computer. This is done at a given
     212//  frequency. Which means, that this positions are not ought to be
     213//  up-to-date.
     214//
    151215ZdAz MCosy::GetRePosPdo()
    152216{
     
    154218}
    155219
     220// --------------------------------------------------------------------------
     221//
     222//  set the velocity and accelerations for position maneuvers.
     223//
     224//  The acceleratin is set as given (in percent of maximum).
     225//  The velocity is given in percent, depending on the ratio (<1 or >1)
     226//  one of the axis becomes a slower velocity. This is used for maneuvers
     227//  in which both axis are moved synchromously and should reach their
     228//  target position at the same time.
     229//
    156230void MCosy::SetPosVelocity(const Float_t ratio, Float_t vel, Float_t acc)
    157231{
     
    186260}
    187261
     262// --------------------------------------------------------------------------
     263//
     264// Does a relative positioning.
     265//
     266// The steps to move are given in a ZdAz object relative to the current
     267// position. The coordinates are given in Roteryencoder steps.
     268// Axis 1 is moved only if axe1==kTRUE, Axis 2 is moved only
     269// if Axis 2==kTRUE. The function waits for the movement to be finished.
     270//
    188271void MCosy::DoRelPos(const ZdAz &rd, const Bool_t axe1, const Bool_t axe2)
    189272{
    190     SetStatus(kMoving);
     273    SetStatus(MCosy::kMoving);
    191274
    192275    if (axe1) fMac2->StartRelPos(rd.Zd());
     
    200283}
    201284
     285// --------------------------------------------------------------------------
     286//
     287// check for a break-signal (from the msgqueue) and errors.
     288//
     289int MCosy::StopWaitingForSDO() const
     290{
     291    return Break() || HasError();
     292}
     293
     294// --------------------------------------------------------------------------
     295//
     296// Waits for a movement to become finished.
     297//
     298// First waits for all peding Sdos, then waits until both motors are stopped
     299// or waiting for SDOs was stopped (either by an error or by Break)
     300//
     301void MCosy::WaitForEndMovement()
     302{
     303    WaitForSdos();
     304
     305    while ((fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO())
     306        usleep(1);
     307}
     308
     309// --------------------------------------------------------------------------
     310//
     311// Check for an error...
     312//
     313// This is ment for usage after the Action: All Motors Stop.
     314//
    202315void MCosy::CheckForError()
    203316{
     317    //
     318    // Check all Can-Nodes for an Error. If there is no error the motor
     319    // status is set to stopped.
     320    //
    204321    if (!HasError())
    205322    {
    206         SetStatus(kStopped);
     323        SetStatus(MCosy::kStopped);
    207324        return;
    208325    }
    209326
    210     SetStatus(kError);
     327    //
     328    // If there is an error, the error status is set to Error.
     329    //
     330    SetStatus(MCosy::kError);
     331
     332    //
     333    // No try to handle the error.
     334    //
    211335    fMac1->HandleError();
    212336    fMac2->HandleError();
     337
     338    //
     339    // If the error couldn't get solved return
     340    //
    213341    if (HasError())
    214342        return;
    215343
    216     SetStatus(kStopped);
    217 }
    218 
     344    //
     345    // Set motor status to stopped
     346    //
     347    SetStatus(MCosy::kStopped);
     348}
     349
     350// --------------------------------------------------------------------------
     351//
     352// Move the telescope to the given position. The position must be given in
     353// a ZdAz object in rad.
     354//
     355// The first positioning is done absolutely. If we didn't reach the
     356// correct psotion we try to correct for this by 10 relative position
     357// maneuvers. If this doesn't help positioning failed.
     358//
     359// As a reference the shaftencoder values are used.
     360//
    219361int MCosy::SetPosition(const ZdAz &dst) // [rad]
    220362{
     
    296438}
    297439
    298 Bool_t MCosy::RequestRePos()
    299 {
    300 
    301     fMac2->RequestSDO(0x6004);
    302     fMac1->RequestSDO(0x6004);
     440// --------------------------------------------------------------------------
     441//
     442// Sets the tracking velocity
     443//
     444// The velocities are given in a ZdAz object in re/min. Return kTRUE
     445// in case of success, kFALSE in case of failure.
     446//
     447Bool_t MCosy::SetVelocity(ZdAz v)
     448{
     449    //
     450    // Send the new velocities for both axes.
     451    //
     452    fMac2->SendSDO(0x3006, 1, (LWORD_t)v.Zd());  // SetRpmVelocity [re/min]
     453    fMac1->SendSDO(0x3006, 1, (LWORD_t)v.Az());  // SetRpmVelocity [re/min]
     454
     455    //
     456    // Wait for the objects to be OKed.
     457    //
    303458    WaitForSdos();
     459
     460    //
     461    // If the waiting for the objects wasn't interrupted return kTRUE
     462    //
    304463    if (!StopWaitingForSDO())
    305464        return kTRUE;
    306465
    307     if (HasError())
    308         lout << "Error #6004 (requesting re pos from Macs) happened." << endl;
    309 
    310     return kFALSE;
    311 }
    312 
    313 Bool_t MCosy::SetVelocity(ZdAz v)
    314 {
    315     fMac2->SendSDO(0x3006, 1, (LWORD_t)v.Zd());  // SetRpmVelocity [re/min]
    316     fMac1->SendSDO(0x3006, 1, (LWORD_t)v.Az());  // SetRpmVelocity [re/min]
    317     WaitForSdos();
    318     if (!StopWaitingForSDO())
    319         return kTRUE;
    320 
     466    //
     467    // print a message if the interruption was due to a Can-node Error
     468    //
    321469    if (HasError())
    322470        lout << "Error #3006 (setting velocity of Macs) happened." << endl;
     
    325473}
    326474
     475// --------------------------------------------------------------------------
     476//
     477// Initializes Tracking mode
     478//
     479// Initializes the accelerations of both axes with 90% of the maximum
     480// acceleration. Set the status for moving and tracking and starts thr
     481// revolution mode.
     482//
    327483void MCosy::InitTracking()
    328484{
     
    336492    fMac1->SetDeceleration(0.90*fMac1->GetVelRes());
    337493
    338     SetStatus(kMoving | kTracking);
     494    SetStatus(MCosy::kMoving | MCosy::kTracking);
    339495
    340496    fMac2->SetRpmMode(TRUE);
     
    342498}
    343499
     500// --------------------------------------------------------------------------
     501//
     502// Limits the speed.
     503//
     504// This function should work as a limiter. If a tracking error is too large
     505// to be corrected fast enough we would get enormous velocities. These
     506// velocities are limited to the maximum velocity.
     507//
    344508void MCosy::LimitSpeed(ZdAz *vt, const ZdAz &vcalc) const
    345509{
     
    527691}
    528692
    529 int MCosy::IsPositioning() const
    530 {
    531     return (fMac1->IsPositioning() || fMac2->IsPositioning()) && !StopWaitingForSDO();
    532 }
    533 
    534 void MCosy::WaitForEndMovement()
    535 {
    536     WaitForSdos();
    537 
    538     while (IsPositioning())
    539         usleep(1);
    540 }
    541 
     693// --------------------------------------------------------------------------
     694//
     695// Stops the movement of both motors.
     696//
     697// Sets the status to stopping. Sets the deceleration to 50% of the maximum.
     698// stops. Quits the revolution mode and wait for the end of the movement.
     699//
    542700void MCosy::StopMovement()
    543701{
    544     SetStatus(kStopping);
    545 
     702    //
     703    // Set status to stopped
     704    //
     705    SetStatus(MCosy::kStopping);
     706
     707    //
     708    // set deceleration to 50%
     709    //
    546710    cout << "Stopping  positioning..." << endl;
    547711    fMac1->SetDeceleration(0.5*fMac1->GetVelRes());
    548712    fMac2->SetDeceleration(0.5*fMac2->GetVelRes());
    549713
    550     cout << "Stoping possible RPM mode..." << endl;
     714    //
     715    // Stop revolution mode (movement)
     716    //
     717    cout << "Stoping possibleRPM mode..." << endl;
    551718    fMac1->SetRpmMode(FALSE);
    552719    fMac2->SetRpmMode(FALSE);
    553720
     721    //
     722    // Wait for the movement to really be finished.
     723    //
    554724    cout << "Waiting for silence..." << endl;
    555725    WaitForEndMovement();
    556726
     727    //
     728    // Check whether everything works fine.
     729    //
    557730    CheckForError();
    558 
    559731    cout << "Movement stopped." << endl;
    560732}
     
    587759
    588760            RaDec rd(37.94, 89.2644);
    589             ZdAz za=sla.CalcZdAz(rd*D2PI/360.0)*16384.0/D2PI;
     761            ZdAz za=sla.CalcZdAz(rd*kDeg2Rad)*16384.0/k2Pi;
    590762
    591763            cout << "Calc Zd: " << za.Zd() << " Az: " << za.Az() << endl;
     
    607779            ZdAz dest = *((ZdAz*)mp);
    608780
    609             SetPosition(dest*D2PI/360.0);
     781            SetPosition(dest*kDeg2Rad);
    610782        }
    611783        cout << "WM_Position: done. (return 0x7777)" << endl;
     
    616788        {
    617789            RaDec dest = *((RaDec*)mp);
    618             TrackPosition(dest*D2PI/360.0);
     790            TrackPosition(dest*kDeg2Rad);
    619791        }
    620792        cout << "WM_Track: done. (return 0x8888)" << endl;
     
    8431015
    8441016
    845 int MCosy::StopWaitingForSDO() const
    846 {
    847     return Break() || HasError();
    848 }
    849 
     1017// --------------------------------------------------------------------------
     1018//
     1019// Start the work of the application:
     1020//
     1021// Start the Can-Network.
     1022// Start the MCosy::TalkThread thread.
     1023// turn on the gui update
     1024//
    8501025void MCosy::Start()
    8511026{
     
    8611036}
    8621037
     1038// --------------------------------------------------------------------------
     1039//
     1040// Start the work of the application:
     1041//
     1042// Turn of the gui update
     1043// stop the MCosy::TalkThread thread.
     1044// Stop the network
     1045//
    8631046void MCosy::Stop()
    8641047{
  • trunk/MagicSoft/Cosy/main/MCosy.h

    r926 r1111  
    3737};
    3838
    39 #define kError     0x01
    40 #define kMoving    0x02
    41 #define kTracking  0x04
    42 #define kStopping  0x08
    43 #define kStopped   0x10
    4439
    4540class TTimer;
     
    5045
    5146private:
     47    enum
     48    {
     49        kError    = 0x01,
     50        kMoving   = 0x02,
     51        kTracking = 0x04,
     52        kStopping = 0x08,
     53        kStopped  = 0x10
     54    };
     55
    5256    ShaftEncoder *fZd1;
    5357    ShaftEncoder *fZd2;
     
    99103
    100104    int StopWaitingForSDO() const;
    101     int IsPositioning() const;
    102105    void CheckForError();
    103106
     
    117120
    118121    static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst);
    119 //    static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));
     122    //    static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));
    120123
     124    ClassDef(MCosy, 0)
    121125};
    122126
  • trunk/MagicSoft/Cosy/main/MainLinkDef.h

    r924 r1111  
    55#pragma link off all functions;
    66
     7#pragma link C++ class MCosy;
     8
    79#endif
  • trunk/MagicSoft/Cosy/main/Makefile

    r924 r1111  
    3535           MStarguider.cc
    3636
    37 SRCS    = $(SRCFILES)
    38 HEADERS = $(SRCFILES:.cc=.h)
    39 OBJS    = $(SRCFILES:.cc=.o)
     37SRCS        = $(SRCFILES)
     38HEADERS     = $(SRCFILES:.cc=.h)
     39OBJS        = $(SRCFILES:.cc=.o)
     40CINTHEADERS = $(HEADERS)
    4041
    4142############################################################
Note: See TracChangeset for help on using the changeset viewer.