Hi All,
I have been stumped on this programming or hardware problem for many days now, and hope i can get some assistance to get things up and running.
I am using the below pair of Superheterodyne 433mhz TX and RX units to make a skid steering tracked robot. I've been able to successfully use code to make a full-forward/full-reverse robot, when the analog joysticks are pushed. But when i tried to implement a completely new code to give each motor proportional speed, the robots behaviour is erratic and does not correspond to the joystick movement. I am able to Serial Print the data of the receiver (on the robot), and it prints the joystick data perfectly, accurately, and responsively. But when i change the code to analogwrite those values to the motor driver pins, i don't get the expected motor behaviour.
It seems as if the robot first responds correctly, for about a second or two, to the first direction i push the joystick in. So if i push the joystick a bit forward, then full forward, the motor will move slow then fast. When i release the joystick, the motor will continue to move forward?! and then when i pull full back, the motor will stop. when i let go of the joystick, the motor will move forward and/or stop when it feels like it.
Its as if either the Tx or Rx arudinos are getting frazzled after a second of joystick input and not able to keep up with the data flow? I've compensated for the joystick deadzone (using another sketch) and added delays to slow things down, to no avail.
I have a hunch that since the Tx and Rx modules are not the mainstream ones that are now sold, perhaps these may not be right for this application. The below code I'm now working with is taken from https://www.dipmicro.com/store/RF315PAIR, and i've changed it slightly to read one joystick and write to one motor...and even with this new code, i'm still encountering the same problem.
If anyone can point me in the direction of Arduino skid steering code, using the cheap 315mhz/433mhz modules, it would be greatly appreciated.
I've searched the internet hi and low, and I can't find any arduino skid steering code using these modules, and have reached a dead end in my project.
Thanks in advance for the help! Or if anyone notices any errors in the code, please feel free to point them out!
Transmitter Code
#include <VirtualWire.h>
/* Digital IO pin that will be used for sending data to the transmitter */
const int TX_DIO_Pin = 12;
void setup()
{
pinMode(13, OUTPUT);
/* Initialises the DIO pin used to send data to the Tx module */
vw_set_tx_pin(TX_DIO_Pin);
/* Set the transmit logic level (LOW = transmit for this
version of module)*/
vw_set_ptt_inverted(true);
/* Transmit at 2000 bits per second */
vw_setup(2000); // Bits per sec
}
/* Main program */
void loop()
{
/* Temporarily holds the value read from analogue input A0 */
unsigned int Data;
/* The transmit buffer that will hold the data to be
transmitted. */
byte TxBuffer[2];
/* Read the analogue input A0... */
Data = analogRead(A0);
/* ...and store it as high and low bytes in the transmit
buffer */
TxBuffer[0] = Data >> 8;
TxBuffer[1] = Data;
/* Turn on the LED on pin 13 to indicate that we are about
to transmit data */
digitalWrite(13, HIGH);
/* Send the data (2 bytes) */
vw_send((byte *)TxBuffer, 2);
/* Wait until the data has been sent */
vw_wait_tx();
/* Turn off the LED on pin 13 to indicate that we have
now sent the data */
digitalWrite(13, LOW);
/* Do nothing for a second. Lower this delay to send
data quicker */
delay(10);
}
Receiver Code
#include <VirtualWire.h>
int LeftForward = 3;
int LeftReverse = 5;
/* Digital IO pin that will be used for receiving data from the receiver */
const int RX_DIO_Pin = 8;
void setup()
{
pinMode(13, OUTPUT);
//Serial.begin(9600);
pinMode(LeftForward, OUTPUT); // set OUTPUT mode for output pins
pinMode(LeftReverse, OUTPUT);
//digitalWrite(RX_DIO_Pin,HIGH); //turn on pullup resistor for RXpin
vw_set_rx_pin(RX_DIO_Pin);
vw_setup(2000);
vw_rx_start();
}
/* Main program */
void loop()
{
/* Set the receive buffer size to 2 bytes */
uint8_t Buffer_Size = 2;
/* Holds the recived data */
unsigned int Data;
/* The receive buffer */
uint8_t RxBuffer[Buffer_Size];
/* Has a message been received? */
if (vw_get_message(RxBuffer, &Buffer_Size)) // Non-blocking
{
/* If so, then turn on the LED connected to DIO 13
to indicate this */
digitalWrite(13, HIGH);
/* Store the received high and low byte data */
Data = RxBuffer[0] << 8 | RxBuffer[1];
/* Output this data to the UART */
//Serial.print("Analogue pin A0: ");
// Serial.println(Data);
if (Data <= 507){
Data = map(Data, 507,0, 0, 254);
analogWrite(LeftForward,Data);
}
if (Data >= 517){
Data = map(Data, 517,1023, 0, 254);
analogWrite(LeftReverse,Data);
}
/* Turn off the LED on pin 13 to indicate that the
data has now been received */
digitalWrite(13, LOW);
delay(10);
}
}