2dof sim code

Running simulator build projects.
Please use the image gallery for your pictures, a short tutorial can be found here.
The first image in the first post will be shown in the project gallery.

2dof sim code

Postby volkantopc » Mon 29. May 2017, 20:05

Arduino code for dynamic playseat 2DOF
*/

#define BRAKEVCC 0
#define RV 2 //beware it's depending on your hardware wiring
#define FW 1 //beware it's depending on your hardware wiring
#define STOP 0
#define BRAKEGND 3

////////////////////////////////////////////////////////////////////////////////
#define pwmMax 255 // or less, if you want to lower the maximum motor's speed

// defining the range of potentiometer's rotation
const int potMini=208;
const int potMaxi=815;

////////////////////////////////////////////////////////////////////////////////
#define motLeft 0
#define motRight 1
#define potL A0
#define potR A1

////////////////////////////////////////////////////////////////////////////////
// DECLARATIONS
////////////////////////////////////////////////////////////////////////////////
/* VNH2SP30 pin definitions*/
int inApin[2] = {
7, 4}; // INA: Clockwise input
int inBpin[2] = {
8, 9}; // INB: Counter-clockwise input
int pwmpin[2] = {
5, 6}; // PWM input
int cspin[2] = {
2, 3}; // CS: Current sense ANALOG input
int enpin[2] = {
0, 1}; // EN: Status of switches output (Analog pin)
int statpin = 13; //not explained by Sparkfun
/* init position value*/
int DataValueL=512; //middle position 0-1024
int DataValueR=512; //middle position 0-1024

////////////////////////////////////////////////////////////////////////////////
// INITIALIZATION
////////////////////////////////////////////////////////////////////////////////
void setup()
{
// serial initialization
Serial.begin(115200);

// initialization of Arduino's pins
pinMode(statpin, OUTPUT); //not explained by Sparkfun
digitalWrite(statpin, LOW);

for (int i=0; i<2; i++)
{
pinMode(inApin[i], OUTPUT);
pinMode(inBpin[i], OUTPUT);
pinMode(pwmpin[i], OUTPUT);
}
// Initialize braked for motor
for (int i=0; i<2; i++)
{
digitalWrite(inApin[i], LOW);
digitalWrite(inBpin[i], LOW);
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Main Loop ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void loop()
{
int sensorL,sensorR;

readSerialData(); // DataValueR & L contain the last order received (if there is no newer received, the last is kept)
// the previous order will still be used by the PID regulation MotorMotion Function

sensorR = analogRead(potR); // range 0-1024
sensorL = analogRead(potL); // range 0-1024

motorMotion(motRight,sensorR,DataValueR);
motorMotion(motLeft,sensorL,DataValueL);
}
////////////////////////////////////////////////////////////////////////////////
// Procedure: wait for complete trame
////////////////////////////////////////////////////////////////////////////////
void readSerialData()
{
byte Data[3]={
'0','0','0' };
// keep this function short, because the loop has to be short to keep the control over the motors

if (Serial.available()>2){
//parse the buffer : test if the byte is the first of the order "R"
Data[0]=Serial.read();
Last edited by volkantopc on Wed 24. Oct 2018, 23:15, edited 2 times in total.
volkantopc
 
Posts: 4
Joined: Sun 28. May 2017, 10:58
Has thanked: 1 time
Been thanked: 2 times

Re: my 2DOF motion simulator, ardunio, motomonster

Postby lucioviper » Tue 20. Jun 2017, 03:49

very nice. im building my 2dof like yours buyt im have some troubles with pots...


How did you connect your potentiometers to the motors?
lucioviper
 
Posts: 4
Joined: Thu 5. Jan 2017, 01:43
Has thanked: 0 time
Been thanked: 0 time

Re: my 2DOF motion simulator, ardunio, motomonster

Postby Bora » Thu 22. Jun 2017, 22:51

You can use couplings. It's very useful for connect different diameters of shafts.
Bora
 
Posts: 7
Images: 12
Joined: Sat 27. Aug 2016, 17:56
Has thanked: 2 times
Been thanked: 2 times


Return to Motion simulator Projects in progress

Who is online

Users browsing this forum: No registered users and 5 guests