Forum

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1] 2
Author Topic: Towards running a Polargraph with an Adafruit Motorshield V2
k3a
Newbie
Posts: 4
Permalink
Post Towards running a Polargraph with an Adafruit Motorshield V2
on: March 24, 2014, 16:58
Quote

Yes, that´s the question right now, and I hope we will find a final answer in this thread.

The Issue:
The Polargraph server software (aka Arduino Firmware) is designed to work with the Adafruit Motorshield V1. This shield is obsolete and not sold anymore. The new version, the Motorshield V2 seems to be working differently.

Approaches so far:

In this thread, Xander1027 suggests a modification of the configuration.ino:

// 1. Adafruit motorshield
 #include <Wire.h>
 #include <Adafruit_MotorShield.h>
 #include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 

const int stepType = INTERLEAVE;

Adafruit_StepperMotor *afMotorA = AFMS.getStepper(motorStepsPerRev, 1);
 Adafruit_StepperMotor *afMotorB = AFMS.getStepper(motorStepsPerRev, 2); 

void forwarda() { afMotorA->onestep(FORWARD, stepType); }
 void backwarda() { afMotorA->onestep(BACKWARD, stepType); }
 AccelStepper motorA(forwarda, backwarda);

void forwardb() { afMotorB->onestep(FORWARD, stepType); }
 void backwardb() { afMotorB->onestep(BACKWARD, stepType); }
 AccelStepper motorB(forwardb, backwardb);

void configuration_motorSetup()
 {
AFMS.begin();// create with the default frequency 1.6KHz
 }

Xander1027 is using a Arduino Mega 2560 and Adafruit Motorshield V2. He/She did not actually say it's working, but it sounded somewhat like that.
I tried to reproduce the results on my Arduino Uno R3 and Motorshield V2. I had the problem that the sketch gets too big. So I cut out the penlift feature, because I currently do not need it. This resulted in a sketch that is just small enough to fit.
Problem 2: The Arduino Uno bootloader (Optiboot) seems to be broken and fails with large sketches. I simply erased the bootloader and uploaded my compiled sketch using an ISP programming tool (Atmel AVRISP MKII).

Now the sketch is running and I can connect the controller application. But when I send motion commands, nothing is moving.
Using the Adafruit example codes that come with the Motorshield V2 lib, I was able to move the motors.

k3a
Newbie
Posts: 4
Permalink
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: March 24, 2014, 17:24
Quote

So some more thoughts on that:

Let's start with the difference of the Motorshield V1 and V2:
Both use two motor driver ICs and one logical driver IC that takes commands from the Arduino and passes them to the motor driver ICs. In V1, this logic driver is a 74HC959 shift register. It basically takes a serial data stream and parallelizes it, distributes the signals to the motor drivers. No intelligence involved. (Pardon my non-engineer-explanation).
Now the V2 shield works similar on the one hand and completely different on the other. The logic IC this time is a PCA9685 16-Channel 12-bit PWM/servo driver with an I2C interface. This chip is "intelligent" in so far that it does not need to be refreshed for every pulse a stepper motor takes. It just receives the pulse rate once and then pulses away until your Arduino tells it to stop. That device can do a couple of neat things, but the main problem is:

The Polargraph server uses the Accelstepper, which is a smooth way to control the Polargraph, but unfortunately does only support the Motorshield V1 and not V2.

My suggestion to get this work the quick and dirty way would be to use an old version of the Polargraph server which does NOT use the Accelstepper lib yet and patch that one to use the V2 Motorshield instead of the V1 one. The clean way would obviously be patching the Accelstepper lib to support the V2 shield.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: March 24, 2014, 18:08
Quote

Hello! Accelstepper already supports the v2 shield, insomuch as it ever supported the v1 shield - via the onestep(..) methods on the AFMotor objects, linked with the Accelstepper(forwardFunction, backwardFunction) constructor.

I think the -> notation way of calling onestep is a bit curious, but I guess it's a pointery way of doing it since the motor objects themselves are declared as pointers. (I don't really understand that stuff very clearly.)

There is no version of polagraph server that doesn't use accelstepper, it's always been there. Thank god.

Looking at the adafruit examples, I don't see what's missing from Xander's code. Are you positive that there are no other things that might be preventing the motors from moving? What does the debug console report when you do your move commands (ctrl-c for the debug console in the controller).

You're right that something needs to be stripped out of the arduino ("small footprint") firmware to make it ready. My thought was to produce two versions for small footprints, one that has pixel shading, and one that has vector drawing+penlift.

Realistically, a memory-efficient rewrite of the firmware is the next step. And that's why I've been putting it off...

sn

k3a
Newbie
Posts: 4
Permalink
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: March 26, 2014, 14:53
Quote

Ah, so it seems like it's not an issue with the shield but with the communication between PC and the Arduino Uno. The Uno does not use an FTDI as a serial converter but an Atmega8/16U4. This one appears to behave slightly different. I narrowed it down to the commands not being received by the controller. Now I connected a Seeeduino Mega, added extra I2C pinheaders and it seems to work. At least the motors are spinning now.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: March 26, 2014, 18:42
Quote

It's good that you've got something working, but I don't think it is for the reason you suggest. If you were able to connect at all, and get a READY filtering through to the controller app, then that means your virtual comm port was working, drivers present, all that.

As a note, the code (or indeed the RXTX driver that the code uses) does not target any particular USB implementation. It just connects to "ports", however they are created.

Good luck!
sn

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 17, 2014, 23:27
Quote

Ok, I've just committed a fairly big update to the polargraph_server_a1 project repo (https://github.com/euphy/polargraph_server_a1).

This enables the Adafruit Motorshield v2. I only have motors attached to this machine I'm testing with, so can't tell if it's really making sense, but they are moving at least.

It requires a little configuration now, so read the README.md. I have pre-compiled two binaries and put them in the same project:

polargraph_server_a1_adafruit_v1.cpp.hex - Is for motorshield v1.
polargraph_server_a1_adafruit_v2.cpp.hex - Is for the new motorshield v2.

The sound doesn't seem quite right to me, but that just be lack of familiarity.

I'd like to hear if anybody tries this and has any luck.
sn

vdrome
Beginner
Posts: 36
Permalink
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 18, 2014, 16:34
Quote

Hi Sandy,

I have a V2 motorsheild, I'll upload this firmware and pop it on my setup and see what happens.

Just curious what would be the benefits of running the newer motor-shield?

Cheers.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 18, 2014, 21:30
Quote

As far as I can see,
1) You can't buy the old motorshield from Adafruit anymore.
2) It's a proper stepper driver chip that can handle 1.2A rather than 0.6A, and proper microstepping.

Not so important for us, 3) It stacks and so can use lots of motors at once.

Mainly I just wanted to get it working for the folks who had them - got a lot of questions about them!

vdrome
Beginner
Posts: 36
Permalink
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 23, 2014, 04:20
Quote

Okay, I've got the firmware up and running! I'm using the V2 motor-shield, rendering vector graphics - still in tweaking mode as this is my first build. One issue I'm having is squiggly vector lines - which seem to be coming from the motors vibrating and running down the beaded cords. I've a pair of these motors:
(https://www.adafruit.com/products/324) defined at 400 steps per rev in the controller software. Here's a picture of whats going on:

Image

I was also getting these squiggly lines running on the older motorsheild as well. Is there anyway I can smooth these lines out?

Alejandro-
de-
Montecrist-
o
Newbie
Posts: 15
Permalink
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 23, 2014, 12:53
Quote

may be it's not a really a solution but may we can still buy old motor shields from ebay and china clones, i use de cheaper clones may be is an alternative

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 23, 2014, 13:21
Quote

If your squiggles are vibrations coming from the steppiness of the motors, then you could try changing the step style from INTERLEAVE to MICROSTEP. I didn't really try the microstepping on the shield, so not clear how well it works - it was never very good on the old motorshield, but this v2 has proper stepper driver chips so I bet it's worth using now, and will certainly smooth some motion out.

Once you switch to microstepping, you will have 16x 200 steps per rev (3200). You can use that if you like, but I don't like the idea of stopping the motor on a microstep, so what I do for the Polarshield (with 8x microstepping) is specify the native steps per rev accurately (ie 200 in your case), and then set the stepMultiplier setting to my microstepping setting (ie 16 in your case).

This has the effect of addressing the machine in whole steps, so that it never stops inbetween steps, but still gives the benefits of smooth stepping. Naturally it will work 16x slower, so you need to multiply your speed manually, and you will probably run into the limitations of the arduino hardware when stepping at more than 4000 steps per second. This post (http://forums.adafruit.com/viewtopic.php?f=31&t=42477) might help with overcoming rate limiting, but there is potentially more than one bottleneck.

With any other stepper driver, I would suggest turning the power down... Over-powered steppers tend to run hot and aggressive, and lose any gentleness in their movement. In this case, there is no power twiddler to change the motor power. Try turning the voltage down perhaps?

Last thing - vector line drawing internally chops the line into lots of small lines, and draws each one as a wiggle. Smaller lines means smaller wiggles, and apparently straighter lines. You can change the maximum line length (wiggle length) with ctrl+< and ctrl+>, or by editing the default.properties.txt. Press ctrl+i so see the current maximum line length. I thought it was set to something very small like two anyway, but worth double-checking that.

sn

vdrome
Beginner
Posts: 36
Permalink
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 23, 2014, 17:09
Quote

Just for clarification - I have two options for setting up Micro-stepping using the controller software:

1. Increase steps per rev to 3200 leaving the stepMultiplier at 1

or

2. Leave the steps per rev at 200 (the motors native revolution) and increase the stepMultiplier to 16, thus 16 x 200 = 3200

You're right about the voltage, running at 12v (from the power adapter, as there's no trim-pot to the motors) the motors got pretty hot. I bumped the voltage down to around 7-9v and they've cooled off some, but still warm, which is normal.

Didn't know about the changing the "wiggle length", I had no idea that was a thing, so I will try it out too. I really want to try and get as much diminutive detail as I can using vector graphics. I have another question about using the servo, but I'll make a new thread for that.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 23, 2014, 17:33
Quote

That sounds like a good summary. In both cases you can make the changes in the controller and do "upload machine spec". Changing these fundamental units sometimes makes the rest of the machine definition go a bit crazy, so I'd change it in the default.properties.txt and restart, rather than try to change it through the controller interface itself.

I checked, and the wiggle length is called the "max line segment length" in the ctrl-i overlay.

In the default.properties.txt, it's called controller.maxSegmentLength, and has the default value of 2, so I'm sure it won't be anything to do with that. Higher values will be very slightly faster, but not significantly, so I tend not to bother changing it from the default.

It depends, but in general, I've found that pen holder technology, balance, tip friction etc, position of the drawing and speed etc have more bearing on detail than outright resolution. For a 40mm sprocket, 200 steps is a movement of just over half a millimetre, which is usually not far off the thickness of the pen tip anyway.

sn

vdrome
Beginner
Posts: 36
Permalink
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 23, 2014, 17:56
Quote

Speaking of pen holder technology - is there any materials you recommend for holding the pen inside of the brass tube? Right now I've just wrapped some cloth-tape around the end of the pen so it'll fit snug inside of the tube - I bet something like foam tape would help reduce the friction/vibration, though I'm all ears for any new ideas.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 23, 2014, 18:04
Quote

I always just used a pad of blu-tack, until I switched to the jinjawhopper (https://www.thingiverse.com/thing:31973) with a simple foldback clip. In PLA it's a bit fragile, but in nylon it is super.

vdrome
Beginner
Posts: 36
Permalink
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 25, 2014, 01:00
Quote

I changed my stepper settings in the Default properties txt but I'm having some issues with the motors way over shooting the drawing surface and the machine size itself. I have the steps per rev at 200 and multiplier at 16. If I attempt to move the gondola around the drawing surface (which isn't a large area at all) it moves FAR beyond where I expect it should go. It does the same shenanigans if I change the steps per rev at 3200 and multiplier to 1 as well.

Any ideas, below I've pasted my default properties txt. - and for those just catching up on this thread, I'm running an Uno with an Adafruit motorshield v2.

*** Polargraph properties file ***
#Thu Apr 24 19:42:37 EDT 2014
controller.pixel.samplearea=10.0
controller.pictureframe.position.y=190
controller.pictureframe.position.x=190
controller.testPenWidth.startSize=0.5
controller.machine.colour=969696
machine.motors.mmPerRev=95.0
controller.window.width=1350
controller.frame.colour=C80000
controller.image.position.y=178
controller.image.position.x=178
machine.motors.accel=400.0
controller.image.height=119
controller.machine.serialport=0
controller.window.height=668
controller.maxSegmentLength=2
machine.penlift.up=180
machine.penlift.down=90
controller.page.position.y=119
controller.vector.scaling=100.0
controller.page.position.x=387
controller.pictureframe.width=95
machine.step.multiplier=16
controller.grid.size=75.0
controller.testPenWidth.endSize=2.0
controller.pictureframe.height=95
controller.page.colour=DCDCDC
controller.testPenWidth.incrementSize=0.5
controller.image.width=119
machine.motors.stepsPerRev=200
machine.pen.size=0.35
controller.page.width=419
controller.pixel.mask.color=00FF00
controller.machine.baudrate=57600
controller.vector.minLineLength=0
machine.width=1193
controller.page.height=238
controller.vector.position.y=0.0
controller.background.colour=646464
controller.image.filename=
controller.vector.position.x=0.0
controller.homepoint.y=119.0
controller.guide.colour=FFFFFF
machine.motors.maxSpeed=600.0
controller.homepoint.x=597.0
controller.density.preview.style=1
controller.pixel.scaling=1.0
controller.densitypreview.colour=000000
machine.height=914

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 25, 2014, 06:49
Quote

Did you remember to 'upload machine spec' after changing the values in the controller?

vdrome
Beginner
Posts: 36
Permalink
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 27, 2014, 15:28
Quote

Quote from sandy on April 25, 2014, 06:49
Did you remember to 'upload machine spec' after changing the values in the controller?

I did, but I will try again soon and post my results.

vdrome
Beginner
Posts: 36
Permalink
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 27, 2014, 18:09
Quote

Okay I re-uploaded my machine specs to the Uno - still taking an incredible long time to move the pen to certain points on the drawing surface. Here is a screenshot of my "setup" tab in the controller software

Image

Seeing that it's taking 3200 steps per rev - I think that the machine is seeing & moving way more then it should be per rev, but paradoxically we're trying to get it to "microstep" properly by adding more steps per rev, it seems like the machine is making more full 360 degree revolutions than dividing them up in between steps - I don't know if that makes sense, but just telling the machine to move to the home point can take up anywhere between 1-3 minutes!

Small update: I think this could be an issue in the firmware; I actually switched to micro-stepping in the firmware and the motors run incredibly smoother now, however it still takes the machine a very long time to rove to points on the drawing surface: here is my firmware code below, please review:

Polargraph_server_a1

*  Polargraph Server for ATMEGA328-based arduino boards.
*  Written by Sandy Noble
*  Released under GNU License version 3.
*  http://www.polargraph.co.uk
*  http://code.google.com/p/polargraph/

The program has a core part that consists of the following files:

- comms.ino
- configuration.ino
- eeprom.ino
- exec.ino
- penlift.ino
- pixel.ino
- util.ino

and the first portion of the main file, probably called
something like polargraph_server_a1.ino.

CONFIGURATION!! Read this!
==========================

Kung fu is like a game of chess. You must think first! Before you move.

This is a unified codebase for a few different versions of Polargraph Server.

You can control how it is compiled by changing the #define lines below.

Comment the lines below in or out to control what gets compiled.
*/

// Turn on some debugging code
// ===========================
//#define DEBUG

// Program features
// ================
//#define PIXEL_DRAWING
#define PENLIFT
#define VECTOR_LINES

// Specify what kind of motor driver you are using
// ===============================================
// REMEMBER!!!  You need to comment out the matching library imports in the 'configuration.ino' tab too.
#define ADAFRUIT_MOTORSHIELD_V2
//#define ADAFRUIT_MOTORSHIELD_V1


#include <AccelStepper.h>
#include <Servo.h>
#include <EEPROM.h>
#include "EEPROMAnything.h"

/*  ===========================================================  
    These variables are common to all polargraph server builds
=========================================================== */    

const String FIRMWARE_VERSION_NO = "1.7";

// for working out CRCs
static PROGMEM prog_uint32_t crc_table[16] = {
    0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
    0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
    0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
    0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
};

static boolean usingCrc = false;

//  EEPROM addresses
const byte EEPROM_MACHINE_WIDTH = 0;
const byte EEPROM_MACHINE_HEIGHT = 2;
const byte EEPROM_MACHINE_MM_PER_REV = 14; // 4 bytes (float)
const byte EEPROM_MACHINE_STEPS_PER_REV = 18;
const byte EEPROM_MACHINE_STEP_MULTIPLIER = 20;

const byte EEPROM_MACHINE_MOTOR_SPEED = 22; // 4 bytes float
const byte EEPROM_MACHINE_MOTOR_ACCEL = 26; // 4 bytes float
const byte EEPROM_MACHINE_PEN_WIDTH = 30; // 4 bytes float

const byte EEPROM_MACHINE_HOME_A = 34; // 4 bytes
const byte EEPROM_MACHINE_HOME_B = 38; // 4 bytes

const byte EEPROM_PENLIFT_DOWN = 42; // 2 bytes
const byte EEPROM_PENLIFT_UP = 44; // 2 bytes

// Pen raising servo
Servo penHeight;
const int DEFAULT_DOWN_POSITION = 90;
const int DEFAULT_UP_POSITION = 180;
static int upPosition = DEFAULT_UP_POSITION; // defaults
static int downPosition = DEFAULT_DOWN_POSITION;
static int penLiftSpeed = 3; // ms between steps of moving motor
byte const PEN_HEIGHT_SERVO_PIN = 9;
boolean isPenUp = false;

int motorStepsPerRev = 800;
float mmPerRev = 95;
byte stepMultiplier = 1;

static float translateX = 0.0;
static float translateY = 0.0;
static float scaleX = 1.0;
static float scaleY = 1.0;
static int rotateTransform = 0;

static int machineWidth = 650;
static int machineHeight = 800;

static int defaultMachineWidth = 650;
static int defaultMachineHeight = 650;
static int defaultMmPerRev = 95;
static int defaultStepsPerRev = 800;
static int defaultStepMultiplier = 1;

float currentMaxSpeed = 800.0;
float currentAcceleration = 400.0;
boolean usingAcceleration = true;

int startLengthMM = 800;

float mmPerStep = mmPerRev / multiplier(motorStepsPerRev);
float stepsPerMM = multiplier(motorStepsPerRev) / mmPerRev;

long pageWidth = machineWidth * stepsPerMM;
long pageHeight = machineHeight * stepsPerMM;
long maxLength = 0;

//static char rowAxis = 'A';
const int INLENGTH = 50;
const char INTERMINATOR = 10;

static float penWidth = 0.8; // line width in mm

boolean reportingPosition = true;
boolean acceleration = true;

extern AccelStepper motorA;
extern AccelStepper motorB;

boolean currentlyRunning = true;

static String inCmd = "                                                  ";
static String inParam1 = "              ";
static String inParam2 = "              ";
static String inParam3 = "              ";
static String inParam4 = "              ";

byte inNoOfParams;

int rebroadcastReadyInterval = 5000L;
long lastOperationTime = 0L;
long motorIdleTimeBeforePowerDown = 600000L;
boolean automaticPowerDown = false;

long lastInteractionTime = 0L;

#ifdef PIXEL_DRAWING
static boolean lastWaveWasTop = true;

//  Drawing direction
const static byte DIR_NE = 1;
const static byte DIR_SE = 2;
const static byte DIR_SW = 3;
const static byte DIR_NW = 4;

const static byte DIR_N = 5;
const static byte DIR_E = 6;
const static byte DIR_S = 7;
const static byte DIR_W = 8;
static int globalDrawDirection = DIR_NW;

const static byte DIR_MODE_AUTO = 1;
const static byte DIR_MODE_PRESET = 2;
const static byte DIR_MODE_RANDOM = 3;
static byte globalDrawDirectionMode = DIR_MODE_AUTO;
#endif

//static int currentRow = 0;

const String READY = "READY";
const String RESEND = "RESEND";
const String DRAWING = "DRAWING";
const String OUT_CMD_CARTESIAN = "CARTESIAN,";
const String OUT_CMD_SYNC = "SYNC,";

static String readyString = READY;

String lastCommand = "";
boolean commandConfirmed = false;

const static String COMMA = ",";
const static String CMD_END = ",END";
const static String CMD_CHANGELENGTH = "C01";
const static String CMD_CHANGEPENWIDTH = "C02";
const static String CMD_CHANGEMOTORSPEED = "C03";
const static String CMD_CHANGEMOTORACCEL = "C04";
#ifdef PIXEL_DRAWING
const static String CMD_DRAWPIXEL = "C05";
const static String CMD_DRAWSCRIBBLEPIXEL = "C06";
//const static String CMD_DRAWRECT = "C07";
const static String CMD_CHANGEDRAWINGDIRECTION = "C08";
const static String CMD_TESTPATTERN = "C10";
const static String CMD_TESTPENWIDTHSQUARE = "C11";
#endif
const static String CMD_SETPOSITION = "C09";
#ifdef PENLIFT
const static String CMD_PENDOWN = "C13";
const static String CMD_PENUP = "C14";
const static String CMD_SETPENLIFTRANGE = "C45";
#endif
#ifdef VECTOR_LINES
const static String CMD_CHANGELENGTHDIRECT = "C17";
#endif
const static String CMD_SETMACHINESIZE = "C24";
const static String CMD_SETMACHINENAME = "C25";
const static String CMD_GETMACHINEDETAILS = "C26";
const static String CMD_RESETEEPROM = "C27";
const static String CMD_SETMACHINEMMPERREV = "C29";
const static String CMD_SETMACHINESTEPSPERREV = "C30";
const static String CMD_SETMOTORSPEED = "C31";
const static String CMD_SETMOTORACCEL = "C32";
const static String CMD_SETMACHINESTEPMULTIPLIER = "C37";

void setup() 
{
  Serial.begin(57600);           // set up Serial library at 57600 bps
  Serial.print(F("POLARGRAPH ON!"));
  Serial.println();
  configuration_motorSetup();
  eeprom_loadMachineSpecFromEeprom();
  configuration_setup();

  motorA.setMaxSpeed(currentMaxSpeed);
  motorA.setAcceleration(currentAcceleration);  
  motorB.setMaxSpeed(currentMaxSpeed);
  motorB.setAcceleration(currentAcceleration);
  
  float startLength = ((float) startLengthMM / (float) mmPerRev) * (float) motorStepsPerRev;
  motorA.setCurrentPosition(startLength);
  motorB.setCurrentPosition(startLength);
  readyString = READY;
  comms_establishContact();

#ifdef PENLIFT
  penlift_penUp();
#endif
  delay(500);

}

void loop()
{
  lastCommand = comms_waitForNextCommand();
  comms_parseAndExecuteCommand(lastCommand);
}

Here is the Configuration tab (with micro-stepping)

/**
*  Polargraph Server. - CORE
*  Written by Sandy Noble
*  Released under GNU License version 3.
*  http://www.polargraph.co.uk
*  http://code.google.com/p/polargraph/

Configuration.

This is one of the core files for the polargraph server program.  
It sets up the motor objects (AccelSteppers), and has default
values for the motor, sprocket and microstepping combinations used
by polargraphs so far.

Comment out the blocks of code you don't need.

*/
// motor configurations for the various electrical schemes

// =================================================================
// 1. Adafruit motorshield

// Using Adafruit Motorshield V2? Comment out this one line underneath.
//#include <AFMotor.h>

// Using Adafruit Motorshield V1? Comment out the three INCLUDE lines below.
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

#ifdef ADAFRUIT_MOTORSHIELD_V1
const int stepType = INTERLEAVE;
AF_Stepper afMotorA(motorStepsPerRev, 1);
AF_Stepper afMotorB(motorStepsPerRev, 2);

void forwarda() { afMotorA.onestep(FORWARD, stepType); }
void backwarda() { afMotorA.onestep(BACKWARD, stepType); }
void forwardb() { afMotorB.onestep(FORWARD, stepType); }
void backwardb() { afMotorB.onestep(BACKWARD, stepType); }
#endif

#ifdef ADAFRUIT_MOTORSHIELD_V2
const int stepType = MICROSTEP;

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_StepperMotor *afMotorA = AFMS.getStepper(motorStepsPerRev, 1);
Adafruit_StepperMotor *afMotorB = AFMS.getStepper(motorStepsPerRev, 2);

void forwarda() { afMotorA->onestep(FORWARD, stepType); }
void backwarda() { afMotorA->onestep(BACKWARD, stepType); }
void forwardb() { afMotorB->onestep(FORWARD, stepType); }
void backwardb() { afMotorB->onestep(BACKWARD, stepType); }
#endif


AccelStepper motorA(forwarda, backwarda);
AccelStepper motorB(forwardb, backwardb);

void configuration_motorSetup()
{
  // no initial setup for these kinds of motor drivers
}
void configuration_setup()
{
  defaultMachineWidth = 650;
  defaultMachineHeight = 650;
  defaultMmPerRev = 95;
  defaultStepsPerRev = 200;
  defaultStepMultiplier = 16;
#ifdef ADAFRUIT_MOTORSHIELD_V2
  AFMS.begin();  // create with the default frequency 1.6KHz
#endif
  delay(500);
  
}
// end of Adafruit motorshield definition
// =================================================================


sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Towards running a Polargraph with an Adafruit Motorshield V2
on: April 27, 2014, 19:35
Quote

I did the exact same thing - changed all the settings but forgot to actually upload the firmware. Well, so upon loading the MICROSTEP'd firmware, indeed, it's slow as molasses. Seems even less than 16 times slower actually, but difficult to tell. Pushing the speed right up to 20,000+ didn't seem to make any difference.

Based on http://forums.adafruit.com/viewtopic.php?f=31&t=42477, I changed my I2C bus speed up to 400kHz, and also pushed the AFMS frequency to 4000 (AFMS.begin(4000);), and that actually made some improvement to the speed. Almost to a reasonable speed for a small machine, but it'll still take hours to get anything done on a big one. However it at least allowed the general polargraph maxspeed setting to seem to make a difference.

I think this is a fundamental problem with a) arduino b) using I2C as the communication bus and c) microstepping.

Solve a: use a different board (eg chipkit uno32),
Solve b: use a v1 motorshield or drive motor drivers directly
Solve c: Use a shield where microstepping can be adjusted, or don't use microstepping.

None of which are very helpful, sorry!
sn

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