Serial Port Communication added!

This commit is contained in:
Kostka 2022-10-21 12:55:06 +02:00
parent 0940317345
commit a072beb928
2 changed files with 32 additions and 27 deletions

View File

@ -1,23 +0,0 @@
#include <Braccio.h>
#include <Servo.h>
#include <math.h>
#include "math.hpp"
Servo base;
Servo shoulder;
Servo elbow;
Servo wrist_rot;
Servo wrist_ver;
Servo gripper;
void setup() {
Serial.begin(9600);
Braccio.begin();
}
void loop() {
Vec4 targ = Vec4(0, 0, 0, 0);
Vec4 rot = targ.to_rotation();
// speed inverse knematics wrist rot grip
Braccio.ServoMovement(30, rot.x, rot.y, rot.z, rot.w, 90, 70);
}

View File

@ -1,10 +1,17 @@
#ifndef ROBOT_MATH_HPP
#define ROBOT_MATH_HPP
#include <Braccio.h>
#include <Servo.h>
#include <math.h>
Servo base;
Servo shoulder;
Servo elbow;
Servo wrist_rot;
Servo wrist_ver;
Servo gripper;
#define PI 3.14159265359
#define PIdiv2 PI/2
const float shoulder_and_elbow_length = 12.5;
const float shoulder_plus_elbow_length = shoulder_and_elbow_length * 2;
const float wrist_length = 19;
@ -63,4 +70,25 @@ public:
float x,y,z,w;
};
#endif
// communication
Vec4 read() {
float x = parseFloat();
float y = parseFloat();
float z = parseFloat();
float w = parseFloat();
return Vec4(x,y,z,w);
}
void setup() {
Serial.begin(9600);
Braccio.begin();
pinPeripheral(PIN_SERIAL1_TX, PIO_SERCOM);
pinPeripheral(PIN_SERIAL1_RX, PIO_SERCOM);
}
void loop() {
Vec4 targ = read();
Vec4 rot = targ.to_rotation();
// speed inverse knematics wrist rot grip
Braccio.ServoMovement(30, rot.x, rot.y, rot.z, rot.w, 90, 70);
}