Monday 20 June 2016

Wheelchair hacking part 2 (running under RC now)

Got home from work yesterday and promptly drove the wheelchair over beside the kitchen table and loaded it up with my laptop, oscilloscope, couple multimeters, notepad and all the other random stuff you need for a bit of hardware hacking:
I don't have any proper oscilloscope probes, so I just cut a BNC patch cable in half and then soldered a couple twisted pairs from a CAT5 cable to the ends. I'm not using them for any really sensitive low voltage applications or high frequency stuff so no sheilding and whatnot is totally fine.
In my previous research I found a couple of sites that have the pinout and some other data on either the joystick that came with the wheelchair, so figuring out which wires are what was pretty easy. (Ill post a list of the links I found helpful in my wanderings at the end of this post)  I hooked one of the two outputs from both the X and Y axes to the oscilloscope and flicked her on:
Everything seemed in order, it was working just as expected. I also realized that my oscilloscope can use the two channels as an X/Y plotter. Here is a video of what that looks like. Note that the joystick has a circular range of motion:
With that done, I turned my attention to the Arduino. Got some really basic code up and running that takes the signals from an RC transmitter and maps them to values that the DACs accept and then sends it to them. The DACs output a voltage in proportion to the transmitter's joystick. Heres a video of that one. Note that the Tx has a square range of motion. I wasn't sure how that was going to affect everything but it turned out fine:
Now that I knew the signals that I needed to emulate, I just spent a bit of time with the oscilloscope, one channel hooked up to the original joystick and one channel hooked up to the DAC's output, making sure I ended up always inside the original joystick's envelope for the X and Y axes. It would have been nice to have a 4 channel scope while I was doing that, but I made do. Once I had a good match from the RC stick to the original joystick, I shut everything off, disconnected the direction wires from the joystick (Left it with power and the center signal because the controller board needs to see that.) and connected them to the DACs.
I didn't want to just put both inputs from each channel together on the same output from the DAC because I assumed (and read elsewhere on the net) that the control board has some logic that detects that and locks out. So all I did was connect the DAC output to the anode of two diodes, and one channel to each of the cathode. Aside from the voltage drop across the diodes that made me run thru the whole process of connecting the scope up and matching the signals again, this has been working perfectly and only requires me use one DAC for steering and one for throttle.
Here it is all connected and spread out on the table:
And transfered over to the top of the chair:
Because I didn't want over a hundred pounds of metal and plastic putting a hole in my house from going haywire, I gave it a quick test with the clutches disengaged on the chair:
That went so well I engaged the clutches and drove it around the kitchen a little:
But wheelchairs, and this whole project, were designed to be driven outside not inside! So I drove it down the sidewalk to the local park (by now it was past midnight, so the lighting was not so great, fortunately the park has some streetlamps in the parking lot.) and put it thru its paces:
Once I got back home I just started cleaning the wiring up a bit. I routed the joystick connector outside the joystick case, made a little cover for the hole out of some sheet metal and hot glued in all in place. Hot glue is great cause its pretty strong and is waterproof. So once I got the control box screwed back together, it regained its water resistant status:
Tidied the wiring sitting on the top of the wheelchair up a bit:
And heres a closeup of the electronics that make it run. The UNO clone provides power is connected over I2C to the two DACs on the right side of the breadboard. Those provide the voltage out, which is fed over the brown and white twisted pair to the other side of the board, thru the diodes and to the wheelchair control box. The ribbon cable out the bottom goes to the wheelchair box and the wires coming out the top go to the joystick.
Since I got it all working and controlled by an RC transmitter, the next logical thing to do was tie down strap my snowboard onto the top of the chair and go for a rip around the neighbourhood.




I got more than one strange look but I had a lot of fun. Anyways thats all Ive got for now, next up is building a failsafe/joystick isolation board for a bit of safety and allowing me to seperate the added electronics from the original wheelchair electronics.

PS:
Realized after I published this post I said I would post all the useful links that I have found. Well here they are:
This one to a Stackexchange page asking pretty well what I want to know
This 2 page forum post that the Stackexchange post gets its info from
This interesting instructables post
This page from the manufacter of the joystick that shows you how to enter calibration mode
Product page for the DACs that I am using
And last but not least Adafruit's awesome tutorial with library for the DACs

One last thing. Here is a copy and paste of the code I have running right now on the arduino:

#include <Wire.h>
#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 steeringout;
Adafruit_MCP4725 speedout;

int speedin;
int steeringin;

void setup(void)
{
  pinMode(5, INPUT);
  pinMode(6, INPUT);
 
  Serial.begin(9600);
 
  steeringout.begin(0x62);
  speedout.begin(0x63);
}

void loop(void)
{
  steeringin = pulseIn(5, HIGH, 25000);
  speedin = pulseIn(6, HIGH, 25000);

  speedin = map(speedin,1035,1875,1310,3522);
  steeringin = map(steeringin,1035,1875,1310,3522);

  Serial.print(speedin);
  Serial.print("    ");
  Serial.println(steeringin);
 
  speedout.setVoltage(speedin, false);
  steeringout.setVoltage(steeringin, false);

  delay(1);
}

Thats it, thats all folks!

No comments:

Post a Comment