Joystick + RC + Autonomous !...crikey
// Notes
// This sketch was tweaked to operate BRUSHED X-45 Hobby King ESC from a car.
// To operate winch motors on a disabled sailing dinghy.
// == The different limit values for the Nunchuck are deliberate.
// compensating for the ESC's 50% reduction in power when in 'reverse'
// Values from the wii nunchuck were also a little erratic in reverse,
// The if , if else , statements also helped with this.
// As this particular ESC reads neutral immediately upon start up
// and the Adruino is powered from the esc, the mapping was the only way to get neutral reliably.
// This Sketch was written for Sailability Gold Coast by Tony Matthews with
// Help from 'AustinDavid' – endless sphere forums./ Help from 'AustinDavid' – endless sphere forums.
#include <Wire.h>
#include <Servo.h>
#include <wiinunchuk.h>
Servo escnine; // Electronic Speed Controller One declaration
Servo escfive; // Electronic Speed Controller Two declaration
int neu = 128; // default zero value for X, Y axis
void setup(void)
{
nunchuk_init();
delay(50);
nunchuk_calibrate_joy();
delay(20); //wait until the esc starts in case of Arduino got power first
escnine.attach(9, 300, 2000); // attaches the esc to digital pins and
escfive.attach(5, 300, 2000); // sets max values and the neutral area
delay (1000); // Arming section
escnine.write(neu); // Write neutral value.
delay(20);
Serial.begin(57600);
}
void loop() {
nunchuk_get_data(); // receives 6 data bytes from controller
Serial.print("X = ");
Serial.print(nunchuk_cjoy_x());
Serial.print(" Y = ");
Serial.println(nunchuk_cjoy_y());
// Stabilize Wii output and
// set Max values for Wii X to counter the esc 50% reduction in reverse
if (nunchuk_cjoy_x() <= 75)
escnine.write(75);
else if (nunchuk_cjoy_x() >= 155)
escnine.write(155);
else {
escnine.write(nunchuk_cjoy_x());
}
// Stabilize Wii output and
// set Max values for Wii Y to counter the esc 50% reduction in reverse
if (nunchuk_cjoy_y() <= 75)
escfive.write(75);
else if (nunchuk_cjoy_y() >= 155)
escfive.write(155);
else {
escfive.write(nunchuk_cjoy_y());
}
delay(20); // ESCs will only change every 20ms
}
//end code /*
Written by: Mujahed Altahle
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
*/
/* A simple Project for Remote Controlling with nRF24L01+ radios.
We have 2 nodes, the transmitter (this one) and the receiver which is attached to the Car.
The idea is to transmit 2 parameters , one is Direction (Backward, or Forward with the speed) the other is the Steering (Left, or Right with the degree of rotation).
The nRF24L01 transmit values in type of "uint8_t" with maximum of 256 for each packet, so the values of direction is divided by (10) at the Tx side,
then it is multiplied by 10 again at the Rx side.
The Rx rules is to output the received parameters to port 3 and 6 where the Servo and the ESC are are attached
a condition is required to prevent the controller from transmitting values that is not useful (like 1480-1530 for ESC and 88-92 for Servo) to save more power as much as we can
*/
#include <Servo.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
//
// Hardware configuration
//
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);
Servo servo; //steering servo declaration
Servo esc; // Electronic Speed Contoller declaration
// Single radio pipe address for the 2 nodes to communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL;
//
// Payload
//
uint8_t received_data[2];
uint8_t num_received_data =sizeof(received_data);
//
// Setup
//
void setup(void)
{
delay(3000); //wait until the esc starts in case of Arduino got power first
servo.attach(3); // attaches the servo on pin 3 to the servo object
esc.attach(6); // attaches the ESC on pin 6 to the ese object
servo.write(90);
//
// Print preamble
//
Serial.begin(57600);
printf_begin();
//
// Setup and configure rf radio
//
radio.begin(); //Begin operation of the chip.
// This simple sketch opens a single pipes for these two nodes to communicate
// back and forth. One listens on it, the other talks to it.
radio.openReadingPipe(1,pipe);
radio.startListening();
//
// Dump the configuration of the rf unit for debugging
//
radio.printDetails();
}
void loop(void)
{
// if there is data ready
if ( radio.available() )
{
bool done = false;
int ESC_value;
while (!done)
{
// Fetch the payload, and see if this was the last one.
done = radio.read( received_data, num_received_data );
ESC_value=received_data[0]*10; //Multiplication by 10 because the ESC operates for vlues around 1500 and the nRF24L01 can transmit maximum of 255 per packet
esc.writeMicroseconds(ESC_value);
// Serial.println(ESC_value);
servo.write((received_data[1]));
// Serial.println(received_data[1]);
}
}
}
/*
Written by: Mujahed Altahle
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
*/
/* A simple Project for Remote Controlling with nRF24L01+ radios.
We have 2 nodes, the transmitter (this one) and the receiver which is attached to the Car.
The idea is to transmit 2 parameters , one is Direction (Backward, or Forward with the speed) the other is the Steering (Left, or Right with the degree of rotation).
The nRF24L01 transmit values in type of "uint8_t" with maximum of 256 for each packet, so the values of direction is divided by (10) at the Tx side,
then it is multiplied by 10 again at the Rx side.
The Rx rules is to output the received parameters to port 3 and 6 where the Servo and the ESC are are attached
a condition is required to prevent the controller from transmitting values that is not useful (like 1480-1530 for ESC and 88-92 for Servo) to save more power as much as we can
*/
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
//
// Hardware configuration
//
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);
uint8_t data[2] ; //buffer to store received data
const uint8_t buffer_size = sizeof(data);
//pins that used for the Joystick
const int analogInPinY= A0; //
const int analogInPinX = A1;//
const int tx_led=2;// transmission indicator
int Y_value = 0; // values read from the pot
int X_value = 0;
int outputValue = 0;
/*
const int transmit_pin=6;
int transmit_enable;
int ForwrdButton=2;
int BackwrdButton=3;
*/
//
// Topology
//
// Single radio pipe address for the 2 nodes to communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL;
//
// Setup
//
void setup(void)
{
Serial.begin(57600);
printf_begin();
//
// Setup and configure rf radio
//
radio.begin();
radio.openWritingPipe(pipe);
//
// Dump the configuration of the rf unit for debugging
//
radio.printDetails();
//
// Set up buttons
//
/*to be used later
pinMode(ForwrdButton,INPUT );
pinMode(BackwrdButton,INPUT);
pinMode(transmit_enable,INPUT);
*/
pinMode(tx_led,OUTPUT);
digitalWrite(tx_led,LOW);
}
//
// Loop
//
void loop(void)
{
X_value = analogRead(analogInPinX);
data[0] = map(X_value, 0, 1023,100 , 200);
Y_value = analogRead(analogInPinY);
data[1] = map(Y_value, 0, 1023, 135, 45);
// transmit_enable=!digitalRead(transmit_pin);
//an error ratio around +3,-3 appears coming from the Joystick all the time,
//so we neglect them (using the following if statement) because they make the system transmitting data always and they are useless and waste of power
if((data[0]>153 || data[0] <=149) || (data[1]>=92 || data[1]<88))
{
//printf("Now sending...");
bool ok = radio.write( data, buffer_size );
//if (ok)
printf("ok\n\r");
// else
printf("failed\n\r");
// delay(15);
digitalWrite(tx_led,HIGH); //turn led on after transmission
}
else digitalWrite(tx_led,LOW);//keep led off when no transmission
}
gcebiker wrote:Cant plug the Arduino directly into the XLR connector...28.8v![]()
I've a Wizard Cable for the DX, i guess it has a Logic Level Converter so the High volts at the XLR charging port dont fry the USB ports on your PC ?
Doug how did you connect your Gravis/Arduino to the XLR, a LLC ?
Ive a bunch of JST Balance leads (for balance charging RC LiPo batteries), will investigate soldering directly to board.
Its my hope that eventually there will be a bunch of 'include' files for Arduino library, one for each type of controller as they come along.






I also hope (if i can get this first one going) to put some ultrasonic sensors on another powerchair/Arduino to help some mates with brain injuries get about+
...with out taking out the skirting boards all around the house.

Connect pin 5 (the clock, or SCL, pin) and pin 4 (the data, or SDA, pin) on the master Arduino to their counterparts on the slave board. Make sure that both boards share a common ground. In order to enable serial communication, the slave Arduino must be connected to your computer via USB.

There is no need to connect the 28V to your control rig, you just need the ground to make sure the signal levels of the Arduino controller are referenced from the same point as the power base controller.
As for it not doing anything, it's tough to say, can you read the code(and know what it's doing)? One thing I know you'd want to do is zero the joy stick you have connected. Then you'd want to trigger the initialization sequence to be run. IIRC, the LED is a joystick centering indicator so you should be seeing that LED going on/off when you move the joystick off of center and then back to center. And if your joystick does not go back to exactly the same spot, you might have to change the Zero'ing offset value. I think it was set to 10 for the Gravis stick which seemed to be off by around 5-7 through various tests of moving the stick and then releasing it and watching where it centers.
You are going to want more than one button, if I read your reply correctly you stated you only have one button implemented.... The code lists the buttons and the pins I used for those buttons.
Another thing I noticed was you don't seem to have the TX line connected and I don't know why you wouldn't do that since it is how the whole thing works, ie sends a serial byte stream to the power base controller.
gcebiker wrote:There is no need to connect the 28V to your control rig, you just need the ground to make sure the signal levels of the Arduino controller are referenced from the same point as the power base controller.
Cool got that bit right.As for it not doing anything, it's tough to say, can you read the code(and know what it's doing)? One thing I know you'd want to do is zero the joy stick you have connected. Then you'd want to trigger the initialization sequence to be run. IIRC, the LED is a joystick centering indicator so you should be seeing that LED going on/off when you move the joystick off of center and then back to center. And if your joystick does not go back to exactly the same spot, you might have to change the Zero'ing offset value. I think it was set to 10 for the Gravis stick which seemed to be off by around 5-7 through various tests of moving the stick and then releasing it and watching where it centers.
Chairs not moving but i can see it writing data on the serial monitor port of the IDE (sometimes i power it from there instead of the battery). Ill change to a larger Joystick , this ones just to tiny to be accurate in all likely hood.
I am ok with the code, as you have great notes, just was not sure which Digital pins were witch.You are going to want more than one button, if I read your reply correctly you stated you only have one button implemented.... The code lists the buttons and the pins I used for those buttons.
One Joystick just for now while i am in testing.Another thing I noticed was you don't seem to have the TX line connected and I don't know why you wouldn't do that since it is how the whole thing works, ie sends a serial byte stream to the power base controller.
Oh, i originally had it hooked up, Digital 11 and TX but thought i read the code wrong and switched it to D11 and D13
I'll be switching my input joystick over to a full size wheelchair joy with much stronger springs and seeing how it goes re:center values.
SOB.... I just spent 45 minutes commenting item by item referencing my code to be specific etc and finally hit preview and the forum made me log back and it dumped all my comments... crap...
Burgerman wrote:SOB.... I just spent 45 minutes commenting item by item referencing my code to be specific etc and finally hit preview and the forum made me log back and it dumped all my comments... crap...
Depends on browser. With most just click back. "Copy" log in, then "paste"...


DougL wrote:Burgerman wrote:SOB.... I just spent 45 minutes commenting item by item referencing my code to be specific etc and finally hit preview and the forum made me log back and it dumped all my comments... crap...
Depends on browser. With most just click back. "Copy" log in, then "paste"...
yes, I did use the back button but never saw any indicator to repost the data or anything, just the original msg. I'm using Chrome. From now on, if the reply is long then I will open another window to be sure I'm still logged in and haven't timed out.
Maybe the issue was with my hitting the Preview option instead of Submit. I'd mucked with lots of quote/unquoting so wanted to see if I missed anything before submitting.
ex-Gooserider wrote:I don't know if it's available for Chrome, but an addin that I have for Firefox called 'Lazarus' is a real life-saver in situations like this... Essentially it saves anything you put in a form for the last several entries, and allows easy one click recovery of lost info... Doesn't work on everything, partly because of the cute tricks that some places use, but it's almost always things that you really don't want to have recoverable, like passwords, credit card numbers and so on.... Very highly recommended!....
ex-Gooserider

// Wii Nunchuck 2.4ghz wireless to PWM out on pins 3,6. Digital to D4
// will need different wiinunchuck library for middle joy button for on off.
// intent, Joy button = on off, Joy xy = pwm output for second arduino
// Joy C = Speed up, Joy Z = speed down
// Outputs at testing show second arduino with swinging values
// may need to add some hardware or software smoothing of values or sending data differently
#include <Wire.h>
#include <wiinunchuk.h>
// Map and name pins
const int analogOutPin3 = 3 ; // PWM output value from wii Receiver
const int analogOutPin6 = 6 ; // PWM output value from Wii Receiver
const int digitalOutPin4 = 4 ; // Digital On/Off from Wii Joy thumbstick button.
int outputValue3 = 0;
int outputValue6 = 0;
void setup(void)
{
nunchuk_init();
delay(50);
nunchuk_calibrate_joy();
//delay(20); //wait until the not Arduino's get power ? Maybe not necessary
Serial.begin(57600);
}
void loop() {
nunchuk_get_data(); // receives 6 data bytes from controller
outputValue3 = map(nunchuk_cjoy_x(),0,1023,0,255);
outputValue6 = map(nunchuk_cjoy_y(),0,1023,0,255);
// finish this on/of line // outputValueD4 = (nunchuck_cjoy_
// Write Wii Data to appropriate Output port
analogWrite(analogOutPin3,outputValue3);
analogWrite(analogOutPin6,outputValue6);
//digital write Boolean for on off value, note to self complete this line.
// Print Debug Data to Serial Monitor
Serial.print("X = ");
Serial.print(nunchuk_cjoy_x());
Serial.print(" , A3 Output = ");
Serial.print(outputValue3);
Serial.print(" || Y = ");
Serial.print(nunchuk_cjoy_y());
Serial.print(" , A6 Output= ");
Serial.println(outputValue6);
}
Return to Everything Powerchair
Users browsing this forum: emilevirus, Kande_ian, LROBBINS, ricardoh, tettralytic and 86 guests