Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

damenace

macrumors newbie
Original poster
Aug 6, 2005
6
0
I am doing a senior design project. We are using an isight to do image capturing of a resistor, then figuring out its' resistance through band color identification. We then have a conveyor belt system to transport the resistor to an appropriate bin. We have found a unix script to capture information from the isight, but we don't know to use my powerbook to write to a motor controller.

What do you think would be the best method to do this? We are already using matlab to do some image analysis.

We will be operating in Unix so hopefully there is an easier method outside of using python. With that said, python is our last resort.

Can C be used to impliment this? We can use C for the image processing instead of matlab, so is there a way to communicate to an external motor controller via USB -> Serial cable? And how?
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
Why does it need to be so damnably difficult? Why can't I just do something like this:
Code:
/* find available ports */
NSArray *serialPorts = [[NSSerialManager sharedManager] availablePorts];
NSSerialPort *aPort = [serialPorts objectAtIndex:0];

/* open port for exclusive access and set format */
[aPort openWithAccess:NSReadWriteAccess];
[aPort setTransmissionSpeed:9600 dataBits:8 stopBits:1];

/* read available data from the port (buffered) */
NSData *availableData = [aPort readAndClear];

/* write a string to the port */
[aPort writeData:[@"test" dataUsingEncoding:NSASCIIEncoding]];

[aPort close];

EDIT: typo fix
 

csubear

macrumors 6502a
Aug 22, 2003
613
0
superbovine said:


but in practice implementing a USB client in hardware is a real pain, and can require a good knowledge of VHDL (and yes i know you can by off the self chips, but you have to use a driver provided by the manufacture, and can be a royal pain when trying to integrate to the device)

think of it this way application -> device driver -> host usb controller -> usb client -> motor.

I am not aware of any motor that can be controlled via USB (but there maybe one)

An easier way to to use a micro-controller that has the necessary hardware to do what you want (ie serial io, and a pwm for controlling to motor). The Obj-c code posted above would work just fine, and could work along side any C code that you are going to use for image processing.

application (obj-c) -> device driver (serial, provided) -> micro-controller -> motor

That would be the quickest way to get a solution out the door.

edit:
assuming those objects exist, a quick google showed nothing, but in all reality, its just wrap the os's c api for serial io.
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
csubear said:
The Obj-c code posted above would work just fine
The problem is, the code I listed above doesn't exist. AFAIK, there's nothing like that available, I'm wondering why there isn't something that easy, it seems like there could be and should be.
 

csubear

macrumors 6502a
Aug 22, 2003
613
0
HiRez said:
The problem is, the code I listed above doesn't exist. AFAIK, there's nothing like that available, I'm wondering why there isn't something that easy, it seems like there could be and should be.


/shrug

I don't think there's any way to access the serial port in .Net either. Most frameworks have dropped support for serial ports.

http://pyserial.sourceforge.net/ is a python module that does serial port io. You could take a look at his code and make your own obj-c wrapper for serial io.
 

thisone

macrumors newbie
Feb 7, 2006
1
0
Southern California
connecting to RS-232 serial with a Mac using WiFi

damenace said:
I am doing a senior design project. We are using an isight to do image capturing of a resistor, then figuring out its' resistance through band color identification. We then have a conveyor belt system to transport the resistor to an appropriate bin. We have found a unix script to capture information from the isight, but we don't know to use my powerbook to write to a motor controller.

What do you think would be the best method to do this? We are already using matlab to do some image analysis.

We will be operating in Unix so hopefully there is an easier method outside of using python. With that said, python is our last resort.

Can C be used to impliment this? We can use C for the image processing instead of matlab, so is there a way to communicate to an external motor controller via USB -> Serial cable? And how?


I've been using a WiFi to serial port converter that works extremely well for having the Mac 'talk' to an RS-232 serial port. I belong to a group of Robot enthusiasts that work with the Hero Robot which has an RS-232 port for communications.
The product that makes the Mac to serial communications easy is made by DataHunter. They are at http://www.datahunter.com
The small box is powered by 12V DC and provides two serial ports and a WiFi 802.11b,g link. There are other manufacturers of this type of product, but I like the low price of the DataHunter.
By using a terminal application on the Mac or from the command line I can send serial data to and from my Robot.

I've tried the USB to serial 'dongles' and there always seems to be problems getting them to work reliably. You may have better luck with them than I did.
For my purposes the Wifi to serial converter is just $169 dollars and zero time spent trying to program it or get it to work.
 

Timepass

macrumors 65816
Jan 4, 2005
1,051
1
sorry had to laugh really quickly. I rememeber people saying serial ports are dead and worthless a while ago and they did not seem to believe me that they still have very valid uses today. (namely that are easier to program things to do for). Part of the reason why I think floppy drives will never die and that I will keep putting them in my self build PCs for very long time. They both still have several very valid and useful things that the more modern stuff cannt do (few and far between but that not the point) It going to be that one time, just that ONE time that you need it and you dont have. and yes I also own a USB floppy drive for laptops if I ever need to use it which isl ike maybe once a year.

that being side maybe there is some MPCI card you can get that would give you a serial port. It be hard to find but I would not be surpised to see one out there. With that you might make you job a bit easier
 

superbovine

macrumors 68030
Nov 7, 2003
2,872
0

yippy

macrumors 68020
Mar 14, 2004
2,087
3
Chicago, IL
I know this is way differnt than you were thinking or are has been suggested. But what about using something that is already made?

Lego Mindstorms, it looks like the newest ones are even officially Mac compatible.
 

superbovine

macrumors 68030
Nov 7, 2003
2,872
0
yippy said:
I know this is way differnt than you were thinking or are has been suggested. But what about using something that is already made?

Lego Mindstorms, it looks like the newest ones are even officially Mac compatible.

awesome solution
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
csubear said:
http://pyserial.sourceforge.net/ is a python module that does serial port io. You could take a look at his code and make your own obj-c wrapper for serial io.
Thank you for that link, that is really cool and I think a great solution for me for some future projects. Wrapping that in Obj-C looks to be much, much simpler than using Apple's very low level solution. Man I love Python. I like Objective-C, but I wish Apple had based Cocoa natively on Python (without a bridge). I know, the roots go all the way back to NeXT, but still...I can dream. Python is interpreted but is generally very fast, most of the time much more speed and resource efficient than Java, and in terms of work per line of code and readability it's more efficient than just about any language out there.
 

damenace

macrumors newbie
Original poster
Aug 6, 2005
6
0
Thanks Guys. I should have researched more before I posted. Past few days I have found many of the things you guys have just suggested. I went more of the hardware route in EE and my OS/Programming knowledge is not up to par. With that said, here is an update on what we are doing.

Found some sample code for Serial accessing with a Keyspan Adapter.

http://www.keyspan.com/support/developers/

"(obj-c) -> device driver (serial, provided) -> micro-controller -> motor"
This is exactly what we are doing.......

Our plan is to drop Matlab and stick with obj-C or python for all image analysis and motor controls. I've checked out various books on Objective - C with Cocoa, and python so wish me/us luck.

PS. We have a Math/EE major who understands programming and the windows enviroment. I hope he has no trouble doing OBJ-C cocoa on a mac.
PS1.1 What is up with O'reilly and having animals on their books
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
damenace said:
Can C be used to impliment this? We can use C for the image processing instead of matlab, so is there a way to communicate to an external motor controller via USB -> Serial cable? And how?

I don't understand -- do you already have a motor controller? If its controlled by serial port, then you can probably use a USB->Serial cable, and just write to the serial port like any other device. (As easy as 'cat > /dev/ttyx', etc.) Notice that those converter cables usually don't handle signal selects very well, so if your motor controller is looking for handshaking signals or anything like that, then you might be stuck.

If you don't have a motor controller, you can buy (kind of expensive, tho) a USB motor controller. Try googling for "Phidgets".

If its inside the scope of the project, design and build your own motor controller. Then you can control the interface easily.

C can definitely do this type of I/O, I think Matlab can too but its been a while since I've used it.

I took a computer vision class in college, what kind of image analysis are you doing on the isight?
 

damenace

macrumors newbie
Original poster
Aug 6, 2005
6
0
Taking a picture of a resistor. Identifying the color bands and using a moveable shoot at the end of a conveyor belt to sort the resistor. Needless to say, in 1 semester, we are only sorting too 3 bins.

Thank god we have a EE/Math major who understands all the imaging algorithms.
 

cervy

macrumors newbie
May 15, 2010
1
0
to sir damenace ,having the same project

we have the same project,, we capture resistor using webcam ,and analyzing it with matlab.. we have troubles on the program,, can you pls teach me sir damenace,, we came up with 5 wattages of resistor (2W,1W,1/2,1/4,1/8W).. on the other hand our mechanical way of sortting the resistor is weak,, do you have any suggestion, aside from using robotic arm,, i am hoping for your response. i hope i you will let me know a lot about your project.. just incase here is my email add. cervy_012@yahoo.com, thank you
 

jared_kipe

macrumors 68030
Dec 8, 2003
2,967
1
Seattle
Slide down smooth metal ramp with doors that can be opened/closed to drop down "shafts" into buckets.

I've never done anthing like this but I would think it would be quite easy to program the logic for controlling the doors provided you could find some easy way of opening/closing them.
 

jared_kipe

macrumors 68030
Dec 8, 2003
2,967
1
Seattle
Why does it need to be so damnably difficult? Why can't I just do something like this:
Code:
/* find available ports */
NSArray *serialPorts = [[NSSerialManager sharedManager] availablePorts];
NSSerialPort *aPort = [serialPorts objectAtIndex:0];

/* open port for exclusive access and set format */
[aPort openWithAccess:NSReadWriteAccess];
[aPort setTransmissionSpeed:9600 dataBits:8 stopBits:1];

/* read available data from the port (buffered) */
NSData *availableData = [aPort readAndClear];

/* write a string to the port */
[aPort writeData:[@"test" dataUsingEncoding:NSASCIIEncoding]];

[aPort close];

EDIT: typo fix
I know right?

I assume it is because Apple has no interest in doing it themselves. Its not like they sell something that interfaces over serial port, so they have no interest in making it easy for anyone else to do.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
I know right?

I assume it is because Apple has no interest in doing it themselves. Its not like they sell something that interfaces over serial port, so they have no interest in making it easy for anyone else to do.

You're replying to a post from more than 4 years ago.

Anyway, these days I usually point folks to AMSerialPort:
http://sourceforge.net/projects/amserial/

You could use it as-is, or write your own simplifying facade over it.


Slide down smooth metal ramp with doors that can be opened/closed to drop down "shafts" into buckets.
I suggest a solenoid-operated catapult. A resistor slides onto it and a specific amount of energy is used to energize the solenoid. The resistor is catapulted at a specific angle into a bin positioned at a certain distance.

Since the mass of the resistor is proportional to its wattage, and the energy into the solenoid is known, physics suggests that smaller wattage resistors will travel farther than higher wattage ones. Calculate the bin positions using the equations for motion in a gravitational field, then verify by experimental fine-tuning. And if it doesn't work, it will be a lot more fun to watch fail than doors and shafts.

Alternative approach...

Most resistors have tinned-steel leads, and steel is magnetic. So again noting that wattage is proportional to mass, energize an electromagnet to pick up the resistor. The electromagnet is mounted on the end of a circular arm, which rotates at a constant angular velocity. Ramp down the electromagnet current (magnetic force is proportional to current) as the arm turns, and the mass of the heavier resistors will cause them to separate from the electromagnet sooner. Again, arrange the bins in decreasing order of wattage.


As intriguing as this topic is, its resurrection is unlikely to yield an answer to the resurrector. The damenace user hasn't posted anything since 2006, so the likelihood of getting details about his student project are remote.
 

autorelease

macrumors regular
Oct 13, 2008
144
0
Achewood, CA
Remember there are other APIs on Mac OS X other than Cocoa. The POSIX serial functions work just fine on a Mac; any code examples you find for using the serial port in Linux will work with a Mac.

If you get an FTDI cable, like this one (http://www.sparkfun.com/commerce/product_info.php?products_id=9718), the serial port will show up as something like /dev/cu.usbserial***. You can open, read, and write to the device just like you would any other file descriptor. (read the man pages for read(), write(), open(), and tcgetattr()/tcsetattr() for setting baud rate, etc.)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.