OpenServo.com Forum Index OpenServo.com
Discussion of the OpenServo project
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Open-Encoder-MG995
Goto page 1, 2, 3, 4, 5, 6, 7, 8  Next
 
Post new topic   Reply to topic    OpenServo.com Forum Index -> Hardware
View previous topic :: View next topic  
Author Message
jharvey
co-admin


Joined: 15 Mar 2009
Posts: 362
Location: Maine USA

PostPosted: Tue Jul 07, 2009 2:26 am    Post subject: Open-Encoder-MG995 Reply with quote

This topic has been talked about in another thread, however, I felt it was OT and really should be brought into a different tread. The prior references can be found in this thread, titled "Question about precision and repeatability".

http://www.openservo.com/forums/viewtopic.php?t=766&postdays=0&postorder=asc&start=45

This thread will discuss Open-Encoder specific to modifying a MG995 servo. Below are some items I'm starting to work on.

-- I expect to get the custom magnets in a couple days. When I get them, I plan to use the OSIF to do basic communications with the device receiving the position. That is only one step of getting this working. For this to really work, we will need this to be integrated with the OSV3 code.

I've ordered several extra magnets. For those that are willing to help in the devel of this encode, I'll offer three to match the 3 samples one can get of the encoder chip.

I plan to glue my first magnets on, later version will use a custom shaft that has a rivet feature on it.

-- I've been looking over the OSV3 code, and I'm not sure what the best general approach is. I'm tempted to push for a separate branch similar to the velocity control code, perhaps an upgraded version of the velocity code. One firmware to rule them all would be nice, that way bugs and such don't have to be addressed multiple times, however that also increases the complications, so perhaps separate firmwares for specific operating features is a good idea.

As for how to implement the software I2C, that's a different beast. I'm still studying the normal firmware, is the timer used for anything? Perhaps that can function as a clock signal. Some key issues I see include figuring out how not to waste time waiting for the I2C commands to come down from the encoder chip.

The encoder is 12 bits, but the position reg can handle 16 bits. That allows for 16 revolutions natively, which should work for my application. An option that would be nice to include, but is unimportant for me right now, would be off loading more bits to the controlling PC software. Such that you can control this like it's a 32 bit device, and have lots of revolutions. That would require more I2C commands and I'm not sure what commands might be handy for this feature. Perhaps that's better done later down the road, but a general game plan now would be nice. You know pigeon hole prevention.

Be warned, software is a weaker skill for me, I generally know enough to be dangerous, I'm fairly bad about generating original code.

-- As for the physical setup, I think we are in good shape. I believe we can reuse the AN POT input PC2 pin, as SDA, then the extra pad that Cliff put in for PD5 as SCL. I choose PD5, because it looks like it might be capable of having a VIA in future versions. The resistors can be taken care of on the Open-Encoder PCB. Power can be tapped from the + and _ of the AN POT circuit.
Back to top
View user's profile Send private message Visit poster's website
jharvey
co-admin


Joined: 15 Mar 2009
Posts: 362
Location: Maine USA

PostPosted: Tue Jul 07, 2009 11:10 pm    Post subject: Reply with quote

I got the magnets, here's a pic



They measure spot on. A size B drill should work just fine for putting the hole in the PCB. Something like McMastercarr part 30595A32 would work, however I've got one and will do that tomorrow. Drills typically over drill slightly so this should be a nice tight fit.

Also I've made a slight update to the MG995 servo mod. I added a note about the .1uF cap, that I failed to install. I choose Tant caps, and posted Newark numbers for these parts. I believe these parts should be good, however it's my stable in the dark. That page is found here.

http://www.openservo.com/ConstructionTutorial_MG995


Last edited by jharvey on Wed Jul 08, 2009 8:11 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Cliff



Joined: 23 Jan 2007
Posts: 150
Location: Saratoga, CA

PostPosted: Wed Jul 08, 2009 5:24 pm    Post subject: Reply with quote

Jared,

You do NOT want to install a tantalum capacitor across the motor leads - they are polarized and will be backwards half of the time (depending on motor direction). Backward tantalum capacitors make great smoke (and some times flame) generators, but I don't think that is what you had in mind. Choose instead a ceramic capacitor, which is not polarized.

Cliff
Back to top
View user's profile Send private message
jharvey
co-admin


Joined: 15 Mar 2009
Posts: 362
Location: Maine USA

PostPosted: Wed Jul 08, 2009 6:28 pm    Post subject: Reply with quote

Errr, what can I say, I like to live dangerously... Good catch.

I just updated the wiki to call for this cap from Newarks, 36K6164 at $.072 in qty 1. 50VDC Ceramic Multilayer Capacitor.
Back to top
View user's profile Send private message Visit poster's website
jharvey
co-admin


Joined: 15 Mar 2009
Posts: 362
Location: Maine USA

PostPosted: Wed Jul 08, 2009 8:03 pm    Post subject: Reply with quote

I've made some progress on the open-encoder. Here's a picture of where it stands now.



The key problem I have at the moment, is that I made a blunder when I made my PCB's. I used a narrow version of the AS5046. So my chip wouldn't work with the PCB I made.

I did the above modifications with a hacked version of a machine shop. I used a file and a vice to first rough in the stud.



Then again at a 45



Eventually I chucked it up in a drill and with the file, finished it off.



In the end, it's not as accurate as it really should be. It's OC by about .015, but for such a hacked attempt, it came out better than I expected. A dab of super glue in the hole, and it should be done. That glue really pulled it's self in.
Back to top
View user's profile Send private message Visit poster's website
BasicFox



Joined: 15 Mar 2009
Posts: 59
Location: Belgium

PostPosted: Fri Aug 14, 2009 9:05 am    Post subject: Reply with quote

My first open-encoder magnet is also mounted :p it looks really great, the magnets are very small but they have incredible strength! used locktite to connect the magnet to the shaft. Here is the result:
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
jharvey
co-admin


Joined: 15 Mar 2009
Posts: 362
Location: Maine USA

PostPosted: Fri Aug 14, 2009 9:22 am    Post subject: Reply with quote

That's looking good. Interesting to hear how it self centered. That makes sense as the metal body does attract the magnet. I think the next time I do one, I'll cut my nub a bit on the small side and see if that helps keep things aligned.

Last night I stopped by a friends and etched some boards. I have to upload this most recent version. I think this time I have it, and I should know for sure this weekend. I also have to figure out how to get some I2C code in the OSV3. My first goal is to see if I can get data out and into the OSIF.
Back to top
View user's profile Send private message Visit poster's website
BasicFox



Joined: 15 Mar 2009
Posts: 59
Location: Belgium

PostPosted: Fri Aug 14, 2009 10:21 am    Post subject: Reply with quote

The osif itself is a I2C interface, i would first try to read the data using a self made program. So just connect the osif with the open-encoder and listen to what it has to say, if that works good you can write extra code in the OS3. First disable the potentiometer code and use the same register to write the open regulater value.

Can you show me your new pcb file for the open-regulator so i can make one too?
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
jharvey
co-admin


Joined: 15 Mar 2009
Posts: 362
Location: Maine USA

PostPosted: Sat Aug 15, 2009 10:43 am    Post subject: Reply with quote

I have uploaded the most recent of what I have for both Open_Regulator (OR), and Open_Encoder (OE). They can be found here.

http://jaredharvey.com/openservo

In OR I had selected a huge cap, to prevent others from making the same mistake, I blanked that part out of the BOM.

In OE I have made some panels that are mirrored and work well for etching your own boards. pnl3 is the most recent.

Both of these include KICAD files (zip'ed) and PDF's. I renamed the folder structure for OE, so I may have broken a link or two.

Enjoy.
Back to top
View user's profile Send private message Visit poster's website
jharvey
co-admin


Joined: 15 Mar 2009
Posts: 362
Location: Maine USA

PostPosted: Sun Aug 16, 2009 3:52 pm    Post subject: Reply with quote

I modified another POT and now have the first open-encoder. eventually I plan to post an assembly wiki like I did with the MG995 OSV3 construction tutorial. For now I'll post parts of significants in the forums. One note is that you should install the caps and SMT components before the magnet. They kept flying off the board and over to the magnet. What a pain that was.

I also find a dremel works better as a make shift lathe. The OD of the POT shaft is technically .135, not .125, but it's close enough. The big thing to remember is that you release dremel bits after you loosen the lock nut, you tap the end pushing it in, breaking the grip, then pull it out.






The next time I do it, I plan to make an alignment shaft. Such that I align the board with the hole, then glue it in place. Then I install the magnet using the PCB as an alignment tool. I'm thinking I can make a low cost version of this tool by wrapping tape on a nail or some such shaft. Change how much you wind on and you change the OD. It's worth I shot I think.

Now I need to figure out how to make the OSIF software read this thing.
Back to top
View user's profile Send private message Visit poster's website
jharvey
co-admin


Joined: 15 Mar 2009
Posts: 362
Location: Maine USA

PostPosted: Sun Aug 23, 2009 5:00 am    Post subject: Reply with quote

I fired up open encoder for the first time today. Passed the smoke test. Yup it smoked due to a short. I'm glad D3 on the OSIF was the weak point. The board consisted of a home etched PCB, with the chip, two filter caps, and a wire harness, connecting it to the OSIF, with a fedora box. By using python, and pyusb, I modified a script to get the below code. This worked great and I was getting consistent readings. Yipe!

osif.py
Code:

#
# Classes to communicate with OpenServo InterFace
#
#
# Copyright (C) 2009  Darius Rad
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import usb


_OSIF_USB_VID=0x1964
_OSIF_USB_PID=0x0001

_USBI2C_READ=20
_USBI2C_WRITE=21
_USBI2C_STOP=22
_USBI2C_STAT=23

_DEFAULT_TIMEOUT=1000

_EPIN=usb.ENDPOINT_TYPE_CONTROL | usb.ENDPOINT_IN | usb.TYPE_CLASS
_EPOUT=usb.ENDPOINT_TYPE_CONTROL | usb.ENDPOINT_OUT | usb.TYPE_CLASS

class Osif:
    """OpenServo Interface"""

    # todo: support other methods of connecting to OSIF (/dev/i2c-*, uart)


    def __init__(self, adapter=0):
        self.__adapter = adapter

        dev = _adapters[self.__adapter]
        self.__handle = dev.open()

        configuration = dev.configurations[0]
        #self.__handle.setConfiguration(configuration)

        interface = configuration.interfaces[0][0]
        #self.__handle.detachKernelDriver(interface)
        self.__handle.claimInterface(interface)


    def write(self, slave, data=[]):
        """Write data"""

        ret = self.__handle.controlMsg(_EPOUT, _USBI2C_WRITE, data, index=slave, timeout=_DEFAULT_TIMEOUT
)

        self.__handle.controlMsg(_EPIN, _USBI2C_STOP, 0, timeout=_DEFAULT_TIMEOUT)

        return ret


    def read(self, slave, length=0):
        """Read data"""

        ret = self.__handle.controlMsg(_EPIN, _USBI2C_READ, length, index=slave, timeout=_DEFAULT_TIMEOUT
)

        self.__handle.controlMsg(_EPIN, _USBI2C_STOP, 0, timeout=_DEFAULT_TIMEOUT)

        return ret


    def status(self):
        """Get I2C transaction status"""

        ret = self.__handle.controlMsg(_EPIN, _USBI2C_STAT, 10, timeout=_DEFAULT_TIMEOUT)

        return ret


# build list of OSIF adapters
_adapters = []
for bus in usb.busses():
    for dev in bus.devices:
        if dev.idVendor == _OSIF_USB_VID \
                and dev.idProduct == _OSIF_USB_PID:
            _adapters.append(dev)


test_OE_reading.py
Code:
#!/usr/bin/python
#
# OpenServo Scan
#
# Scans the I2C bus provided by OSIF for OpenServo devices and dumps
# the registers of any slave found.
#
#
# Copyright (C) 2009  Darius Rad
# modified by Jared Harvey
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

def int2bin(n, count=24):
    """returns the binary of integer n, using count number of digits"""
    return "".join([str((n >> y) & 1) for y in range(count-1, -1, -1)])

import osif

osif = osif.Osif()

for i2 in range(10):
  for i in range(40, 41):
#      print "probing address 0x%x..." % (i)
      osif.write(i, [0x00])

      stat = osif.status()
      if len(stat) > 0 and stat[0] != 0x20:
#          print "found device at address 0x%02x" % (i)

#          print "stat =",
#          for s in range(len(stat)):
#              print "%02x" % stat[s],
#          print

#          print "regs =",
          regs = osif.read(i,128)
          for r in range(1):
              print "pos = %02x:%02x " % (regs[0], regs[3]) ,
              print "status=",int2bin(regs[1],6),
              print "mag: %02x" % (regs[2]),
              print
#          print


I now know the magnet is strong enough, I was able to center it accurately enough, and I know the basics of how the I2C is handled by this device. Won't be long now until I'm getting into the -dev code looking to add the I2C to code base.
Back to top
View user's profile Send private message Visit poster's website
BasicFox



Joined: 15 Mar 2009
Posts: 59
Location: Belgium

PostPosted: Sun Aug 23, 2009 7:38 pm    Post subject: Reply with quote

good to hear that Very Happy, can't wait to play with it... but still have to do some exams, just keep on going Wink
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
jharvey
co-admin


Joined: 15 Mar 2009
Posts: 362
Location: Maine USA

PostPosted: Sun Sep 06, 2009 10:29 am    Post subject: Reply with quote

BatchPCB is awesome. Just got my first batch of boards. I ordered 12, they gave me 24. Cost me less than $50 for this pile. They are spot on. I can now make a couple open-encoder for real, yeah!
Back to top
View user's profile Send private message Visit poster's website
FireBALL



Joined: 24 Jul 2009
Posts: 28

PostPosted: Thu Sep 17, 2009 4:11 pm    Post subject: Reply with quote

my take on open encoder

Hitec HS-5245MG

Back to top
View user's profile Send private message
BasicFox



Joined: 15 Mar 2009
Posts: 59
Location: Belgium

PostPosted: Thu Sep 17, 2009 5:24 pm    Post subject: Reply with quote

nice how did you attach the magnet?
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    OpenServo.com Forum Index -> Hardware All times are GMT
Goto page 1, 2, 3, 4, 5, 6, 7, 8  Next
Page 1 of 8

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group