Advertisement
Guest User

Untitled

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