background image

                 

                                                             

Spring Model Electronics Co.Ltd

   

TEL

+86-755-2974-9810    FAX

+86-755-2974-9779        www.springrc.com 

v

1.0

 

Page 40 of 49

 

 

5.24 Realize control logic 

 

The realization of servo swing logic 

When we have servo position and speed control function

then we can complete the control 

logic  of  a  servo  swaying    between  two  positions

Here  suppose  the  ID  No.  is  1  for  the  servo 

needs control

the modified main function code is below

 

/**********************************Function Info *********************** 

** (Function Name): 

 

 

 

main 

** 

** (Description):   

 

(Wave the Servo of ID 1) 

** 

** 

** (Input Variable):  

 

 

void   

** (Return Value):   

 

 

 

int 

** 

** (Macro or constant used):   

None 

** (Global variable used): 

 

None 

** 

** (Other function called): 

 

 

None 

** 

** (Author):   

 

 

 

 

robot 

** (Date created):   

 

 

 

2010-3-25 

** 

** (Revised):   

 

 

Summary of Contents for SR518

Page 1: ...Spring Model Electronics Co Ltd TEL 86 755 2974 9810 FAX 86 755 2974 9779 www springrc com v 1 0 Page 1 of 49 SR518 Robot Servo Manual...

Page 2: ...que 18Kgf cm Support wide voltage range DC 6 0V 12V Resolution 0 32 Double sides installation be suitable to install in robot joints High precision all metal gears double bearing Good heal dissipation...

Page 3: ...X 86 755 2974 9779 www springrc com v 1 0 Page 3 of 49 1 2 Diagram 1 3 Electrical connection 1 3 1 Pin Definition The following is the picture of SR518 electrical connection Servos can be tandemed one...

Page 4: ...tion set to open through asynchronous serial interface and the user s PC controller or PC you can set its parameters to change function control Through asynchronous serial interface sends commands SR5...

Page 5: ...18 Model 1 can quickly debug SR5XX series robot servo modify paramenters of function However this method can t work without PC cannot build independent robots configurations You can design a special c...

Page 6: ...is the length of the packet The length is calculated as the number of Parameters N 2 PARAMETER0 N Parameter is used when Instruction requires ancillary data CHECK SUM It is used to check if packet is...

Page 7: ...he standby state without being executed until the ACTION command arrives 0x04 2 or more ACTION This command initiates motions registered with REG WRITE 0x05 0 RESET his command restores the state of S...

Page 8: ...0 0XDB If the read data is 0x20 the current temperature is about32 0x20 2 4 3 REG WRITE REG WRITEinstruction is similar to WRITE DATA just the execution time different When receive the REG WRITE instr...

Page 9: ...ET Function Reset the data in control table to factory value Length 0X02 Instruction 0X06 Parameter Example 4 Reset SR518 ID No is 0 Instruction frame 0XFF 0XFF 0X00 0X02 0X06 0XF7 T head ID Valid dat...

Page 10: ...rite data length and the first address of stored data must be the same that mutiple SR518s must execute the same actions Example5 write position and speed for 4 SR518s below ID0 position 0X010 speed 0...

Page 11: ...rite 0 0x00 7 0x07 Highest byte of clockwise Angle Limit H read write 0 0x00 8 0x08 Lowest byte of counterclockwise Angle Limit L read write 255 0xFF 9 0x09 Hightest byte of counterclockwise Angle Lim...

Page 12: ...3 Decelerating speed read write 32 36 0x24 Present Position L read 37 0x25 Present Position H read 38 0x26 Present Speed L read 39 0x27 Present Speed H read 40 0x28 Present Load read 41 0x29 Present L...

Page 13: ...0x10 117647 1 115200 0 2 124 34 0x22 57142 9 57600 0 0 794 103 0x67 19230 8 19200 0 0 160 0x05 Set return delay time When SR518 receive an instruction which needs response u can set the time of how l...

Page 14: ...as 1 the LED flickers when Input Voltage Error happened If all that happens at the same time please follow the logic or principle 0x12 Setting unload conditions BIT Function BIT7 0 BIT6 If the bit is...

Page 15: ...R518 is62RPM under Position model the minimum speed is 1 the maximum speed is 0 equivalent to 1023 0x22 0x23 The running accelerating and decelerating speed of servo ACC Dcc range 0 255 0x24 0x2E The...

Page 16: ...anti clockwise Angle restrictions 0x06 0x09 r both set to 0 give a another speed 0x20 0x21 the servo will run turn in motor speed adjustment mode Speed has magnitude and direction control mode are sh...

Page 17: ...80degree Instruction WRITE DATA Address 0X0B Data 0X50 Instruction packet FF FF 00 04 03 0B 50 9D Status packet FF FF 00 02 00 FD State no error Example 4 Set the recommended working voltage range of...

Page 18: ...1 Instruction REG_WRITE Address 0X1E Data 0xFF 0x03 ID 0XFE Instruction ACTION Instruction packet FF FF 02 05 04 1E 00 00 D6 Status packet FF FF 02 02 00 FB Instruction packet FF FF 01 05 04 1E FF 03...

Page 19: ...49 Chapter 5 The development of servo controller based on AVR SCM Single Chip Micyoco 5 1 Schematic diagram In actual use of SR518 you may need to develop your own controller to control the servo Belo...

Page 20: ...ipse development program AVR please refer to the document EclipseForAVR program development The initial goal of this program is to make the servo sway between two locations then by adding code can rea...

Page 21: ...2974 9779 www springrc com v 1 0 Page 21 of 49 In the popup dialog box type Servo Control in Project Name in Project Type listing the item of AVR Cross Target Application Choose Empty Project click N...

Page 22: ...ringrc com v 1 0 Page 22 of 49 Pop up target equipment attribute Settings dialog in MCU Type listing pls choose ATmega128 and type 16000000 in MCU Frequency as below click Finish Return to Eclipse mai...

Page 23: ...TEL 86 755 2974 9810 FAX 86 755 2974 9779 www springrc com v 1 0 Page 23 of 49 Choose File New Source File menu item Construct new source code files as below Pop up setting dialogbox type main c in So...

Page 24: ...com v 1 0 Page 24 of 49 Return to Eclipsemain window main c documents to be automatically added to ServoControl and in editable form Add main function in main c window as below The click start compile...

Page 25: ...1 0 Page 25 of 49 http robot up tech com File Info File Name main c Date Last Modified 2010 3 25 Last Version 1 0 Description Author robot Date Created 2010 3 25 Version 1 0 Description int main void...

Page 26: ...after the program run first we must initialize the UARTO Besides when realizing obstacle avoiding car control logic need to connect two IO quantity sensors to judge obstacles so also needs to initiali...

Page 27: ...rt 0 and port 1 to input mode DDRE _BV PE5 _BV PE4 Set Set general digital I O port 0 and pull up state PORTE _BV PE5 _BV PE4 Duplicate paste the above code to the main c documents before main functio...

Page 28: ...e Global variable used None Other function called None Author robot Date created 2010 3 25 Revised Date Revised void InitUart0 void Set baud rate UCSR0A 0x02 Set to double velocity mode UBRR0H 0 Set m...

Page 29: ...paste the above code to main c documents click keep main c then click recompile procedure u can see the compilation result in Console child window as below 5 23 Add servo control function To realize t...

Page 30: ...ne Author robot Date created 2010 3 25 Revised Date Revised void SendUart0Byte unsigned char data waiting for finishing sending all datas in the Transmit Buffer while UCSR0A 1 UDRE Put the data in the...

Page 31: ...mum limit parameters Here add a SetServoLimit function to set the servo mode when program needs to change the actual operation mode you can invoke this function the code is below Function Info Functio...

Page 32: ...sended unsigned char temp_cw_h 0 unsigned char temp_cw_l 0 unsigned char temp_sum 0 temp variable to save checksum if ccw_limit 1023 temp_ccw 1023 limit the velocity to 0 1023 else temp_ccw ccw_limit...

Page 33: ...rt0Byte temp_ccw_l Send the low byte of counterclockwise position limit SendUart0Byte temp_ccw_h Send the low byte of counterclockwise position limit temp_sum id 7 0x03 0x06 temp_cw_l temp_cw_h temp_c...

Page 34: ...mand through UART0 code is below Function Info Function Name SetServoPosition Description Set servo postion Input Variable unsigned char id unsigned short int position signed short int velocity Return...

Page 35: ...unsigned char temp_position_h 0 unsigned char temp_position_l 0 unsigned char temp_sum 0 temp variable to save checksum if velocity 1023 temp_velocity 1023 limit the velocity to 0 1023 else temp_velo...

Page 36: ...velocity SendUart0Byte temp_position_h Send the high byte of velocity SendUart0Byte temp_velocity_l Send the low byte of position SendUart0Byte temp_velocity_h Send the high byte of position temp_sum...

Page 37: ...ize the sending speed control command through UART0 the code is below Function Info Function Name SetServoVelocity Description Set servo velocity Input Variable unsigned char id signed short int veloc...

Page 38: ...locity velocity if negative get the absolute value temp_sign 1 Set negative flag else temp_velocity velocity temp_sign 0 Set positive flag if temp_velocity 1023 temp_velocity 1023 Limit the velocity t...

Page 39: ...value_h Send the high byte of velocity temp_sum id 5 0x03 0x20 temp_value_l temp_value_h temp_sum temp_sum Calculate the checksum SendUart0Byte temp_sum Send the checksum while UCSR0A 1 TXC0 Waiting f...

Page 40: ...ol function then we can complete the control logic of a servo swaying between two positions Here suppose the ID No is 1 for the servo needs control the modified main function code is below Function In...

Page 41: ...Control the servo of ID 1 to position 1000 with the velocity of 500 _delay_ms 1000 Delay 1 s SetServoPosition 1 200 100 Control the servo of ID 1 to position 200 with thevelocity of 100 Duplicate past...

Page 42: ...nfrared sensor on right must connect to the controller s IO0 the infrared sensor on left must connect to the controller s IO1 To realize the obstacle avoidance you need to check the sensor to judge wh...

Page 43: ...ed None Global variable used None Other function called None Author robot Date created 2010 3 25 Revised Date Revised void GetGpio unsigned char val unsigned char temp_input_value 0 temp_input_value 0...

Page 44: ...5 Revised Date Revised void TurnLeft unsigned short int time SetServoVelocity 1 500 Control the servo of ID 1 to rotate with the velocity of 500 SetServoVelocity 2 500 Control the servo of ID 2 to rot...

Page 45: ...velocity of 500 SetServoVelocity 2 500 Control the servo of ID 2 to rotate with the velocity of 500 SetServoVelocity 3 500 Control the servo of ID 3 to rotate with the velocity of 500 SetServoVelocity...

Page 46: ...locity 4 500 Control the servo of ID 4 to rotate with the velocity of 500 The code of is shown below Function Info Function Name Back Description Back Input Variable unsigned short int time Return Val...

Page 47: ...ption Logic to control the robot escape from hit the obstacle Input Variable void Return Value int Macro or constant used None Global variable used None Other function called None Author robot Date cr...

Page 48: ...00 TurnRight 1000 1s Turn right and delay 1 s break case 2 Back _delay_ms 1000 TurnLeft 1000 break default Forward Go forward in other conditions _delay_ms 200 break Duplicate paste the above code to...

Page 49: ...86 755 2974 9779 www springrc com v 1 0 Page 49 of 49 Appendix A SR518 electric functional block diagram System Voltage 5V Conversion Protection Over heat Over voltage Over load Under voltage H Bridge...

Reviews: