Dec 2, 2013: Remote control Shark

Here is a forum for all the students of the i.am.angel Robotics class. Please feel free to post your projects as we go thru the semester.

Dec 2, 2013: Remote control Shark

Postby Tim Laren » Tue Dec 03, 2013 1:27 am

You have all the pieces, now put them together.

I have modified the JoyStick Sketch and added the radio link to it so it sends out motor speed parameters.
Here it is:
Code: Select all
// nRF24L01 Linrary stuff
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
All the includes
Code: Select all
// Hardware configuration
// SPI on UNO  SCK - 13, MOSI - 12, MISO - 11 SS - 10 (leave open)
// SPI on MEGA MOSI - 51, SCK - 52, MISO - 50 SS - 53 (leave open)
// Set up nRF24L01 radio on SPI bus plus pins A0 & A1 (CE & CS)
RF24 radio(8,9);
Setup the radio.
Code: Select all
// Topology
// Radio pipe addresses for the nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0D1LL, 0xF0F0F0F0C2LL};
Name the pipes.
Code: Select all
uint8_t motorSpeed[2];  // Right and left motor speed from Radio
uint8_t motorSpeedSize = sizeof(motorSpeed);

const int joyX   = 0;
const int joyY   = 1;
const int Button = 2;
const int LED    = 13;

int X;
int Y;
Misc constants and variables.
Code: Select all
void setup()
{
  Serial.begin(9600);
  printf_begin();
  Serial.println("Radio Joy Stick");
  pinMode(Button, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
Display Stuff
Code: Select all
  radio.begin();

  // optionally, increase the delay between retries & # of retries
  radio.setRetries(15,15);

  // optionally, reduce the payload size.  seems to improve reliability
  radio.setPayloadSize(motorSpeedSize);
Radio configuration
Code: Select all
  //
  // Open pipes to other nodes for communication
  //
  radio.openReadingPipe(0,pipes[1]);

  radio.openWritingPipe(pipes[0]);
  radio.startListening();
  radio.printDetails();
}
Open the piped and start listening
Code: Select all

void loop()
{
  int R;
  int L;
  int But = digitalRead(Button);
  digitalWrite(LED, But);
  X = map(analogRead(joyX),0,1023,-100,100);
  Y = map(analogRead(joyY),0,1023,-100,100);
Read the stick, convert to +-100 (Easier to work with)
Code: Select all
  if ( (X > 10) || (X < -10))
  {
    R = X;
    L = X;
  }
  if ( Y > 10 )
  {
    L = L + Y;
    R = R - Y;
  }
  if ( Y < -10 )
  {
    L = L - Y;
    R = R + Y;
  }
  if(L > 255) L = 255;
  if(R > 255) R = 255;
  if(L < -255) L = -255;
  if(R < -255) R = -255;
Convert joystick position to motor speed values
Code: Select all
  motorSpeed[0] = L;
  motorSpeed[1] = R;
  /*
  Serial.print("X:");
  Serial.print(X);
  Serial.print(", Y:");
  Serial.println(Y);
  */
  Serial.print("L:");
  Serial.print(L);
  Serial.print(", R:");
  Serial.println(R);
Display values
Code: Select all
  radio.stopListening();
  printf("Now sending...");
  bool ok = radio.write( motorSpeed, motorSpeedSize );
  if (ok)
    printf("ok\n\r");
  else
    printf("failed\n\r");
  radio.printDetails();

  radio.startListening();
  delay(100);
}
Stop listening so we can transmit, transmit then re-enable listening.

I used pins 8 and 9 for CE and CSN.

Load it up and it should start sending motor values. When the second sketch is loaded into the Shark, you can drive it.
Image
Tim Laren
Site Admin
 
Posts: 135
Joined: Thu Mar 04, 2010 8:25 pm

Re: Dec 2, 2013: Remote control Shark

Postby dolumekeqa » Sat Sep 08, 2018 1:48 am

The hanger of the new tinge is done for the possible means. The ironic use of the best essay writing reviews has been done for the completion of the paper and all such issues for the persons.
dolumekeqa
 
Posts: 1
Joined: Sat Sep 08, 2018 1:47 am


Return to i.am.angel Robotics

Who is online

Users browsing this forum: No registered users and 1 guest

cron