Go to Post Push the envelope a little, but not too much. There's a difference between being on the cutting edge and being on the bleeding edge. - cadandcookies [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 6 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 12-07-2013, 10:52
cad321 cad321 is offline
Jack of all trades, Master of none
AKA: Brian Wagg
FRC #2386 (Trojans)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Burlington, Ontario
Posts: 348
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
Arduino Mecanum drive using PWM?

I have been trying to program an Arduino Uno to take PWM signals from a spectrum RC receiver and mix those signals to control 4 motors on a mecanum drive bot. Although I don't have the bot built/designed yet I have been trying to get some of the code working. My issue is that when ever I try to use more than one pulseIn command it adds about 1 second of lag per pulseIn command. I am controlling a servo through this setup.

The code:
Code:
#include <Servo.h>

Servo FLS; //front left servo
Servo FRS; //front right servo...
Servo RLS;
Servo RRS;
int Forward = 1; //Inputs from RC receiver
int Strafe = 2;  
int Rotate = 3;  
unsigned long ForwardDuration; //To store the duration of the pulses
unsigned long StrafeDuration;    //coming from the receiver
unsigned long RotateDuration;
unsigned long FL; //Front Left Value
unsigned long FR; //Front Right Value...
unsigned long RL;
unsigned long RR;

void setup()
{
  FLS.attach(10);
  FRS.attach(11);
  RLS.attach(12);
  RRS.attach(13);
  pinMode(Forward, INPUT);
  pinMode(Strafe, INPUT);
  pinMode(Rotate, INPUT);
}

void loop()
{
  ForwardDuration = pulseIn(Forward, HIGH); //read receiver inputs
  StrafeDuration = pulseIn(Strafe, HIGH);
  RotateDuration = pulseIn(Rotate, HIGH);
  FL = ForwardDuration + StrafeDuration + RotateDuration;
  FR = ForwardDuration - StrafeDuration - RotateDuration;
  RL = ForwardDuration - StrafeDuration + RotateDuration;
  RR = ForwardDuration + StrafeDuration - RotateDuration;
  FLS.writeMicroseconds(FL);
  FRS.writeMicroseconds(FR);
  RLS.writeMicroseconds(RL);
  RRS.writeMicroseconds(RR);  
}
My initial thought was to add interrupts but I'm not exactly sure how to do that.

My attempt at using Interrupts:
Code:
#include <Servo.h>

Servo FLS; //front left servo
Servo FRS; //front right servo...
Servo RLS;
Servo RRS;
int Forward = 1; //Inputs from RC receiver
int Strafe = 2;  
int Rotate = 3;  
volatile unsigned long ForwardDuration; //To store the duration of the pulses
volatile unsigned long StrafeDuration;    //coming from the receiver
volatile unsigned long RotateDuration;
volatile unsigned long FL; //Front Left Value
volatile unsigned long FR; //Front Right Value...
volatile unsigned long RL;
volatile unsigned long RR;

void setup()
{
  attachInterrupt(0, reciever, CHANGE);
  FLS.attach(10);
  FRS.attach(11);
  RLS.attach(12);
  RRS.attach(13);
  pinMode(Forward, INPUT);
  pinMode(Strafe, INPUT);
  pinMode(Rotate, INPUT);
}

void loop()
{
  FLS.write(FL);
  FRS.writeMicroseconds(FR);
  RLS.writeMicroseconds(RL);
  RRS.writeMicroseconds(RR);
}
void reciever()
 {
  ForwardDuration = pulseIn(Forward, HIGH); //read receiver inputs
  StrafeDuration = pulseIn(Strafe, HIGH);
  RotateDuration = pulseIn(Rotate, HIGH);

  FL == ForwardDuration + StrafeDuration + RotateDuration;
  FR == ForwardDuration - StrafeDuration - RotateDuration;
  RL == ForwardDuration - StrafeDuration + RotateDuration;
  RR == ForwardDuration + StrafeDuration - RotateDuration;
 }
The reason I am posting here and not on the Arduino forums is that it wont load on my computer right now so I thought I'd try my shot with CD and see if anyone here could help.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 22:38.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi