CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Machine Controllers Software and Solutions > LinuxCNC (formerly EMC2)


LinuxCNC (formerly EMC2) Discuss LinuxCNC (formerly EMC2) Controlers here!


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 08-16-2007, 05:47 AM
 
Join Date: Aug 2007
Location: Australia
Posts: 6
dakiller322 is on a distinguished road
EMC2 to diy CNC

Hi all,

I'm working on building a fairly basic XYZ CNC mill/plotter, stepper motor controlled, all fairly basic. Now controlling it with EMC2, I want to be able to send all the commands via the PC serial port to a microcontroller and have it manage the stepper motors there. coding micro's and building all the hardware is no problem, but I'm a linux noob and setting up the HAL driver to send commands serially is a little beyond me right now.

I've got the latest Ubuntu CD with EMC bundled on it and have booted it in a virtual machine at the moment to have a look at it, but I'll probably make a dedicated install if it gets too hard trying to talk through the virtual machine drivers.

So has anyone got any tips on setting up the drivers to send commands via serial? I just need to get them out of the PC, decoding their function at the microcontroller is no problems. And how about communication in the other direction, limit switches and stuff like that?

Thanks,
Dan
Reply With Quote

  #2   Ban this user!
Old 08-16-2007, 08:08 AM
 
Join Date: Feb 2007
Location: United States
Posts: 8
Jeff Epler is on a distinguished road

In emc2, the PC interprets all the gcode, and then the realtime portion of the software produces a "commanded position", typically every 1ms ("commanded position" includes helical arc interpolation, blending, acceleration & velocity limits, and so on). It compares it to a "feedback position" just as often, issuing a following error if the difference is too great.

You can put whatever you want between "commanded position" and "feedback position" -- for instance, servos controlled with a PID loop and PWM, steppers controlled by "step & direction" signals generated at 50kHz, and so on.

So back to this device you'd like to build. You've said it will use the "PC serial port". emc2 doesn't yet include any hardware drivers that use the serial port and can't use linux own drivers for realtime tasks like motion control, but since you're familiar with programming microcontrollers, you should understand in general what it takes to write a hardware driver for the PC's "16550" serial chip. http://www.beyondlogic.org/serial/serial.htm

Now you need to figure out all the details, like the format of the data to be transmitted between the PC and your device. At 115200 baud (the maximum supported by a standard PC serial port) you get about 10 8-byte characters each way per 1ms under ideal conditions. Conveniently, this fits within the 16-byte FIFO of the 16550. One possible format would be a series of 3 or 4 signed differences in position (one per axis you control) with the rest of the bits left over for misc digital inputs and outputs.

Then all you have to do is write all the software and hook up the HAL driver. Documentation for writing HAL drivers is on the linuxcnc.org website: http://linuxcnc.org/docs/2.1/html/hal/comp/
Reply With Quote

  #3   Ban this user!
Old 08-16-2007, 06:47 PM
 
Join Date: Oct 2005
Location: USA
Posts: 12
fenn is on a distinguished road

a good place to start hacking might be the serial port component:
http://linuxcnc.org/docs/html/man/man9/serport.9.html
this driver currently only gives you access to the raw bits of the serial port. it doesn't expose any FIFO buffers; you would have to add them to the list of functions as new "inb()" and "outb()" methods for example. also you will have to come up with some kind of protocol like jepler described, and that is best done in C rather than trying to glue stuff together in HAL.
Reply With Quote

  #4   Ban this user!
Old 08-16-2007, 07:38 PM
 
Join Date: Mar 2007
Location: USA
Posts: 207
John3 is on a distinguished road

Originally Posted by Jeff Epler View Post
..... Then all you have to do is write all the software and hook up the HAL driver. Documentation for writing HAL drivers is on the linuxcnc.org website: http://linuxcnc.org/docs/2.1/html/hal/comp/
Jeff,

Just tried the above website.....NO-GO! Is it mistyped / down / or do I have a bum connection?

John
Reply With Quote

  #5   Ban this user!
Old 08-16-2007, 10:48 PM
acondit's Avatar  
Join Date: Apr 2005
Location: USA
Posts: 1,774
acondit is on a distinguished road

John,

I just clicked on the link and it worked for me.

Alan
__________________
http://www.alansmachineworks.com
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 08-17-2007, 07:55 AM
 
Join Date: Mar 2007
Location: USA
Posts: 207
John3 is on a distinguished road

Its working for me now......
Reply With Quote

  #7   Ban this user!
Old 08-17-2007, 09:11 AM
 
Join Date: Aug 2007
Location: Australia
Posts: 6
dakiller322 is on a distinguished road

Thanks for the posts, I've read through a bit so far and I'll see what I can make of it
Reply With Quote

  #8   Ban this user!
Old 08-27-2007, 08:56 PM
 
Join Date: Aug 2007
Location: Australia
Posts: 20
HelicalCut is on a distinguished road

dakiller what are you running on the serial port, is it an ocean controls or silicon chip type serial command interpreter?

You will have to write a device driver for the HAL, I am looking at the same thing. It is not quite as simple as just moving the comands to the serial port, the parallel inteface has step and direction info with acceleration max step rates etc handled by the host machine (one running EMC) the ocean controls serial board offloads this to an embedded micro.

I havent looked at the internal architecture of EMC yet but it may be that all that is required is a simple command interpreter and a serial driver.
Reply With Quote

  #9   Ban this user!
Old 09-02-2007, 03:30 AM
 
Join Date: Aug 2007
Location: Australia
Posts: 6
dakiller322 is on a distinguished road

I've been going over how to do it and have basically come up with the idea to take the parallel port step/direction commands as well as the other standard bits and just put them in two bytes and just send them via serial port to the micro. Makes for easy programming and I don't need to calculate anything and leave it to EMC to do all that.

Going with this SERPORT driver, is this already built in? Looks like it already has the read-write functions built in and I don't see how I need a FIFO as it wont be necessary for the output bytes to the micro to be exactly timed (everything can be synced to latch out there) and as long as I read any byte in in enough time I'll be right? Or is the FIFO always active and going to make more complications?

Sorry for some of the stupid questions, linux is new to me and so is HAL
Reply With Quote

  #10   Ban this user!
Old 09-02-2007, 09:12 AM
 
Join Date: Feb 2007
Location: United States
Posts: 8
Jeff Epler is on a distinguished road
serport is not for streams

the serport driver is only for the rs232 control lines; the "TX" output pin does not send a byte stream, it just sends MARK or SPACE according to the value hooked to pin-3-out. Think of it as a crippled parport with only 4 inputs and 3 outputs, and at inconvenient voltages.

If you want to send streams of bytes, you will have to write your own serial driver.

In any case, the idea of sending a stream of bytes where bit 0 is "X Step", bit 1 is "X Direction", and so on is attractive but unlikely to work very well in practice.

The first kind of problem you will see is that at the 16550 FIFO's maximum rate (115200 bits per second) you can only command very low step rates. If each byte can command a step, then the maximum step rate is 11520 steps per second--OK for a slow machine or a machine without microstepping, but also easily attainable with a parallel port.

The second kind of problem you will see is in the timing of things. HAL threads run at a particular rate, called the PERIOD, which is a multiple of the period of a high-resolution timer in the PC. The 16550 FIFO has its own timer to determine the start of each transmitted bit. Now, you need to configure HAL so that it is activated exactly as often as the 16550 transmits a byte. In HAL, you put a new byte on the transmit FIFO. BUt what if these two clocks can't mesh exactly, every time? If the 16550 clock is the tiniest bit slower than the HAL clock, you will eventually find that the 16550 transmit FIFO is full. What do you do? You are faced with either skipping a byte (and thus losing steps) or trying to delay until the FIFO is not quite full (and eventually miss realtime deadlines). Another solution is to arrange it so that the 16550 clock is always faster than the HAL clock, but that will erode your already-low steprate.

That's why I believe that any driver using a serial protocol will have to adopt a packet structure like the one I outlined tersely in my earlier message. The packet structure will have high-level information (like velocity request and position feedback), fit within the bits available, and by having slack time it will avoid the problem of skew between the HAL and FIFO clocks.
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 10-04-2007, 09:29 PM
 
Join Date: May 2007
Location: USA
Posts: 717
sansbury is on a distinguished road

Out of random curiosity, why is it that you want serial port control?
Reply With Quote

  #12   Ban this user!
Old 10-05-2007, 12:16 AM
 
Join Date: Aug 2007
Location: Australia
Posts: 6
dakiller322 is on a distinguished road

Originally Posted by sansbury View Post
Out of random curiosity, why is it that you want serial port control?
Hoping to run it off my laptop which doesn't have a parallel port, thought it would be a good learning exercise as I haven't done much with rs232 before and I always like to do things different

Anyway, I've dropped the serial port idea and just sticking with parallel port step/direction

This is actually for a uni project, so here are a few pics of it so far if anyone's interested

Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help On EMC2 Info... Brenck LinuxCNC (formerly EMC2) 3 06-27-2007 05:29 AM
Emc2 sdantonio Mach Mill 2 02-05-2007 02:26 PM
emc2 -hal*? essa LinuxCNC (formerly EMC2) 3 05-27-2006 12:06 PM
emc2 heilcnc LinuxCNC (formerly EMC2) 2 05-23-2006 05:03 PM
Easy EMC/EMC2 whirlybomber LinuxCNC (formerly EMC2) 15 04-18-2006 07:13 AM




All times are GMT -5. The time now is 02:54 PM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361