RoboAide
Project to improve a DIY robotic arm used for mobility assistance
axialMotor.h
Go to the documentation of this file.
1 
2 class axialMotor
3 {
4  public:
5  axialMotor(int enAPin, int motorInitialState,int pinCWOutputValue, int pinCCWOutputValue, int ProxSensor1Value,int ProxSensor2Value);
6  axialMotor();
7  bool shouldSlowDown();
8  bool runAxialCalibration();
9  void setMotorState(int stateValue);
10  void setEnableDrive(bool driveValue);
11  int getMotorState();
12  int getDriveState();
13  int getProximitySensorPin(bool sensorNumber);
14  int getProximitySensorValue(bool sensorNumber);
15  int getMotorPin(int directionNumber);
16  int getDrivePin();
17 
18  private:
20  int enAPin; //digital pin for enabling the motor control
21  int pinCWOutput; //Pin for CW control (#1)
22  int pinCCWOutput; //Pin for CCW control (#2)
23  int proximitySensor1Pin; //Connected pin for sensor #1
24  int proximitySensor2Pin; //Connected pin for sensor #2s
25 };
26 
32 axialMotor::axialMotor(int enAPinValue, int motorInitialState,int pinCWOutputValue, int pinCCWOutputValue, int ProxSensor1Value,int ProxSensor2Value)
33 {
34  motorState = motorInitialState;
35  //setMotorState(motorState);
36  enAPin = enAPinValue;
37  pinCWOutput = pinCWOutputValue;
38  pinCCWOutput = pinCCWOutputValue;
39  proximitySensor1Pin = ProxSensor1Value;
40  proximitySensor2Pin = ProxSensor2Value;
41 
42 }
43 
47 {
48  motorState = -1;
49  //setMotorState(motorState);
50  enAPin = 45;
51  pinCWOutput = 47;
52  pinCCWOutput = 49;
55 }
56 
61 {
62  int proximitySensor1Reading = digitalRead(getProximitySensorPin(1)); //defines the input to pins #51. The input is HIGH when nothing is capted this is the top sensor
63  //Serial.print("la valeur de proximite est de :");
64  //Serial.print(proximitySensor1Reading);
65  if (proximitySensor1Reading == false && getMotorState() == true || getMotorState() == -1)
66  {
67  // Serial.print("Je lis le capteur et le moteur monte");
68  return true;
69  }
70 
71  else if (proximitySensor1Reading == false && getMotorState() == false)
72  {
73  //Serial.print("Je lis le capteur et le moteur DESCEND");
74  return false;
75  }
76  else
77  {
78  return false;
79  }
80  int proximitySensor2Reading = digitalRead(getProximitySensorPin(2)); //defines the input to pin #53. The input is HIGH when nothing is capted
81  //Serial.print("TU ENTRE EN CAPTEUR 2!");
82 
83  if (proximitySensor2Reading == false && getMotorState() == true)
84  {
85  // Serial.print("CAPTEUR 2 UNDER CONSTRUCTION");
86  return false;
87  }
88 
89  else if (proximitySensor2Reading == false && getMotorState() == false || getMotorState() == -1)
90  {
91  // Serial.print("CAPTEUR 2 UNDER CONSTRUCTION");
92  return true;
93  }
94 
95  else
96  {
97  return false;
98  }
99 }
100 
108 {
109  setMotorState(1);
110  //Serial.print("le moteur tourne maintenant");
111  while (shouldSlowDown() == false)
112  {
113  if (shouldSlowDown() == true)
114  {
115  setMotorState(-1);
116  return true;
117  }
118  }
119  return false;
120 
121 }
122 
126 void axialMotor::setMotorState(int stateValue)
127 {
128  //Serial.println("JE PASSE ICI");
129  //Serial.println(stateValue);
130 
131  if (stateValue != -1 && stateValue != 1 && stateValue != 0)
132  {
133  //Serial.println("MAUVAISE ENTRÉE, MAINTENANT MOTORSTATE SERA DE :");
134 
135  stateValue = -1; //doesn't move the motor
136  }
137  //Serial.println("STATE VALUE correct");
138  motorState = stateValue; //Sets the motor value to the new direction value.
139 
140  if (motorState == 1) //Changes the motor rotation by changing output pin value.
141  {
142  //Serial.println("ICI SI LE STATE VALUE EST DE 1");
143 
144  digitalWrite(getMotorPin(1),HIGH);
145  digitalWrite(getMotorPin(2),LOW);
146  //Serial.print(digitalRead(getMotorPin(1)));
147  //Serial.print(digitalRead(getMotorPin(2)));
148  }
149 
150  else if (motorState == 0)
151  {
152  // Serial.println("ICI SI LE STATE VALUE EST DE 0");
153  digitalWrite(getMotorPin(2),HIGH);
154  digitalWrite(getMotorPin(1),LOW);
155  }
156  /* for(int motorValue = 0 ; motorValue <= 255; motorValue +=5) //CECI EST A ADAPTER POUR ANALOG
157  {
158  analogWrite(motorPin, motorValue);
159  delay(30);
160  } */
161 
162  else if (motorState == -1)
163  {
164  // Serial.print("ICI SI LE STATE VALUE EST DE -1");
165  digitalWrite(getMotorPin(2),LOW);
166  digitalWrite(getMotorPin(1),LOW);
167  }
168 }
169 
174 {
175  return motorState;
176 }
177 
182 int axialMotor::getProximitySensorPin(bool sensorNumber)
183 {
184  if (sensorNumber == 1)
185  {
186  return proximitySensor1Pin;
187  }
188 
189  else if (sensorNumber == 2)
190  {
191  return proximitySensor2Pin;
192  }
193 }
194 
200 {
201  if (sensorNumber == 1)
202  {
203  return digitalRead(proximitySensor1Pin);
204  }
205 
206  else if (sensorNumber == 2)
207  {
208  return digitalRead(proximitySensor2Pin);
209  }
210 }
211 
216 int axialMotor::getMotorPin(int directionNumber)
217 {
218  if (directionNumber == 1)
219  {
220  return pinCWOutput;
221  }
222  else if (directionNumber == 2)
223  {
224  return pinCCWOutput;
225  }
226 
227  else
228  {
229  return -1;
230  }
231 }
232 
233 void axialMotor::setEnableDrive(bool driveValue)
234 {
235  if (driveValue == true)
236  {
237  digitalWrite(enAPin,HIGH);
238  }
239  else if (driveValue== false)
240  {
241  digitalWrite(enAPin,LOW);
242  }
243  else
244  {
245  digitalWrite(enAPin,LOW);
246  }
247 }
248 
250 {
251  return digitalRead(enAPin);
252 }
253 
255 {
256  return enAPin;
257 }
int proximitySensor1Pin
Definition: axialMotor.h:23
void setEnableDrive(bool driveValue)
Definition: axialMotor.h:233
int getMotorState()
gets the motor current state.
Definition: axialMotor.h:173
int getDrivePin()
Definition: axialMotor.h:254
int proximitySensor2Pin
Definition: axialMotor.h:24
void setMotorState(int stateValue)
Sets the motor state value to a given value of 0,1 or -1. If the value is not in this range...
Definition: axialMotor.h:126
int getProximitySensorPin(bool sensorNumber)
Gives the proximity sensor pin number on the arduino.
Definition: axialMotor.h:182
int motorState
Definition: axialMotor.h:19
int getProximitySensorValue(bool sensorNumber)
Gives a sensor value. All proximity sensors are pulled up.
Definition: axialMotor.h:199
int enAPin
Definition: axialMotor.h:20
bool shouldSlowDown()
Checks if the requirement to make the motor stop are met. /return bool : value confirming if the moto...
Definition: axialMotor.h:60
int pinCWOutput
Definition: axialMotor.h:21
axialMotor()
Construct the axial motor with no initial states/pinout. Motor state is then set to STOP (-1)...
Definition: axialMotor.h:46
bool runAxialCalibration()
Calibrate the assembly&#39;s vertical axis using the upper proximity sensor.
Definition: axialMotor.h:107
int getMotorPin(int directionNumber)
Gives the chosen motor direction pin.
Definition: axialMotor.h:216
int pinCCWOutput
Definition: axialMotor.h:22
int getDriveState()
Definition: axialMotor.h:249