Guest User

Untitled

a guest
Feb 1st, 2018
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.52 KB | None | 0 0
  1.  
  2. /***********************************************************
  3. File name: AdeeptArmDrive.ino
  4. Description:
  5. After the robotic arm is powered on, you can control it by two methods:
  6. 1)By potentiometers on the Arm Drive board
  7. You can rotate the 4 potentiometers on the Adeept Arm Drive board to make the arm turn left/right, move up/down and forward/backward, and grab objects.
  8. 2)By remote control
  9. Pull the left stick to the left and the robotic arm will turn clockwise in a range of 0-180 degrees; push it to the right, the arm will turn counterclockwise in the same range.
  10. Push the left stick forward and the arm will stretch forward; pull it backward, the arm will retract back.
  11. Push forward the stick on the right, the arm will reach up; pull it backward, the arm will draw back.
  12. Push the right stick to the left, the arm will pinch the grippers; pull it to the right, the grippers will open.
  13. Website: www.adeept.com
  14. Author: Tom
  15. Date: 2017/06/06
  16. ***********************************************************/
  17. #include <SPI.h>
  18. #include "RF24.h"
  19. #include <Servo.h>
  20.  
  21. RF24 radio(8, 10); // define the object to control NRF24L01
  22. byte addresses[5] = "00006"; // define communication address which should correspond to remote control
  23. int data[9]={512, 512, 0, 0, 1, 1, 512, 512, 512}; // define array used to save the communication data
  24. int mode[1];
  25.  
  26. Servo servo1;//create servo object to control a servo
  27. Servo servo2;//create servo object to control a servo
  28. Servo servo3;//create servo object to control a servo
  29. Servo servo4;//create servo object to control a servo
  30.  
  31.  
  32. //The following can be modified according to your specific needs
  33. int dataServo1 = 90; // Servo 1 rotation range(dataServo1=15~165)
  34. int dataServo2 = 45; // Servo 2 rotation range(dataServo2=15~75)
  35. int dataServo3 = 60; // Servo 3 rotation range(dataServo3=15~110)
  36. int dataServo4 = 0; // Servo 4 rotation range(dataServo4= 0~50)
  37.  
  38.  
  39. float dirServo1Offset = 0; // define a variable for deviation(degree) of the servo
  40. float dirServo2Offset = 0; // define a variable for deviation(degree) of the servo
  41. float dirServo3Offset = 0; // define a variable for deviation(degree) of the servo
  42. float dirServo4Offset = 0; // define a variable for deviation(degree) of the servo
  43.  
  44. int automatic = 0;
  45.  
  46. int val1;
  47. int val2;
  48. int val3;
  49. int val4;
  50. int motorPin = 7; // define pin for motor
  51.  
  52. void setup()
  53. {
  54. servo1.attach(9);//attachs the servo on pin 5 to servo object
  55. servo2.attach(6);//attachs the servo on pin 5 to servo object
  56. servo3.attach(5);//attachs the servo on pin 9 to servo object
  57. servo4.attach(3);//attachs the servo on pin 10 to servo object
  58.  
  59. radio.begin(); // initialize RF24
  60. radio.setRetries(0, 15); // set retries times
  61. radio.setPALevel(RF24_PA_LOW); // set power
  62. radio.openReadingPipe(1, addresses);// open delivery channel
  63. radio.startListening(); // start monitoring
  64. pinMode(motorPin, OUTPUT); // set buzzerPin to output mode
  65. }
  66.  
  67. void loop()
  68. {
  69. servo1.write(dataServo1+dirServo1Offset);//goes to dataServo1 degrees
  70. servo2.write(dataServo2+dirServo2Offset);//goes to dataServo2 degrees
  71. servo3.write(dataServo3+dirServo3Offset);//goes to dataServo3 degrees
  72. servo4.write(dataServo4+dirServo4Offset);//goes to dataServo4 degrees
  73. receiveData();
  74. if(automatic == 0){ //Operating mode 1: Potentiometer control on the drive board
  75. mode[0]=0;
  76. val1 = map(analogRead(0), 0, 1023, 15, 165);
  77. val2 = map(analogRead(1), 0, 1023, 15, 75);
  78. val3 = map(analogRead(2), 0, 1023, 15, 110);
  79. val4 = map(analogRead(3), 0, 1000, 0, 50);
  80. }
  81. if(automatic == 1){//Operating mode 2: Remote control
  82. mode[0]=1;
  83. if(data[0]<300){val1++;if(val1>=165){val1=165;}}//Control the arm turn right(Servo1)
  84. if(data[0]>600){val1--;if(val1<=15){val1=15;}} //Control the arm turn left(Servo1)
  85.  
  86. if(data[1]>600){val3++;if(val3>=110){val3=110;}}//Control the movement of the arm forward(Servo3)
  87. if(data[1]<300){val3--;if(val3<=15){val3=15;}} //Control the arm to move backwards(Servo3)
  88.  
  89. if(data[8]>600){val4++;if(val4>=50){val4=50;}} //The control the arm(Servo4)
  90. if(data[8]<300){val4--;if(val4<1){val4=0;}} //The control the arm (Servo4)
  91.  
  92. if(data[7]<300){val2++;if(val2>=75){val2=75;}} //The control the arm moves downward(Servo2)
  93. if(data[7]>600){val2--;if(val2<=15){val2=15;}} //The control the arm moves upward(Servo2)
  94. }
  95. if(dataServo1>val1){dataServo1--; }
  96. if(dataServo1<val1){dataServo1++; }
  97. if(dataServo1>165) {dataServo1=165;}
  98. if(dataServo1<15) {dataServo1=15; }
  99.  
  100. if(dataServo2>val2){dataServo2--; }
  101. if(dataServo2<val2){dataServo2++; }
  102. if(dataServo2>75) {dataServo2=75;}
  103. if(dataServo2<15) {dataServo2=15;}
  104.  
  105. if(dataServo3>val3){dataServo3--; }
  106. if(dataServo3<val3){dataServo3++; }
  107. if(dataServo3>110){dataServo3=110;}
  108. if(dataServo3<15) {dataServo3=15; }
  109.  
  110. if(dataServo4>val4){dataServo4--; }
  111. if(dataServo4<val4){dataServo4++; }
  112. if(dataServo4>50) {dataServo4=50;}
  113. if(dataServo4<1) {dataServo4=0; }
  114.  
  115.  
  116. delay(50);//wait for a second.33
  117.  
  118. }
  119. void receiveData(){
  120. if ( radio.available()) { // if receive the data
  121. while (radio.available()) { // read all the data
  122. radio.read( data, sizeof(data) ); // read data
  123. }
  124. if(!data[3]){automatic = 0;}
  125. if(!data[4]){automatic = 1;}
  126. if(!data[5])// control the motor
  127. digitalWrite(motorPin, LOW);
  128. else
  129. digitalWrite(motorPin, HIGH);
  130.  
  131. }
  132. }
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. /***********************************************************
  143. File name: AdeeptRemoteControl.ino
  144. Description:
  145. After the robotic arm is powered on, you can control it by two methods:
  146. 1)By potentiometers on the Arm Drive board
  147. 2)By remote control
  148. You can switch the status of the arm by the remote control.
  149. The remote control can communicate with the robotic arm, the LED1 on the remote will blink.
  150. Press the button B on the remote, so the robotic arm will be controlled in the first method, and the LED2
  151. lights up when LED3 dims at the same time. Press button C to enter the second mode of control; meanwhile
  152. the LED3 will light up when LED2 will go out.
  153. Website: www.adeept.com
  154. Author: Tom
  155. Date: 2017/06/06
  156. ***********************************************************/
  157. #include <SPI.h>
  158. #include "RF24.h"
  159. RF24 radio(9, 10); // define the object to control NRF24L01
  160. byte addresses[5] = "00006"; // define communication address which should correspond to remote control
  161. int data[9]; // define array used to save the communication data
  162. int mode = 0;
  163. const int pot6Pin = 5; // define R6
  164. const int pot5Pin = 4; // define R1
  165. const int led1Pin = 6; // define pin for LED1 which is close to NRF24L01 and used to indicate the state of NRF24L01
  166. const int led2Pin = 7; // define pin for LED2 which is the mode is displayed in the robotic arm remote control mode
  167. const int led3Pin = 8; // define pin for LED3 which is the mode is displayed in the robotic arm auto mode
  168. const int APin = 2; // define pin for D2
  169. const int BPin = 3; // define pin for D3
  170. const int CPin = 4; // define pin for D4
  171. const int DPin = 5; // define pin for D5
  172.  
  173. const int u1XPin = 0; // define pin for direction X of joystick U1
  174. const int u1YPin = 1; // define pin for direction Y of joystick U1
  175. const int u2XPin = 2; // define pin for direction X of joystick U2
  176. const int u2YPin = 3; // define pin for direction Y of joystick U2
  177.  
  178. void setup() {
  179.  
  180. radio.begin(); // initialize RF24
  181. radio.setRetries(0, 15); // set retries times
  182. radio.setPALevel(RF24_PA_LOW); // set power
  183. radio.openWritingPipe(addresses); // open delivery channel
  184. radio.stopListening(); // stop monitoring
  185. pinMode(led1Pin, OUTPUT); // set led1Pin to output mode
  186. pinMode(led2Pin, OUTPUT); // set led2Pin to output mode
  187. pinMode(led3Pin, OUTPUT); // set led3Pin to output mode
  188. pinMode(APin, INPUT_PULLUP); // set APin to output mode
  189. pinMode(BPin, INPUT_PULLUP); // set BPin to output mode
  190. pinMode(CPin, INPUT_PULLUP); // set CPin to output mode
  191. pinMode(DPin, INPUT_PULLUP); // set DPin to output mode
  192. data[3] = 0;
  193. data[4] = 1;
  194. }
  195.  
  196. void loop() {
  197. // put the values of rocker, switch and potentiometer into the array
  198. data[0] = analogRead(u1XPin);
  199. data[1] = analogRead(u1YPin);
  200. if(digitalRead(APin)==LOW){
  201. delay(100);
  202. data[2] = digitalRead(APin);
  203. }else{
  204. data[2] = HIGH;
  205. }
  206. if( digitalRead(BPin)==LOW){//Switch the working mode
  207. mode = 0;
  208. data[3] = 0;
  209. data[4] = 1;
  210. }
  211. if(digitalRead(CPin)==LOW){//Switch the working mode
  212. mode = 1;
  213. data[3] = 1;
  214. data[4] = 0;
  215. }
  216. data[5] = digitalRead(DPin);
  217. data[6] = analogRead(pot5Pin);
  218. data[7] = analogRead(u2YPin);
  219. data[8] = analogRead(u2XPin);
  220. // send array data. If the sending succeeds, open signal LED
  221. if (radio.write( data, sizeof(data) ))
  222. digitalWrite(led1Pin,HIGH);
  223.  
  224. // delay for a period of time, then turn off the signal LED for next sending
  225. delay(2);
  226. digitalWrite(led1Pin,LOW);
  227.  
  228. if(mode==0){//LED display status
  229. digitalWrite(led2Pin,HIGH);
  230. digitalWrite(led3Pin,LOW);
  231. }
  232. if(mode==1){//LED display status
  233. digitalWrite(led2Pin,LOW);
  234. digitalWrite(led3Pin,HIGH);
  235. }
  236. }
Advertisement
Add Comment
Please, Sign In to add comment