Main Page
Namespaces
Classes
Files
File List
File Members
arm_firmware
src
main.cpp
Go to the documentation of this file.
1
#include <Arduino.h>
2
#include <Servo.h>
3
4
// PWM specs of the Victor SP motor controller.
5
// https://www.vexrobotics.com/217-9090.html
6
#define victorMax 2350
7
#define victorMin 650
8
9
struct
JOINTPINS
{
10
int
wrist_roll
= 9;
// wrist roll pin
11
int
wrist_pitch
= 10;
// wrist pitch pin
12
int
upper_elbow
= 11;
// upper elbow pin
13
int
lower_elbow
= 12;
// lower elbow pin
14
int
base_yaw
= 13;
// base yaw pin
15
int
grip_enable
= A4;
// gripper enable pin
16
int
grip_open
= A5;
// gripper open pin
17
int
grip_close
= A6;
// gripper close pin
18
int
cam_tilt
= 7;
// camera servo pin
19
}
pins
;
20
21
struct
RECIEVED
{
22
float
wrist_roll
,
wrist_pitch
,
upper_elbow
,
lower_elbow
,
base_yaw
,gripper,winch,
cam_tilt
;
23
}
data
;
24
25
Servo
joint0
,
joint1
,
joint2
,
joint3
,
joint4
,
cam_tilt
;
26
27
int
mapToVictor
(
float
input){
28
return
map((input*100),-100,100,
victorMin
,
victorMax
);
29
}
30
void
recievedData
(){
31
if
(Serial.available()>=
sizeof
(float)){
32
Serial.readBytes((
char
*)&
data
.
gripper
,
sizeof
(
float
));
33
Serial.readBytes((
char
*)&
data
.
wrist_roll
,
sizeof
(
float
));
34
Serial.readBytes((
char
*)&
data
.
wrist_pitch
,
sizeof
(
float
));
35
Serial.readBytes((
char
*)&
data
.
upper_elbow
,
sizeof
(
float
));
36
Serial.readBytes((
char
*)&
data
.
lower_elbow
,
sizeof
(
float
));
37
Serial.readBytes((
char
*)&
data
.
base_yaw
,
sizeof
(
float
));
38
Serial.readBytes((
char
*)&
data
.
cam_tilt
,
sizeof
(
float
));
39
}
40
}
41
42
void
writeToJoints
(){
43
joint0
.writeMicroseconds(
mapToVictor
(
data
.
wrist_roll
));
44
joint1
.writeMicroseconds(
mapToVictor
(
data
.
wrist_pitch
));
45
joint2
.writeMicroseconds(
mapToVictor
(
data
.
upper_elbow
));
46
joint3
.writeMicroseconds(
mapToVictor
(
data
.
lower_elbow
));
47
joint4
.writeMicroseconds(
mapToVictor
(
data
.
base_yaw
));
48
cam_tilt
.write((
int
)
data
.
cam_tilt
);
49
50
// Gripper Open
51
if
(
data
.
gripper
== 1){
52
digitalWrite(
pins
.
grip_enable
, HIGH);
// enable pin on
53
digitalWrite(
pins
.
grip_open
, HIGH);
// turn open on
54
digitalWrite(
pins
.
grip_close
, LOW);
// turn close off
55
}
56
// Gripper Close
57
else
if
(
data
.
gripper
== -1){
58
digitalWrite(
pins
.
grip_enable
, HIGH);
// enable pin on
59
digitalWrite(
pins
.
grip_open
, LOW);
// turn open off
60
digitalWrite(
pins
.
grip_close
, HIGH);
// turn close on
61
}
62
// Gripper Stop
63
else
if
(
data
.
gripper
== 0){
64
digitalWrite(
pins
.
grip_enable
, LOW);
// enable pin off
65
digitalWrite(
pins
.
grip_open
, LOW);
// turn open off
66
digitalWrite(
pins
.
grip_close
, LOW);
// turn close on
67
}
68
}
69
void
setup
() {
70
Serial.begin(9600);
71
joint0
.attach(
pins
.
wrist_roll
);
72
joint1
.attach(
pins
.
wrist_pitch
);
73
joint2
.attach(
pins
.
upper_elbow
);
74
joint3
.attach(
pins
.
lower_elbow
);
75
joint4
.attach(
pins
.
base_yaw
);
76
cam_tilt
.attach(
pins
.
cam_tilt
);
77
pinMode(
pins
.
grip_enable
, OUTPUT);
78
pinMode(
pins
.
grip_open
, OUTPUT);
79
pinMode(
pins
.
grip_close
, OUTPUT);
80
recievedData
();
81
}
82
83
void
loop
() {
84
recievedData
();
85
writeToJoints
();
86
}
JOINTPINS::grip_enable
int grip_enable
Definition:
main.cpp:15
JOINTPINS::wrist_pitch
int wrist_pitch
Definition:
main.cpp:11
JOINTPINS
Definition:
main.cpp:9
joint4
Servo joint4
Definition:
main.cpp:25
JOINTPINS::grip_close
int grip_close
Definition:
main.cpp:17
loop
void loop()
Definition:
main.cpp:83
JOINTPINS::lower_elbow
int lower_elbow
Definition:
main.cpp:13
RECIEVED
Definition:
main.cpp:21
recievedData
void recievedData()
Definition:
main.cpp:30
JOINTPINS::cam_tilt
int cam_tilt
Definition:
main.cpp:18
writeToJoints
void writeToJoints()
Definition:
main.cpp:42
setup
void setup()
Definition:
main.cpp:69
joint2
Servo joint2
Definition:
main.cpp:25
victorMin
#define victorMin
Definition:
main.cpp:7
RECIEVED::cam_tilt
float cam_tilt
Definition:
main.cpp:22
RECIEVED::gripper
float gripper
Definition:
main.cpp:22
pins
struct JOINTPINS pins
mapToVictor
int mapToVictor(float input)
Definition:
main.cpp:27
joint0
Servo joint0
Definition:
main.cpp:25
RECIEVED::lower_elbow
float lower_elbow
Definition:
main.cpp:22
data
struct RECIEVED data
RECIEVED::upper_elbow
float upper_elbow
Definition:
main.cpp:22
RECIEVED::base_yaw
float base_yaw
Definition:
main.cpp:22
RECIEVED::wrist_roll
float wrist_roll
Definition:
main.cpp:22
JOINTPINS::base_yaw
int base_yaw
Definition:
main.cpp:14
JOINTPINS::wrist_roll
int wrist_roll
Definition:
main.cpp:10
joint1
Servo joint1
Definition:
main.cpp:25
JOINTPINS::grip_open
int grip_open
Definition:
main.cpp:16
JOINTPINS::upper_elbow
int upper_elbow
Definition:
main.cpp:12
RECIEVED::wrist_pitch
float wrist_pitch
Definition:
main.cpp:22
victorMax
#define victorMax
Definition:
main.cpp:6
joint3
Servo joint3
Definition:
main.cpp:25
simple_arm
Author(s): Daniel Snider
, Matthew Mirvish
autogenerated on Mon Jun 10 2019 15:05:31