Conscience Core
CscServoInterface.h
Go to the documentation of this file.
1 //
2 // CscEncoderRs.h
3 // ConscienceRobotManager
4 //
5 // Created by Conscience_Victor on 31/03/2020.
6 // Copyright © 2020 IliesZaoui. All rights reserved.
7 //
8 
9 #ifndef CscServoInterface_h
10 #define CscServoInterface_h
11 
12 #include <CscCommon.h>
13 #include "CoreObjects/CscState.h"
14 #include <chrono>
15 #include <thread>
16 
17 #define FileDesc int
18 
19 using std::vector, std::string, std::thread;
20 namespace this_thread = std::this_thread;
21 
23 private:
24  inline static CscServoInterface* instance = nullptr;
25 
26  bool activated;
27 
28  float currentMotorsAngles[2] = {0,0};
29  float requestedMotorsAngles[2] = {0,0};
30  thread *updateStatusAndProcessActionThread = nullptr;
31  void refreshMotorsAngles();
32  int nbMotors = 2;
33 
34  bool moto0Moving = false;
35  bool moto1Moving = false;
36 
37  char calculateCheckSum(signed char buffer[8]);
38  float degToRad(float x);
39  float shortestSignedDistanceBetweenTwoAngles(float currentAngle, float targetAngle);
40 public:
41 
42  explicit CscServoInterface();
43  bool setupSerialStream(FileDesc &fd,const char * portName);
44 
45  void writePelcoPMessage(int movement, float deltaAngleMotor0, float deltaAngleMotor1);
46  void processUnitSample();
47 
48  int processResultToRs(CscState * state);
49 
50  bool writeToRs(const char * buffer, unsigned int buf_size);
51 
52  bool isActivated();
53 
54  void closeSerial();
55 
56  virtual ~CscServoInterface();
57 
60  void activate(const char* rsPortName);
61  void disactivate();
62 
63  void reachMotorsAngles(float directionValues[2]);
64  int updateRequestedMotorsAngles(float motor0Speed, float motor1Speed);
65 
66  void stopAllMovments();
67 
68  const char * rsPortName;
69  int rsFd;
70 
72  if (instance != NULL ) {
73  return instance;
74  }
75  return (instance = new CscServoInterface());
76  }
77 
78  float getMotoValInPercent(int motorId);
79 
80  void emergencyStop();
81  void writeSerialMessage(int motor, int targetAngleMotor);
82 };
83 
84 #endif /* CscServoInterface_h */
CscServoInterface::processUnitSample
void processUnitSample()
Definition: CscServoInterface.cpp:362
CscServoInterface::writeToRs
bool writeToRs(const char *buffer, unsigned int buf_size)
Definition: CscServoInterface.cpp:414
CscServoInterface::getMotoValInPercent
float getMotoValInPercent(int motorId)
Definition: CscServoInterface.cpp:305
CscServoInterface::isActivated
bool isActivated()
Definition: CscServoInterface.cpp:419
CscServoInterface::disactivate
void disactivate()
Definition: CscServoInterface.cpp:242
CscServoInterface::rsFd
int rsFd
Definition: CscServoInterface.h:69
CscServoInterface::emergencyStop
void emergencyStop()
Definition: CscServoInterface.cpp:229
CscServoInterface::rsPortName
const char * rsPortName
Definition: CscServoInterface.h:68
CscServoInterface::writePelcoPMessage
void writePelcoPMessage(int movement, float deltaAngleMotor0, float deltaAngleMotor1)
Definition: CscServoInterface.cpp:112
CscServoInterface::writeSerialMessage
void writeSerialMessage(int motor, int targetAngleMotor)
Definition: CscServoInterface.cpp:97
CscServoInterface::processResultToRs
int processResultToRs(CscState *state)
Definition: CscServoInterface.cpp:312
CscServoInterface::setupSerialStream
bool setupSerialStream(FileDesc &fd, const char *portName)
Definition: CscServoInterface.cpp:254
CscServoInterface
Definition: CscServoInterface.h:22
FileDesc
#define FileDesc
Definition: CscServoInterface.h:17
CscServoInterface::~CscServoInterface
virtual ~CscServoInterface()
Definition: CscServoInterface.cpp:427
CscServoInterface::stopAllMovments
void stopAllMovments()
Definition: CscServoInterface.cpp:222
CscState
Definition: CscState.h:24
CscServoInterface::getInstance
static CscServoInterface * getInstance()
Definition: CscServoInterface.h:71
CscServoInterface::activate
void activate(const char *rsPortName)
Definition: CscServoInterface.cpp:233
CscServoInterface::updateStatusAndProcessAction
void updateStatusAndProcessAction()
Definition: CscServoInterface.cpp:63
CscServoInterface::CscServoInterface
CscServoInterface()
Definition: CscServoInterface.cpp:50
CscCommon.h
CscServoInterface::updateRequestedMotorsAngles
int updateRequestedMotorsAngles(float motor0Speed, float motor1Speed)
Definition: CscServoInterface.cpp:350
CscServoInterface::closeSerial
void closeSerial()
Definition: CscServoInterface.cpp:423
CscState.h
CscServoInterface::initUpdateStatusAndProcessActionThread
void initUpdateStatusAndProcessActionThread()
Definition: CscServoInterface.cpp:198
CscServoInterface::reachMotorsAngles
void reachMotorsAngles(float directionValues[2])
Definition: CscServoInterface.cpp:80