-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e061054
Showing
8 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "Arduino.h" | ||
#include "Actuators.h" | ||
|
||
Actuators::Actuators() | ||
{ | ||
|
||
} | ||
|
||
void Actuators::attach_servos(int pwmpin1, int pwmpin2, int pwmpin3, int pwmpin4, int pwmpin5) | ||
{ | ||
servo1.attach(pwmpin1); | ||
servo2.attach(pwmpin2); | ||
servo3.attach(pwmpin3); | ||
servo4.attach(pwmpin4); | ||
servo5.attach(pwmpin5); | ||
} | ||
|
||
void Actuators::control_servo(float angleservo1, float angleservo2, float angleservo3, float angleservo4, float angleservo5) | ||
{ | ||
servo1.write(angleservo1); | ||
servo2.write(angleservo2); | ||
servo3.write(angleservo3); | ||
servo4.write(angleservo4); | ||
servo5.write(angleservo5); | ||
} | ||
|
||
void Actuators::control_servo(float angleservo1, float angleservo2, float angleservo3, float angleservo4) | ||
{ | ||
servo1.write(angleservo1); | ||
servo2.write(angleservo2); | ||
servo3.write(angleservo3); | ||
servo4.write(angleservo4); | ||
} | ||
|
||
void Actuators::control_servo(float angleservo1, float angleservo2, float angleservo3) | ||
{ | ||
servo1.write(angleservo1); | ||
servo2.write(angleservo2); | ||
servo3.write(angleservo3); | ||
} | ||
|
||
void Actuators::control_servo(float angleservo1, float angleservo2 ) | ||
{ | ||
servo1.write(angleservo1); | ||
servo2.write(angleservo2); | ||
} | ||
|
||
void Actuators::control_servo(float angleservo, int number) | ||
{ | ||
switch(number) | ||
{ | ||
case 1: | ||
servo1.write(angleservo); | ||
break; | ||
case 2: | ||
servo1.write(angleservo); | ||
break; | ||
case 3: | ||
servo1.write(angleservo); | ||
break; | ||
case 4: | ||
servo1.write(angleservo); | ||
break; | ||
case 5: | ||
servo1.write(angleservo); | ||
break; | ||
default: | ||
int ac; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef Actuators_h | ||
#define Actuators_h | ||
|
||
#include <Servo.h> | ||
#include "Arduino.h" | ||
|
||
class Actuators | ||
{ | ||
public: | ||
|
||
Servo servo1; | ||
Servo servo2; | ||
Servo servo3; | ||
Servo servo4; | ||
Servo servo5; | ||
|
||
Actuators(); | ||
|
||
void attach_servos(int pwmpin1, int pwmpin2, int pwmpin3, int pwmpin4, int pwmpin5); | ||
|
||
void control_servo(float angleservo1, float angleservo2, float angleservo3, float angleservo4, float angleservo5); | ||
void control_servo(float angleservo1, float angleservo2, float angleservo3, float angleservo4); | ||
void control_servo(float angleservo1, float angleservo2, float angleservo3); | ||
void control_servo(float angleservo1, float angleservo2); | ||
void control_servo(float angleservo, int number); | ||
|
||
private: | ||
|
||
|
||
}; | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# ProstheticHand | ||
firmware for robotics prosthetic limb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "Arduino.h" | ||
#include "sensor.h" | ||
|
||
sensor::sensor() | ||
{ | ||
time1 = 0.00; | ||
time2 = 0.00; | ||
|
||
duration = 0.00; | ||
|
||
lastreading = 0.00; | ||
currentstatus = false; | ||
} | ||
|
||
void sensor::attach_sensor(int spin) | ||
{ | ||
pin = spin; | ||
} | ||
|
||
float sensor::read_sensor() | ||
{ | ||
lastreading = analogRead(pin); | ||
return lastreading; | ||
} | ||
|
||
void sensor::set_reference(float ref) | ||
{ | ||
reference = ref; | ||
} | ||
|
||
bool sensor::verify_read() | ||
{ | ||
if (lastreading>reference) | ||
return true; | ||
else | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/************************************ | ||
Header file for sensors, includes | ||
function for any sensor (analog) | ||
functioning. Create an instance | ||
of this for one sensor. | ||
************************************/ | ||
#ifndef sensor_h | ||
#define sensor_h | ||
|
||
#include "Arduino.h" | ||
|
||
|
||
class sensor | ||
{ | ||
public: | ||
|
||
int pin; // stores the Analog pin no. for example if sensor is connected to A0 pin then store 0 in this | ||
signed long time1, time2; /* time1 stores the time stamp when sensor crossed the reference value | ||
and time2 stores the time stamp when sensor reading falls from the reference value */ | ||
float duration; // stores the time period when sensor crossed the reference value | ||
float lastreading; // stores the reading of sensor | ||
bool currentstatus; // tells whether the sensor is currently above the reference value or not | ||
float reference; // stores the reference value | ||
|
||
sensor(); // construtor to initialize the above variables | ||
|
||
void attach_sensor(int spin); // function to pass the pin on which the sensor is connected | ||
float read_sensor(); // function to read the sensor and return the value | ||
void set_reference(float ref); // function to set the reference value | ||
bool verify_read(); // function returns a boolean value by asssessing the current status of sensor (reference value) | ||
|
||
private: | ||
|
||
}; | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "Arduino.h" | ||
#include "sensorprocessing.h" | ||
|
||
|
||
sensorprocessing::sensorprocessing() | ||
{ | ||
} | ||
|
||
// function that reads the current reading off all sensors that are passed as argument | ||
|
||
void sensorprocessing::reading(sensor all[], int size) // all is sensor type array containing instances of sensor class and size is the no. of instances stored in that array | ||
{ | ||
for(int i=0; i<size; i++) | ||
{ | ||
all[i].read_sensor(); | ||
} | ||
} | ||
|
||
// function determines the last ACTIVE (sensor reading more than refernce value) duration of sensors | ||
|
||
void sensorprocessing::sensoring(sensor all[], int size) // all is sensor type array containing instances of sensor class and size is the no. of instances stored in that array | ||
{ | ||
unsigned long t1; | ||
bool verify; | ||
t1 = millis(); // millis() is a predefined function in Arduino that tells the program current time stamp | ||
reading(all,size); // call to reading() to get the current sensor value | ||
|
||
for (int i = 0; i < size; i++) // loop to determine the ACTIVE duration of all sensors that are passeed in all[] array | ||
{ | ||
|
||
verify = all[i].verify_read(); // returns the current ACTIVE status of the particular sensor (TRUE or FALSE) | ||
|
||
if(all[i].currentstatus == false && verify == true) // checks for RISING EDGE by checking their last status and current verify value | ||
{ | ||
all[i].time1 = t1; | ||
all[i].time2 = 0; | ||
} | ||
|
||
if(all[i].currentstatus == true && verify == false) // checks for FALLING EDGE | ||
{ | ||
all[i].time2 = t1; | ||
} | ||
|
||
if(all[i].currentstatus == false && verify == false) // checks for sensor is currently in INACTIVE mode | ||
{ | ||
|
||
} | ||
|
||
if(all[i].currentstatus == true && verify == true) // checks for sensor is currently in ACTIVE mode | ||
{ | ||
all[i].time2 = t1; | ||
} | ||
|
||
all[i].currentstatus=verify; // storing the verify value back into currentstatus variable | ||
|
||
|
||
if((all[i].time2 - all[i].time1)>0) // calcuating the duration | ||
all[i].duration = all[i].time2 - all[i].time1; | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/************************************ | ||
Header file for processing the sensors, | ||
includes the sensor header file. It | ||
caters to as many sensor instances in | ||
form of array which are passed as argument. | ||
Create an instance to use it. | ||
************************************/ | ||
#ifndef sensorprocessing_h | ||
#define sensorprocessing_h | ||
|
||
#include "Arduino.h" | ||
#include "sensor.h" | ||
|
||
class sensorprocessing | ||
{ | ||
public: | ||
|
||
sensorprocessing(); | ||
void reading(sensor all[], int size); // function that reads the current reading off all sensors that are passed as argument | ||
void sensoring(sensor all[], int size); // function determines the last ACTIVE (sensor reading more than refernce value) duration of sensors | ||
|
||
private: | ||
|
||
|
||
}; | ||
|
||
#endif | ||
|