Robotic arms are becoming more prevalent and come in the form of an arm built by hobbyists for their personal use to operating theaters where robotic hands provide valuable aid to surgeons. However, many robots are controlled by panels that features joysticks and buttons. Although we acknowledge that joysticks and buttons are good controls, these controls have their issues. One joystick can only control one movement at a time which thus calls for multiple joysticks. This issue also applies to button controls. Moreover, this means that more than one hand are needed to control the arm. In addition, they are usually wired to the robotic arm. Therefore, there is still a need visible need for a machine that follows human instinctive movements. Most robotic arms are controlled by human input devices such as a joystick. Although a joystick is common form of control input, problems arise as the joystick may not be so intuitive. Therefore, there is a need to fill in a niche of a human interface that allows for more precise and intuitive control.
//Transmitter:
#include <SPI.h>//library to communicate with SPI devices
#include <RF24.h>//library for NRF2401 communication
RF24 radio(7, 8);// CE, CSN
const byte rxAddr[6] = "00001";//create a byte array which will represent the address
int sendingdata[6];
const int xPin=2;
const int yPin=3;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setAutoAck(false);
radio.setRetries(15, 15);
radio.openWritingPipe(rxAddr);//set the same address on the receiver side
radio.stopListening(); //sets module as transmitter
delay(50);
}
void loop()
{
int pulseX,pulseY;
int accelerationX,accelerationY;
pulseX=pulseIn(xPin,HIGH);
pulseY=pulseIn(yPin,HIGH);
accelerationX=(pulseX-5050);
accelerationY=(pulseY-5080);
Serial.print("Rolling:");
Serial.print(accelerationX);
Serial.println();
Serial.print("Pitching:");
Serial.print(accelerationY);
Serial.println();
sendingdata[0]=accelerationX;
sendingdata[1]=accelerationY;
radio.write( sendingdata, sizeof(sendingdata) );
}
//Receiver:
#include <SPI.h>
#include <RF24.h>
#include <Servo.h>
Servo myservo1; // create servo object to control a servo1
Servo myservo2; // create servo object to control a servo2
Servo myservo3; // create servo object to control a servo3
int pos = 0; // variable to store the servo
RF24 radio(7, 8);
const byte rxAddr[6] = "00001";
int acceleration[6];
int buttonPin = 5;
void setup()
{
for(int i = 2; i<=4; i++){
pinMode(i,OUTPUT);
}
while (!Serial);
Serial.begin(9600);
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setAutoAck(false);
radio.openReadingPipe(0, rxAddr);
radio.startListening();
myservo1.attach(9); // attaches the servo on pin 9 to the servo1 object
myservo2.attach(10); // attaches the servo on pin 10 to the servo2 object
myservo3.attach(6); // attaches the servo on pin 6 to the servo3 object
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
if (radio.available())
{
bool done = false;
while (!done)
{
// Fetching the data payload
radio.read( acceleration, sizeof(acceleration) );
done = true;
int val0=map(acceleration[0],0,1024,0,180);
int val1=map(acceleration[1],0,1024,0,180);
if (val0<-135) {
myservo1.write(165); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
if (val1<-110) {
myservo2.write(130); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
else {
myservo2.write(95); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
else if (val0>135) {
myservo1.write(8); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
if (val1<-110) {
myservo2.write(130); // tell servo to go to position in variable 'pos'
delay(100); // waits 100ms for the servo to reach the position
} // waits...
Read more »