Gripper Class
The gripper class controls the servo which is attached to a gripping device which can open or close. Two frequencies for the servo are set which determine the open and close angle for the gripper.
.cpp Code
include <gripper.h>
#include <arduino.h>
#define open_angle 90
# define close_angle 0
gripper :: gripper(unsinged int pin){
m_gripper = new MegaServo;
m_gripper -> attach(pin,800,2200); // The frequencies at which the gripper is open or closed
m_gripper -> write(open_angle);
m_position = 1;
}
void gripper :: open(){
if(m_position)
return;
else{
m_gripper -> write(open_angle);
m_postion = 1;
}
}
void gripper :: close(){
if(!m_position)
return;
else{
m_gripper -> write(close_angle);
m_position = 0;
}
}
.h Code
#include <RangeFinder.h>
#ifndef gripper_h
#define gripper_h
#include <MegaServo.h>
class gripper{
private:
bool m_position; // The position is either on or off
MegaServo*m_gripper; //points to the class MegaServo
public:
gripper(unsigned int pin); //Constructor, pin to which it is attached
void open(); //no return
void close(); //no return
bool isOpen(); //returns what state the gripper is in
};
#endif