Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to draw arcs #8

Open
bjpirt opened this issue Nov 17, 2014 · 8 comments
Open

Add the ability to draw arcs #8

bjpirt opened this issue Nov 17, 2014 · 8 comments

Comments

@bjpirt
Copy link
Contributor

bjpirt commented Nov 17, 2014

It would be nice to be able to draw arcs with Mirobot. Still need to figure out a reasonable way of specifying the arc radius and length that will make sense via the UI. e.g.

{"cmd":"arcleft", "arg":[50, 100]}

would draw a 50mm radius arc, curving to the left for 100 degrees

@dgym
Copy link

dgym commented May 13, 2016

I think the radius + angle works very well.

I am seeing an issue on the arc-command branch - the penup and pendown commands no longer work. It looks like the changes to Timer2 are making it fire more interrupts, and these are causing timing issues with the delayMicroseconds() call in Mirobot::servoHandler().

It may be worth making sure any interrupt handlers do the minimum amount of work possible to minimize problems like these, but since I needed a quick fix I just disabled interrupts in servoHandler which works well enough in this case.

Hope that helps.

@bjpirt
Copy link
Contributor Author

bjpirt commented May 13, 2016

Glad the curves are working well - annoying it broke the pen lift :-) The timer interrupts are firing a lot more often because we need to run the steppers at different rates, but all it does for the majority of the time is just decrement a counter. I’ll have a play and see what I can do to coax it to work. It might be that the delay in there is being interrupted and breaking (I never liked the delay approach anyway as everything else is nicely non-blocking!)

@dgym
Copy link

dgym commented May 13, 2016

The curves are great, thank you!

To avoid the delay could the pulse generation be handled by a PWM timer? I think the servo is conveniently on a PWM capable pin, if so then the timer could be set up for the correct pulse and a end-of-timer signal handler could manage stopping the timer after the 15 pulses. Just a thought.

@bjpirt
Copy link
Contributor Author

bjpirt commented May 13, 2016

That's a good plan. I used to drive the servos via PWM but moved to the current method because it saves a lot of power and stops any jitter in the servo by not driving it when it's in the desired state.

Will need to check which timer drives the PWM on that pin and make sure it doesn't clash with the stepper timing.

@bjpirt
Copy link
Contributor Author

bjpirt commented May 26, 2016

@dgym take a look at the arc-command branch again - I've just pushed a commit which should fix the servo. Some background on what I did:

  • I remembered why I didn't use the PWM based timers. If you turn off a timer you might turn it off in the middle of a pulse and so the wrong pulse value would get sent to the stepper, affecting its position
  • Also wondered about making my own PWM using another timer, but Timer1 is used for the steppers and Timer2 is used by the Tone library, which I use for the buzzer. Sharing Timer interrupts between libraries is an abstraction layer I just don't want to get sucked into right now :-)

In the end I just disabled interrupts for the stepper driver once all steppers had stopped turning which seems to have fixed the issue. Give it a try and let me know how you get on.

@dgym
Copy link

dgym commented Jun 1, 2016

Hello, thank you for looking into this, that sounds like a good solution. I'll let you know how I get on when I next have a bot to try it on.

@dgym
Copy link

dgym commented Jun 14, 2016

That patch works very nicely thank you. I haven't seen any other issues and the arcs are really appreciated.

@bjpirt
Copy link
Contributor Author

bjpirt commented Jun 14, 2016

Excellent! Thanks for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants