collapse

Welcome!



Welcome to Robot Rebels, an online robot maker community.

Register today to post your projects, ask questions, share knowledge and meet like-minded people from around the world.


The RobotRebel.org Community

Recent Posts

Pages: [1] 2 3 ... 10
1
Tutorials / Servo Calibrator
« Last post by BaldwinK on Today at 10:20:42 AM »
This tool finds the relationship between servo pulse time and rotational angle. A simple brief that uncovered a number of tricky issues.

When constructing any robot that moves, work has to be done to define the movement. If using pulsed servos then this ‘definition’ will likely be in µS and quite specific to the actual motor. Should the motor fail and be replaced, or a second bot made, then the definition will no longer be accurate.

Calibrating each joint in degrees, rather than µS, will remove the need to redo the original work.

So an optical shaft encoder is coupled to the joint ‘axle’ to act as an electronic protractor. Then a rotary switch is used to manually find the mechanical limits of the joint plus a reference point.

Next a Nano runs a series of tests and calculates the three coefficients of a second order polynomial ‘best fit’ curve in the form:

y = ax^2 + bx + c

This relationship can then be used to convert from degrees to µS.

 [ You are not allowed to view attachments ]

The bot under test must be held firmly so that the shaft encoder can be positioned to measure each joint. The test setup shown is simple as it is directly coupled to the servo. Think of R2D2 accessing the Death Star systems.

In many cases the servo may act on the joint indirectly via link rods or cables. It is that joint rotation that we must measure, so special adaptors may be required.

The Process

Firstly with the servo connected to the calibrator tool, the limits are established using an EC11 rotary switch. Results are displayed on screen:

Servo Calibrator
 
PHASE ONE: FIND SERVO LIMITS
 
Rotate and press knob at servo reference = 1360 uS
Rotate right and press knob at servo maximum = 2240 uS
Rotate left and press knob at servo minimum = 570 uS

Next the Nano zeroes the shaft encoder at the reference point and spins the servo to check for a secure mechanical interconnection:

PHASE TWO: SHOW WORKING LIMITS
 
            uS       deg
Min   570    78.45
Max   2240   -75.00
 
Min   570    78.60
Max   2240   -75.00
 
Min   570    78.60
Max   2240   -75.45

Then shaft encoder readings are taken every 100 µS:

PHASE THREE: CALIBRATION
 
uS             deg
570            78.60
670            66.00
770            57.00
870            44.70
970            36.45
1070    26.55
1170    17.25
1270    8.55
1370   -0.30
1470   -9.60
1570   -17.55
1670   -26.70
1770   -34.65
1870   -43.20
1970   -51.45
2070   -60.60
2170   -69.00
2240   -75.15 

And finally the coefficients for µS = a*(deg)^2 + b*(deg) + c are printed:

PHASE FOUR: TRENDLINE COEFFICIENTS
 
a = 0.00976096
b = -11.08201885
c = 1364.44213867

Checking the trendline conversion using -60.60 deg, the result is 2072 µS. 

EC11 Switch

This dual pole rotary switch has a knurled shaft and is detented. In this state both A and B contacts are open. One click of rotation will produce a pattern of closures. Connected to the Nano inputs configured with internal pullup resisters, a 2-bit Gray Code is detected.

If the switch is spun too quickly then pulses will be missed. This is not important as the servo is moved under human control and errors can be corrected. The mechanical switch contacts will bounce so a state machine approach is used with the clocking set to 3mS. At clock time the contacts are inspected and a servo pulse is generated if the refresh time of 40mS has passed.

Direction can be determined from the Gray Code changes and the servo pulse time is incremented or decremented by 20 µS each click.

Pushing down on the switch shaft closes the C contact. Again very noisy from switch bounce and the human finger action. The code waits one second before again interrogating this input.

 [ You are not allowed to view attachments ]

These states are easily coded using the Arduino switchcase structure eg:

  switch (bounce) {           
 
case 0:   
  if (ECB == 0)
  bounce = 1;
  ...
  ...
  break;

  ...

  }                           //end of switchcase bounce

Electronic Protractor

This uses optical sensors and an etched disc to produce a 2-bit Gray Code. Ideally an 8-bit or 10-bit disc could be interrogated just once when it had stopped. My encoder is a precision instrument and cost £10, but for that you only get two bits.

The servo speed of rotation is not too different from the shaft encoder output rate. However, without using interrupts some code changes will be missed. But the problem with using interrupts whilst driving a pulsed servo is the loss of clocking stability. So the servo will twitch. Nick Gammon’s blog delves into the underlying code overhead for push and pop. Even if the ISR immediately returns, the servo will still move about.

The special nature of the Gray Code is that it only changes one bit at a time. So if we are at state 00 and see a change to 01 it moved left, say. Change to 10 and it moved right. See a change to 11 and it must be an error.

Now put that error in context. If the previous rotation was to the left then it likely means we missed a move to the left and could correct for the code error. Mostly we can survive a single missed move and in practice this seems to hold here. Of course the state diagram is a bit more complicated.

 [ You are not allowed to view attachments ]  

The stated accuracy of my encoder is 600 P/R which suggests 0.6 degree increments. But this seems to assume a ‘count’ for each completed 2-bit pattern. In practice the Gray Code changes four times per ‘count’ so it actually can detect a 0.15 degree movement.

Once the shaft is turned, the state machine will eventually synchronise, no matter where it began. Then the shaft is moved to the reference point and the count is zeroed.   

Regression Analysis

I like to paste test results into an Excel spreadsheet and see the data graphed. Excel can also apply a trend line and show the equation.

 [ You are not allowed to view attachments ]

But for this calibration tool the trendline coefficients will be calculated by the Nano.

John Brooks’s blog shows a straight line example which works ok. Most of the servos I have tested showed a slight curve mainly due to the non-linearity of the positioning pot. A second order curve is a better fit.

Now it gets interesting. Fortunately, Dr Vogler at The Math Forum explains in detail how to use least squares quadratic regression. With great care I turned these complex expressions into C++ but still ran into a problem with the results.

Coding exactly the same functions into Excel the ansers were correct and matched the secret trend line coefficients. So what went wrong with the Nano?

It seems that, apart from the Due maybe, Arduino C++ uses only 32-bit floats on the Atmega chip. Code for double and it will be just the same as a float. XP is obviously a 64-bit environment and can handle large numbers with many places of decimal.

Test just one small part of the regression calculation eg: ∑x*∑y*(∑x)^4. Using the values printed out during calibration, Excel might give 3.227565150656 E22.

A 10-digit calculator shows 3.2275539 E22 so decimal accuracy has been lost after eight digits. If asked, the Nano simply shows an overflow in any term with powers above ^2. The numbers get huge.

Luckily a work around is available - the x and y values must be pre-scaled!
Divide each down by 10000 and the calculation becomes much more manageable. Of course at the end the coefficients must be re-scaled to get back to µS and degrees.

Demonstration

The video shows a 3-motor leg module under development. It has protruding 2mm axles for coupling to the calibration tool.

The 9g pitch motor has one direct link to the upper leg segment. The heel motor has two links via a bell crank to move the lower leg segment. If the pitch motor is still, the heel motor can rotate the ankle. If the heel motor is still and the pitch motor turns, then the heel angle will change and is the sum of both rotations.


The point of the demonstration is this:

•   The pulsed servos were calibrated in degrees.

•   3D Arduino IK equations convert from IKx, IKy and IKw coordinates.

•   Simple x,y,w sequences now generate the gait.

•   The leg moves in practice as designed in theory.

•   Riding height etc can now be changed on the fly.

 [ You are not allowed to view attachments ]

Working with the PCA9685

A few servos can easily be driven using the delayMicroseconds instruction.

For a bot with a dozen or more motors the PCA9685 breakout board offers very convenient connectivity. Pulse times are set via the two-wire i2c bus and the servos will be constantly refreshed by the board.

 [ You are not allowed to view attachments ]

This is a clever re-use of a chip originally designed to control LEDs. But it doesn’t use microseconds for the pulse times so will require conversion of the calibrator results.

First we determine the refresh cycle time, say 20 mS. A prescale value is then set in control register 0xFE. My little ‘scope showed the refresh time to be shorter than expected but it could be tweaked by changing the prescale value.

The chip divides the cycle time into 4096 parts. So if it were exactly 20 mS then each chunk of time would be 4.8828 µS. This is the smallest change that can be made to the pulse time and we will need another float calculation for the conversion.

So it has got messy again! Better to include the PCA9685 in the original calibration process and find a relationship between angle and the number of ‘chunks of time’. Then we can just send whole numbers via the i2c bus.

If you want you can interleave the pulse times or stagger them to avoid power glitches. The simplest approach is to have each pulse start at time 0 and finish after p * dt. We don’t need to know how long that is as long as it is calibrated out.

So the revised process will have the Nano step 20 * dt (about 98 µS) and measure the angles.

 [ You are not allowed to view attachments ]










2
3D Printing / Re: MKS Gen L 1.0
« Last post by jinx on Today at 05:09:27 AM »
but and theres always a but i have a blank screen"

sure you enabled it? does it beep? once confirmed its enabled in firmware and still blank >:D you gonna need to switch leads around  ext1 goes to ext2 and 2 goes to 1,  you gonna need to rotate the leads 180 and cut a notch in the controller headers to fit leads, just like this http://www.robotrebels.org/index.php?topic=838.msg3918#msg3918
BUT before that just confirm firmware...
3
3D Printing / Re: MKS Gen L 1.0
« Last post by Bappi on Today at 03:34:54 AM »
downloaded both drivers installed the ch341ser.exe and

avrdude: 54526 bytes of flash written
avrdude: verifying flash memory against C:\Users\Bappi\AppData\Local\Temp\arduino_build_697288/Marlin.ino.hex:
avrdude: load data flash data from input file C:\Users\Bappi\AppData\Local\Temp\arduino_build_697288/Marlin.ino.hex:
avrdude: input file C:\Users\Bappi\AppData\Local\Temp\arduino_build_697288/Marlin.ino.hex contains 54526 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 6.28s

avrdude: verifying ...
avrdude: 54526 bytes of flash verified

avrdude done.  Thank you.

but and theres always a but i have a blank screen
4
3D Printing / Re: MKS Gen L 1.0
« Last post by jinx on Today at 02:28:17 AM »
 you got these USB driver https://www.ftdichip.com/Drivers/VCP.htm
this for the mega clones
 http://www.wch.cn/download/CH341SER_EXE.html

 grab both just in case! if it still fails after the driver installed have a read of this using an uno as a boot loader  http://www.robotrebels.org/index.php?topic=601.msg2869#msg2869

think my next step would be get another gen l and upload marlin avoid marlin 2 for now,,, grab an uno and follow the bootloader link above  then you have a spare for your second printer  ^-^
5
3D Printing / Re: MKS Gen L 1.0
« Last post by Bappi on May 20, 2019, 07:11:31 PM »
ok  doing what you just asked COMPILED
Sketch uses 54526 bytes (21%) of program storage space. Maximum is 253952 bytes.
Global variables use 2513 bytes (30%) of dynamic memory, leaving 5679 bytes for local variables. Maximum is 8192 bytes.

when uploading
avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM9
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
avrdude: ser_open(): can't set com-state for "\\.\COM9"
avrdude: ser_drain(): read error: The handle is invalid.


avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.


avrdude: stk500v2_ReceiveMessage(): timeout
the selected serial port avrdude: stk500v2_ReceiveMessage(): timeout
 does not exist or your board is not connected
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.
6
3D Printing / Re: MKS Gen L 1.0
« Last post by jinx on May 20, 2019, 03:16:02 PM »
"i set programmer as arv isp."

set that to AVRISP mkII,,,I think you use arv isp if you where using a boot loader or 3rd party device to upload to a raw chip or something, you want need that.

then comment out the the reprap screen  see if it uploads i just tested  A RAMPS it uploaded fine with a fresh win10 and latest arduino EDI :o yea RAMPS thinks it a gen l now!
7
3D Printing / Re: MKS Gen L 1.0
« Last post by Bappi on May 20, 2019, 02:53:00 PM »
Ok i decided to delete all versions of marlin and arduino from my hard drive and start from the beginning. I downloaded arduino 1.8.9-windows  and fresh installed, i then downloaded marlin 1.1.x bugfix and opened this in arduino edited line 1671 reprap discount full graphic smart controller
i then compiled with arduino/genuino mega or mega 2560 on com port 9. i dont know if it makes any difference but i set programmer as arv isp.
It compiled correctly but when i hit upload it failed
results below
Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Bappi\AppData\Local\Temp\arduino_build_239645\sketch\planner.cpp:2697:1: internal compiler error: Segmentation fault

 }

 ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper.exe: fatal error: C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc returned 1 exit status
compilation terminated.
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit status
Using library U8glib at version 1.19.1 in folder: C:\Users\Bappi\Documents\Arduino\libraries\U8glib
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
8
3D Printing / Re: MKS Gen L 1.0
« Last post by jinx on May 20, 2019, 03:31:49 AM »
post a copy of your config.h and config.adv gonna see if i can replicate those errors with my edi... while you waiting just comment out everything to do with the BLtouch probe.... though my gut feeling is you gonna need to flash the bootloader for the mega.. you got and uno laying around or another arduino... and some jumper leads
9
3D Printing / Re: MKS Gen L 1.0
« Last post by Bappi on May 19, 2019, 07:16:21 PM »
i get these errors in red when compiling with marlin 1.1.x on arduino 1.8.9 com 9 with arduino/genuino mega or mega 2560 programmer arduinoisp

C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `GCodeParser::codebits'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `GCodeParser::command_ptr'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `GCodeParser::param'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `GCodeParser::reset()'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `GCodeParser::string_arg'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `GCodeParser::command_letter'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `GCodeParser::codenum'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `GCodeParser::parse(char*)'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `GCodeParser::unknown_command_error()'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `parser'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\parser.cpp.o (symbol from plugin): In function `GCodeParser::codebits':
(.text+0x0): multiple definition of `GCodeParser::value_ptr'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\gcode.cpp.o (symbol from plugin):(.text+0x0): first defined here
HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':
(.text+0x0): multiple definition of `__vector_25'
C:\Users\Bappi\AppData\Local\Temp\arduino_build_585814\sketch\MarlinSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

10
3D Printing / Re: MKS Gen L 1.0
« Last post by Bappi on May 19, 2019, 04:04:47 PM »
no joy on both versions on marlin 1.1.x i got loads of error messages
Pages: [1] 2 3 ... 10

* Search


* Recent Topics

Servo Calibrator by BaldwinK
[Today at 10:20:42 AM]


MKS Gen L 1.0 by jinx
[Today at 05:09:27 AM]


ESP32 "Life is Life" 64x32 flexible P4 RGB LED by jinx
[May 18, 2019, 11:19:44 AM]


Warco HV-4" Rotary Table by jinx
[May 08, 2019, 03:12:58 PM]


Warco WM14 milling machine by jinx
[April 28, 2019, 09:41:40 AM]


MKS GEN L Servo Issue by Reywas
[April 22, 2019, 09:10:08 PM]


Meowth Abandoned by Nemesis
[April 11, 2019, 11:08:00 AM]


Bench Power: Help a rebel out by jinx
[April 03, 2019, 04:20:10 AM]


Just a short intro... by MEgg
[March 18, 2019, 05:49:28 PM]


Yes I am alive! by jinx
[March 10, 2019, 04:38:53 AM]


CZ-1 2.0: problems, calibration and printing, part2 by MEgg
[February 26, 2019, 03:35:15 PM]


Hi, Mushroom glue here. by nschreiber0813
[February 25, 2019, 02:09:13 PM]


Arduino IK by BaldwinK
[February 25, 2019, 05:54:44 AM]


Raspberry Pi / Python eBook - free for the next 11 hours! by MEgg
[February 24, 2019, 09:49:43 AM]


Fun Fact by Impala
[February 13, 2019, 11:05:01 PM]

* Recent Posts

Servo Calibrator by BaldwinK
[Today at 10:20:42 AM]


Re: MKS Gen L 1.0 by jinx
[Today at 05:09:27 AM]


Re: MKS Gen L 1.0 by Bappi
[Today at 03:34:54 AM]


Re: MKS Gen L 1.0 by jinx
[Today at 02:28:17 AM]


Re: MKS Gen L 1.0 by Bappi
[May 20, 2019, 07:11:31 PM]


Re: MKS Gen L 1.0 by jinx
[May 20, 2019, 03:16:02 PM]


Re: MKS Gen L 1.0 by Bappi
[May 20, 2019, 02:53:00 PM]


Re: MKS Gen L 1.0 by jinx
[May 20, 2019, 03:31:49 AM]


Re: MKS Gen L 1.0 by Bappi
[May 19, 2019, 07:16:21 PM]


Re: MKS Gen L 1.0 by Bappi
[May 19, 2019, 04:04:47 PM]


Re: MKS Gen L 1.0 by jinx
[May 19, 2019, 08:50:41 AM]


Re: MKS Gen L 1.0 by Bappi
[May 18, 2019, 04:38:59 PM]


Re: MKS Gen L 1.0 by Bappi
[May 18, 2019, 04:25:37 PM]


Re: MKS Gen L 1.0 by jinx
[May 18, 2019, 04:10:22 PM]


Re: MKS Gen L 1.0 by Bappi
[May 18, 2019, 02:01:41 PM]