Forum

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1]
Author Topic: Motors not working when i compile but hex works
jhndrx
Newbie
Posts: 10
Permalink
Post Motors not working when i compile but hex works
on: August 8, 2014, 08:09
Quote

Using Arduino Uno Rev 3 with V2 motor shield and two nema 17 200 step/rev motors. Compiling code on Mac OS.

I have tried several different versions of the polar graph code and for some reason I can not make my compiled versions of the code move the motors. I have used Terminal to upload the V2 motor shield hex's included in the files and they work perfectly. I would just use the hex since the controller app can update the machine specs but it disables pixel drawing and thats what I wanted. I've noticed in other questions on the forums about a command to initialize the motors but the most recent versions of the polar graph already include this. Any idea what my problem could be?

I've noticed that with the hex uploaded, the initial commands when starting the controller app get sent and processed very quickly. However, when i compile, they take a few seconds for each one and at the top of the window it shows "busy". I've also pressed ctrl+c in the controller app and it repeats with each command:
Dispatching command: C31,600.0,END
Last command:C31,600.0,END:3221029769
regenerating preview queue.

I'm assuming each hex is made with the most recent version of the sketch so its really confusing why the hex works but my compiled sketch doesn't. I've updated my libraries with the most recent versions included with the polar graph and restarted arduino app each time to make sure they are included.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Motors not working when i compile but hex works
on: August 8, 2014, 14:25
Quote

Hello, the hexes are a pain to prepare, so I wouldn't be surprised to find I had missed this update. Additionally, since this update seems to be an 'upgrade' to a non-working version, maybe that's not so bad...

I've just remembered I've got a duemilenove with a motorshield v2 at the workshop, so I'll have a quick tinker later today and see if I can get movement out of it.

sn

jhndrx
Newbie
Posts: 10
Permalink
Post Re: Motors not working when i compile but hex works
on: August 8, 2014, 21:34
Quote

Thanks for the quick reply. I'm going to try and look into how the commands are being sent and received. To me, it appears to be a communication issue, however your the expert on the program lol. Let me know if you find out anything. I'm anxious to start drawing.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Motors not working when i compile but hex works
on: August 8, 2014, 21:37
Quote

Yep just having a look at it now. First glance it looks like the command is being received, but the checksum isn't worked out correctly. Some kind of corruption in the memory - something overflowing or overwriting it's boundaries.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Motors not working when i compile but hex works
on: August 8, 2014, 22:56
Quote

I've just committed a new version, and rebuilt hexes to https://github.com/euphy/polargraph_server_a1 - have a look.

I really want to retire support for the motorshield 2.

sn

jhndrx
Newbie
Posts: 10
Permalink
Post Re: Motors not working when i compile but hex works
on: August 9, 2014, 00:27
Quote

Thank you very much for the quick update. Its very nice to know you want to help others. I'm not sure if its something on my end but it seems that the Polargraph controller doesn't communicate properly with the arduino. The commands aren't getting processed when using the controller app to send them. However, I can open the Serial Window in the arduino app and manually type in the codes such as "C09,5000,5000,END" and "C01,2000,2000,END" and the motors will initialize and move to the coordinates. If this is a programming error with the Controller app then theres no rush with a fix. I made my own Polarshield, if you will. I have a second arduino uno clone hooked up with a LCD and SD card that i use to send the commands to the polar graph arduino. I tested it and its working via this method but the controller app doesn't.

Again, thank you very much for your help. Its been an exciting project for me. Can't wait to get my first drawing!

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Motors not working when i compile but hex works
on: August 9, 2014, 09:41
Quote

Hello, the difference is (I guess) that the controller adds a check sum on the end of each command, eg C01,2000,3000,END:6483648 and that is there to make sure the commands don't get corrupted. That was a problem for a while.

So if you omit the checksum, then it is slightly less safe, but you're unlikely to have a problem in reality.

The problem is a bit hard to diagnose: what I think is happening is that the program loads too much stuff, and ends up overwriting some other variables that are stored in program space. So when it calculates the checksum, it uses a corrupted lookup table, and so the result doesn't match.

I chopped out a couple of variables, and some strings to make room. Did it make no difference?

Sn

jhndrx
Newbie
Posts: 10
Permalink
Post Re: Motors not working when i compile but hex works
on: August 9, 2014, 18:58
Quote

Short version: What you did to the arduino sketch is working great. However, the Processing controller app doesn't seem to be communicating properly with the arduino.

The arduino sketch is working perfect. I can open the serial window and manually type in the commands and the motors will move. I use the Processing controller to generate the commands and then manually type them into the Serial window on the arduino sketch. If i try to use the processing controller app to send the commands it doesn't seem to be communicating properly with the arduino. It says "busy" for a while between each command before going to the next and i don't think the arduino is processing the commands. The motors never lock and I don't see any feedback about the pen width changing, motor speed, etc.

jhndrx
Newbie
Posts: 10
Permalink
Post Re: Motors not working when i compile but hex works
on: August 9, 2014, 20:24
Quote

So I'm attempting to make a drawing but its not doing anything. It will move to the starting point but then it won't do any of the pixel drawing commands. At first i thought it might be due to my pixel size and pen size so i upped the pixel size and lowered my pen tip size but still nothing is happening with the C05 commands. (no sync messages, errors, or anything except "ready" in serial window). Would this be due to something you may have changed in the sketch? I noticed another forum with the same problem but they didn't have pixel drawing defined so that didn't help. Sorry for all the trouble.

jhndrx
Newbie
Posts: 10
Permalink
Post Re: Motors not working when i compile but hex works
on: August 9, 2014, 22:13
Quote

I disabled the pen lift feature since i currently don't have a servo attached and it started drawing. So it seems its all stemming to memory issues with the arduino Uno.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Motors not working when i compile but hex works
on: August 9, 2014, 22:36
Quote

I think that's what I meant - the arduino sketch is not working perfectly, it can do _some stuff_ ok, but if it's just luck when it works and when it doesn't. The controller is behaving just as it always has.

It's a pity there isn't a more explicit way of telling when this overflow has happened.

happy scribbling 🙂
sn

jhndrx
Newbie
Posts: 10
Permalink
Post Re: Motors not working when i compile but hex works
on: August 10, 2014, 05:13
Quote

Yes, I've wished the arduino program had a debugging feature ever since I've started using it. Step by Step code progression with the variables on the side like many other programs feature would be better than nothing at all. I managed to get something to draw so major Milestone reached! However my rigged gondola isn't up to par. Thanks for your help!

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Motors not working when i compile but hex works
on: August 10, 2014, 11:45
Quote

Good stuff 🙂

sn

jhndrx
Newbie
Posts: 10
Permalink
Post Re: Motors not working when i compile but hex works
on: August 13, 2014, 05:40
Quote

I've noticed that the pen lift causes the sketch to fail with pixels (haven't tried vectors yet). I deleted every Serial.print line in the server sketch to reduce any chances of error in my "polar shield" variant. (simply an arduino looking for the "ready" command and sending the next line of code from a SD card). Deleting all the Serial.print messages brought the sketch down to about 26K. Adding the pen lift definition raised that to 28k. I've read that 30k is the usable amount in an UNO so it must be a memory issue. Programming is my hobby and not a profession so i'm a bit confused on some of the things in your sketch. Any help to understand the general process of your code or help debugging what may be causing the memory issue with the pen lift defined would be greatly appreciated. If i understood the general process of the code I would be more than happy to spend a few hours trying to debug the problem for you.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Motors not working when i compile but hex works
on: August 13, 2014, 17:06
Quote

HEllo, this is actually a rather tricky issue that is rarely covered, and I've found almost impossible to debug

http://arduino.cc/en/Tutorial/Memory is a good guide, but to precis:

There's two kinds of memory in arduino
1) Flash memory - 32,768 bytes. This is where your program goes (and the bootloader).
2) SRAM - 2048 bytes. This is where your variables go.

When you upload your program, it tells you how much flash memory you've used, but it can't tell ahead of time how much SRAM you're going to use, because that depends on how the program actually runs.

You can do things like

int massiveArray[5000];

Which will define an array that is bigger than the total amount of SRAM. It'll compile ok, and even probably run ok, but when you try to put something into that space and then read it back out later, it'll behave very oddly.

It isn't a big problem unless you are dealing with big arrays, or Strings (which are just big arrays with a bit of decoration). And Polargraph uses Strings a lot. Additionally, I'm sure it uses Strings in a pretty inefficient way, because I don't really understand how to housekeep that stuff tidily, pointers etc. (My background is java so I'm pretty sloppy on that low-level stuff.)

The takeaway is that you can easily check your program memory usage when you upload, but you cannot easily check your SRAM usage.

A command like

Serial.println("Hello");

Expands your program memory because it adds the serial.println command into the list of things to do. It also uses SRAM because the String it is sending is created on-the-fly in SRAM. Using the F(...) function is a little helper for arduino, so you will see most of the Serial.prints look like

Serial.println(F("Hello"));

The F(...) function actually puts the string "Hello" into the program memory area (the FLASH area), so it doesn't use up any SRAM. Often this is enough, but there are some things you can't put in there - anything generated dynamically.

sn

Pages: [1]
Mingle Forum by cartpauj
Version: 1.0.34 ; Page loaded in: 0.036 seconds.