Tuesday, August 18, 2009

Laziness

Well it's been a while since I posted, if I'm going to bugger off after only 6 posts I'm probably going to end up doing it again at some point. Anyways! have been working on projects even if I haven't been updating on them.

So hexapod is on hold until I can get some beefier servos but have managed to get a hold of a power wheelchair at long last (I have been after one of these for a while). It's an old one so it doesn't have a 2nd joystick port on it so to get it controlable from an arduino/pc took some work.

The control box is there on the left hand side, it was an old Dynamic which died shortly after I got it so I'm not going into the control system I tried to use since I can only assume I managed to kill the it.

I managed to get a replacement though (don't know who made it). The problem with this new one was that the arduino wasn't able to simulate the output from the joystick on its own.

You can see that the joystick is just two potentiometers at right angles to each other, the difference with this 2nd setup is that the pots are positioned 45 degrees off the direction of travel. It means that each pot is in direct control of one of the motors, from my point of view it makes the code a lot easier. But the way that the rest of the control box uses the current flowing through the joystick means that the arduino can't do it on its own. In the end I decided to use a MCP42100 digital potentiometer ic to simulate the two potentiometers, that only left the problem of controlling the MCP.

The MCP code was pretty easy once I got my head round it. It's an SPI bus device. Credit to http://little-scale.blogspot.com/2008/05/four-midi-controlled-digital-pots-via.html and http://www.arduino.cc/en/Tutorial/SPIDigitalPot.

But here is the code.
#define SS 2
#define CLK 4
#define MOSI 3

byte pot0 = B00010001; // write to pot 0
byte pot1 = B00010010; // write to pot 1
byte pots = B00010011; // write to both

void setup()
{ Serial.begin( 9600 );

pinMode( SS, OUTPUT );
pinMode( CLK, OUTPUT );
pinMode( MOSI, OUTPUT );

digitalWrite( SS, HIGH );
digitalWrite( CLK, HIGH );

set_mcp_pot( pots, potval );
}

void loop()
{ set_mcp_pot( pot0, 255 );
delay( 3000 );

set_mcp_pot( pot1, 255 );
delay( 3000 );

set_mcp_pot( pots, 0 );
delay( 3000 );
}

void set_mcp_pot( byte pot, byte val )
{ digitalWrite( SS, LOW );

spi_transfer( pot );
spi_transfer( val );

digitalWrite( SS, HIGH );
}

void spi_transfer( byte working )
{ int i;

digitalWrite( CLK, LOW );

for( i=1; i<=8; ++i ) { if( working > 127 )
digitalWrite( MOSI, HIGH );
else
digitalWrite( MOSI, LOW );

digitalWrite( CLK, HIGH );
working = working << 1;
digitalWrite( CLK, LOW );
}
}

I have also managed to get it working with the digital compass to do the heading following that I wanted. I'll post that code later once I've checked the wheelchair batteries, I think they are having issues now....

No comments:

Post a Comment