This repository was archived by the owner on Oct 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot_specific.cpp
More file actions
89 lines (65 loc) · 3.21 KB
/
robot_specific.cpp
File metadata and controls
89 lines (65 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* robot_specific.cpp
*
* This file is part of the code for the Hills Road/Systemetric entry to the
* 2017 Student Robotics competition "Easy as ABC".
*
* Written by Josh Holland <anowlcalledjosh@gmail.com>
*
* This file is available under CC0. You may use it for any purpose.
*/
#include "robot_specific.h"
#include "mbed.h"
/****************** These should be updated for each robot. *******************/
// The diameter of the wheels, in centimetres.
const double kWheelDiameter = 13.36;
// Prototype = 13.36
// The distance between the middle of the wheels, in centimetres. Increasing
// this number will decrease the number of steps the robot takes per degree.
const double kRobotDiameter = 40.30; // 42.79 * 17/18 * 359/360
// Prototype = 42.79
/************** These will probably be OK to leave as they are. ***************/
// The number of steps the motors must take to rotate 360 degrees.
const int kStepsPerRotation = 3200;
// The number of steps to accelerate and decelerate for.
const int kAccelDecelSteps = 7000;
// The number of steps to accelerate for when in the low-power state.
const int kAccelLowPowerSteps = 2000;
// The initial PWM period, in microseconds.
const int kInitialPwmPeriod = 1500;
// How much to change the PWM period by at a time, in microseconds.
const int kPwmPeriodIncrement = 1; // was 15
// The voltage at the motor boards, as a fraction, at which the robot should
// take action to decrease the likelihood of the motors stalling.
const double kLowPowerThreshold = 0.6;
// The pins that the motor control boards' DIR pins are connected to.
DigitalOut right_wheel_direction(p16);
DigitalOut left_wheel_direction(p17);
DigitalOut left_wheel_enable(p21);
DigitalOut right_wheel_enable(p22);
AnalogIn battery_voltage(p15);
// What to set the DIR pins to in order to travel in a certain direction.
// (Unfortunately these can't be declared inline, since they're defined in a
// different compilation unit to where they're used -- on the other hand, they
// aren't called that often.)
void LeftWheelForward() {left_wheel_direction = 0;}
void LeftWheelBack() {left_wheel_direction = 1;}
void RightWheelForward() {right_wheel_direction = 1;}
void RightWheelBack() {right_wheel_direction = 0;}
/******************** These shouldn't usually be changed. *********************/
// This isn't defined in the mbed's math.h, so we define it here (unexported).
const double kPi = 3.14159265358979323846;
// Unexported.
const double kWheelCircumference = kWheelDiameter * kPi;
const double kRobotCircumference = kRobotDiameter * kPi;
// The number of steps to take to move one centimetre (probably about 80).
const double kStepsPerCentimetre = kStepsPerRotation / kWheelCircumference;
// The number of steps to take to rotate one degree (probably about 34).
const double kStepsPerDegree = kRobotCircumference / kWheelCircumference
* kStepsPerRotation / 360;
// The pin that *both* motor control boards' CLK pins are connected to.
PwmOut pwm(p23);
// The USB serial connection.
Serial usb_serial(USBTX, USBRX);
// Responsible for calling ScaleSpeed at regular intervals.
Ticker ticker;
BusIn dip_switch(p14);