Merge "Added min_time and mock time support."
diff --git a/aos/linux_code/ipc_lib/ipc_comparison.cc b/aos/linux_code/ipc_lib/ipc_comparison.cc
index f375a17..73c0f9b 100644
--- a/aos/linux_code/ipc_lib/ipc_comparison.cc
+++ b/aos/linux_code/ipc_lib/ipc_comparison.cc
@@ -5,6 +5,7 @@
#include <sys/un.h>
#include <pthread.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -224,8 +225,12 @@
class TCPPingPonger : public FDPingPonger {
public:
- TCPPingPonger() {
+ TCPPingPonger(bool nodelay) {
server_ = PCHECK(socket(AF_INET, SOCK_STREAM, 0));
+ if (nodelay) {
+ const int yes = 1;
+ PCHECK(setsockopt(server_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
+ }
{
sockaddr_in server_address;
memset(&server_address, 0, sizeof(server_address));
@@ -237,6 +242,10 @@
PCHECK(listen(server_, 1));
client_ = PCHECK(socket(AF_INET, SOCK_STREAM, 0));
+ if (nodelay) {
+ const int yes = 1;
+ PCHECK(setsockopt(client_, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)));
+ }
{
sockaddr_in client_address;
unsigned int length = sizeof(client_address);
@@ -465,19 +474,42 @@
class PthreadMutexPingPonger : public ConditionVariablePingPonger {
public:
- PthreadMutexPingPonger()
+ PthreadMutexPingPonger(int pshared, bool pi)
: ConditionVariablePingPonger(
::std::unique_ptr<ConditionVariableInterface>(
- new PthreadConditionVariable()),
+ new PthreadConditionVariable(pshared, pi)),
::std::unique_ptr<ConditionVariableInterface>(
- new PthreadConditionVariable())) {}
+ new PthreadConditionVariable(pshared, pi))) {}
private:
class PthreadConditionVariable : public ConditionVariableInterface {
public:
- PthreadConditionVariable() {
- PRCHECK(pthread_cond_init(&condition_, nullptr));
- PRCHECK(pthread_mutex_init(&mutex_, nullptr));
+ PthreadConditionVariable(bool pshared, bool pi) {
+ {
+ pthread_condattr_t cond_attr;
+ PRCHECK(pthread_condattr_init(&cond_attr));
+ if (pshared) {
+ PRCHECK(
+ pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED));
+ }
+ PRCHECK(pthread_cond_init(&condition_, &cond_attr));
+ PRCHECK(pthread_condattr_destroy(&cond_attr));
+ }
+
+ {
+ pthread_mutexattr_t mutex_attr;
+ PRCHECK(pthread_mutexattr_init(&mutex_attr));
+ if (pshared) {
+ PRCHECK(pthread_mutexattr_setpshared(&mutex_attr,
+ PTHREAD_PROCESS_SHARED));
+ }
+ if (pi) {
+ PRCHECK(
+ pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT));
+ }
+ PRCHECK(pthread_mutex_init(&mutex_, nullptr));
+ PRCHECK(pthread_mutexattr_destroy(&mutex_attr));
+ }
}
~PthreadConditionVariable() {
PRCHECK(pthread_mutex_destroy(&mutex_));
@@ -779,7 +811,13 @@
} else if (FLAGS_method == "aos_event") {
ping_ponger.reset(new AOSEventPingPonger());
} else if (FLAGS_method == "pthread_mutex") {
- ping_ponger.reset(new PthreadMutexPingPonger());
+ ping_ponger.reset(new PthreadMutexPingPonger(false, false));
+ } else if (FLAGS_method == "pthread_mutex_pshared") {
+ ping_ponger.reset(new PthreadMutexPingPonger(true, false));
+ } else if (FLAGS_method == "pthread_mutex_pshared_pi") {
+ ping_ponger.reset(new PthreadMutexPingPonger(true, true));
+ } else if (FLAGS_method == "pthread_mutex_pi") {
+ ping_ponger.reset(new PthreadMutexPingPonger(false, true));
} else if (FLAGS_method == "aos_queue") {
ping_ponger.reset(new AOSQueuePingPonger());
} else if (FLAGS_method == "eventfd") {
@@ -803,7 +841,9 @@
} else if (FLAGS_method == "unix_seqpacket") {
ping_ponger.reset(new UnixPingPonger(SOCK_SEQPACKET));
} else if (FLAGS_method == "tcp") {
- ping_ponger.reset(new TCPPingPonger());
+ ping_ponger.reset(new TCPPingPonger(false));
+ } else if (FLAGS_method == "tcp_nodelay") {
+ ping_ponger.reset(new TCPPingPonger(true));
} else if (FLAGS_method == "udp") {
ping_ponger.reset(new UDPPingPonger());
} else {
@@ -890,6 +930,9 @@
"\taos_mutex\n"
"\taos_event\n"
"\tpthread_mutex\n"
+ "\tpthread_mutex_pshared\n"
+ "\tpthread_mutex_pshared_pi\n"
+ "\tpthread_mutex_pi\n"
"\taos_queue\n"
"\teventfd\n"
"\tsysv_semaphore\n"
@@ -902,6 +945,7 @@
"\tunix_datagram\n"
"\tunix_seqpacket\n"
"\ttcp\n"
+ "\ttcp_nodelay\n"
"\tudp\n");
::gflags::ParseCommandLineFlags(&argc, &argv, true);
diff --git a/y2014/joystick_reader.cc b/y2014/joystick_reader.cc
index d2d1375..fcfe33c 100644
--- a/y2014/joystick_reader.cc
+++ b/y2014/joystick_reader.cc
@@ -191,10 +191,6 @@
const double kThrottleGain = 1.0 / 2.5;
if (false && (data.IsPressed(kDriveControlLoopEnable1) ||
data.IsPressed(kDriveControlLoopEnable2))) {
- // TODO(austin): Static sucks!
- static double distance = 0.0;
- static double angle = 0.0;
- static double filtered_goal_distance = 0.0;
if (data.PosEdge(kDriveControlLoopEnable1) ||
data.PosEdge(kDriveControlLoopEnable2)) {
if (drivetrain_queue.position.FetchLatest() &&
@@ -504,6 +500,10 @@
double goal_angle_;
double separation_angle_, shot_separation_angle_;
double velocity_compensation_;
+ // Distance, angle, and filtered goal for closed loop driving.
+ double distance;
+ double angle;
+ double filtered_goal_distance;
double intake_power_;
bool was_running_;
bool moving_for_shot_ = false;
diff --git a/y2014_bot3/joystick_reader.cc b/y2014_bot3/joystick_reader.cc
index 86f78dc..22610ae 100644
--- a/y2014_bot3/joystick_reader.cc
+++ b/y2014_bot3/joystick_reader.cc
@@ -66,8 +66,6 @@
void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
bool is_control_loop_driving = false;
- static double left_goal = 0.0;
- static double right_goal = 0.0;
const double wheel = -data.GetAxis(kSteeringWheel);
const double throttle = -data.GetAxis(kDriveThrottle);
@@ -139,6 +137,9 @@
bool auto_running_ = false;
bool is_high_gear_;
+ // Turning goals.
+ double left_goal;
+ double right_goal;
::aos::util::SimpleLogInterval no_drivetrain_status_ =
::aos::util::SimpleLogInterval(::aos::time::Time::InSeconds(0.2), WARNING,
diff --git a/y2016/actors/BUILD b/y2016/actors/BUILD
index 453d49e..cfbeb2b 100644
--- a/y2016/actors/BUILD
+++ b/y2016/actors/BUILD
@@ -5,60 +5,12 @@
filegroup(
name = 'binaries',
srcs = [
- ':drivetrain_action',
':superstructure_action',
':autonomous_action',
],
)
queue_library(
- name = 'drivetrain_action_queue',
- srcs = [
- 'drivetrain_action.q',
- ],
- deps = [
- '//aos/common/actions:action_queue',
- ],
-)
-
-cc_library(
- name = 'drivetrain_action_lib',
- srcs = [
- 'drivetrain_actor.cc',
- ],
- hdrs = [
- 'drivetrain_actor.h',
- ],
- deps = [
- ':drivetrain_action_queue',
- '//aos/common:time',
- '//aos/common:math',
- '//aos/common/util:phased_loop',
- '//aos/common/logging',
- '//aos/common/actions:action_lib',
- '//aos/common/logging:queue_logging',
- '//aos/common/util:trapezoid_profile',
- '//frc971/control_loops/drivetrain:drivetrain_queue',
- '//frc971/control_loops:state_feedback_loop',
- '//third_party/eigen',
- '//y2016:constants',
- '//y2016/control_loops/drivetrain:polydrivetrain_plants',
- ],
-)
-
-cc_binary(
- name = 'drivetrain_action',
- srcs = [
- 'drivetrain_actor_main.cc',
- ],
- deps = [
- ':drivetrain_action_lib',
- ':drivetrain_action_queue',
- '//aos/linux_code:init',
- ],
-)
-
-queue_library(
name = 'superstructure_action_queue',
srcs = [
'superstructure_action.q',
diff --git a/y2016/actors/autonomous_actor.cc b/y2016/actors/autonomous_actor.cc
index 7b3fc60..f298420 100644
--- a/y2016/actors/autonomous_actor.cc
+++ b/y2016/actors/autonomous_actor.cc
@@ -1092,6 +1092,7 @@
break;
case 5:
+ case 15:
TwoBallAuto();
return true;
break;
diff --git a/y2016/actors/drivetrain_action.q b/y2016/actors/drivetrain_action.q
deleted file mode 100644
index 9bbebb2..0000000
--- a/y2016/actors/drivetrain_action.q
+++ /dev/null
@@ -1,29 +0,0 @@
-package y2016.actors;
-
-import "aos/common/actions/actions.q";
-
-// Parameters to send with start.
-struct DrivetrainActionParams {
- double left_initial_position;
- double right_initial_position;
- double y_offset;
- double theta_offset;
- double maximum_velocity;
- double maximum_acceleration;
- double maximum_turn_velocity;
- double maximum_turn_acceleration;
-};
-
-queue_group DrivetrainActionQueueGroup {
- implements aos.common.actions.ActionQueueGroup;
-
- message Goal {
- uint32_t run;
- DrivetrainActionParams params;
- };
-
- queue Goal goal;
- queue aos.common.actions.Status status;
-};
-
-queue_group DrivetrainActionQueueGroup drivetrain_action;
diff --git a/y2016/actors/drivetrain_actor.cc b/y2016/actors/drivetrain_actor.cc
deleted file mode 100644
index 2c7c0e5..0000000
--- a/y2016/actors/drivetrain_actor.cc
+++ /dev/null
@@ -1,182 +0,0 @@
-#include "y2016/actors/drivetrain_actor.h"
-
-#include <functional>
-#include <numeric>
-
-#include <Eigen/Dense>
-
-#include "aos/common/util/phased_loop.h"
-#include "aos/common/logging/logging.h"
-#include "aos/common/util/trapezoid_profile.h"
-#include "aos/common/commonmath.h"
-#include "aos/common/time.h"
-
-#include "y2016/actors/drivetrain_actor.h"
-#include "y2016/constants.h"
-#include "y2016/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
-#include "frc971/control_loops/drivetrain/drivetrain.q.h"
-
-namespace y2016 {
-namespace actors {
-
-DrivetrainActor::DrivetrainActor(actors::DrivetrainActionQueueGroup *s)
- : aos::common::actions::ActorBase<actors::DrivetrainActionQueueGroup>(s),
- loop_(::y2016::control_loops::drivetrain::MakeDrivetrainLoop()) {
- loop_.set_controller_index(3);
-}
-
-bool DrivetrainActor::RunAction(const actors::DrivetrainActionParams ¶ms) {
- static const auto K = loop_.K();
-
- const double yoffset = params.y_offset;
- const double turn_offset =
- params.theta_offset * control_loops::drivetrain::kRobotRadius;
- LOG(INFO, "Going to move %f and turn %f\n", yoffset, turn_offset);
-
- // Measured conversion to get the distance right.
- ::aos::util::TrapezoidProfile profile(::aos::time::Time::InMS(5));
- ::aos::util::TrapezoidProfile turn_profile(::aos::time::Time::InMS(5));
- const double goal_velocity = 0.0;
- const double epsilon = 0.01;
- ::Eigen::Matrix<double, 2, 1> left_goal_state, right_goal_state;
-
- profile.set_maximum_acceleration(params.maximum_acceleration);
- profile.set_maximum_velocity(params.maximum_velocity);
- turn_profile.set_maximum_acceleration(
- params.maximum_turn_acceleration *
- control_loops::drivetrain::kRobotRadius);
- turn_profile.set_maximum_velocity(params.maximum_turn_velocity *
- control_loops::drivetrain::kRobotRadius);
-
- while (true) {
- ::aos::time::PhasedLoopXMS(5, 2500);
-
- ::frc971::control_loops::drivetrain_queue.status.FetchLatest();
- if (::frc971::control_loops::drivetrain_queue.status.get()) {
- const auto &status = *::frc971::control_loops::drivetrain_queue.status;
- if (::std::abs(status.uncapped_left_voltage -
- status.uncapped_right_voltage) > 24) {
- LOG(DEBUG, "spinning in place\n");
- // They're more than 24V apart, so stop moving forwards and let it deal
- // with spinning first.
- profile.SetGoal(
- (status.estimated_left_position + status.estimated_right_position -
- params.left_initial_position - params.right_initial_position) /
- 2.0);
- } else {
- static const double divisor = K(0, 0) + K(0, 2);
- double dx_left, dx_right;
-
- if (status.uncapped_left_voltage > 12.0) {
- dx_left = (status.uncapped_left_voltage - 12.0) / divisor;
- } else if (status.uncapped_left_voltage < -12.0) {
- dx_left = (status.uncapped_left_voltage + 12.0) / divisor;
- } else {
- dx_left = 0;
- }
-
- if (status.uncapped_right_voltage > 12.0) {
- dx_right = (status.uncapped_right_voltage - 12.0) / divisor;
- } else if (status.uncapped_right_voltage < -12.0) {
- dx_right = (status.uncapped_right_voltage + 12.0) / divisor;
- } else {
- dx_right = 0;
- }
-
- double dx;
-
- if (dx_left == 0 && dx_right == 0) {
- dx = 0;
- } else if (dx_left != 0 && dx_right != 0 &&
- ::aos::sign(dx_left) != ::aos::sign(dx_right)) {
- // Both saturating in opposite directions. Don't do anything.
- LOG(DEBUG, "Saturating opposite ways, not adjusting\n");
- dx = 0;
- } else if (::std::abs(dx_left) > ::std::abs(dx_right)) {
- dx = dx_left;
- } else {
- dx = dx_right;
- }
-
- if (dx != 0) {
- LOG(DEBUG, "adjusting goal by %f\n", dx);
- profile.MoveGoal(-dx);
- }
- }
- } else {
- // If we ever get here, that's bad and we should just give up
- LOG(ERROR, "no drivetrain status!\n");
- return false;
- }
-
- const auto drive_profile_goal_state =
- profile.Update(yoffset, goal_velocity);
- const auto turn_profile_goal_state = turn_profile.Update(turn_offset, 0.0);
- left_goal_state = drive_profile_goal_state - turn_profile_goal_state;
- right_goal_state = drive_profile_goal_state + turn_profile_goal_state;
-
- if (::std::abs(drive_profile_goal_state(0, 0) - yoffset) < epsilon &&
- ::std::abs(turn_profile_goal_state(0, 0) - turn_offset) < epsilon) {
- break;
- }
-
- if (ShouldCancel()) return true;
-
- LOG(DEBUG, "Driving left to %f, right to %f\n",
- left_goal_state(0, 0) + params.left_initial_position,
- right_goal_state(0, 0) + params.right_initial_position);
- ::frc971::control_loops::drivetrain_queue.goal.MakeWithBuilder()
- .control_loop_driving(true)
- .highgear(true)
- .left_goal(left_goal_state(0, 0) + params.left_initial_position)
- .right_goal(right_goal_state(0, 0) + params.right_initial_position)
- .left_velocity_goal(left_goal_state(1, 0))
- .right_velocity_goal(right_goal_state(1, 0))
- .Send();
- }
- if (ShouldCancel()) return true;
- ::frc971::control_loops::drivetrain_queue.status.FetchLatest();
-
- while (!::frc971::control_loops::drivetrain_queue.status.get()) {
- LOG(WARNING,
- "No previous drivetrain status packet, trying to fetch again\n");
- ::frc971::control_loops::drivetrain_queue.status.FetchNextBlocking();
- if (ShouldCancel()) return true;
- }
-
- while (true) {
- if (ShouldCancel()) return true;
- const double kPositionThreshold = 0.05;
-
- const double left_error =
- ::std::abs(::frc971::control_loops::drivetrain_queue.status
- ->estimated_left_position -
- (left_goal_state(0, 0) + params.left_initial_position));
- const double right_error =
- ::std::abs(::frc971::control_loops::drivetrain_queue.status
- ->estimated_right_position -
- (right_goal_state(0, 0) + params.right_initial_position));
- const double velocity_error = ::std::abs(
- ::frc971::control_loops::drivetrain_queue.status->robot_speed);
- if (left_error < kPositionThreshold && right_error < kPositionThreshold &&
- velocity_error < 0.2) {
- break;
- } else {
- LOG(DEBUG, "Drivetrain error is %f, %f, %f\n", left_error, right_error,
- velocity_error);
- }
- ::frc971::control_loops::drivetrain_queue.status.FetchNextBlocking();
- }
-
- LOG(INFO, "Done moving\n");
- return true;
-}
-
-::std::unique_ptr<DrivetrainAction> MakeDrivetrainAction(
- const ::y2016::actors::DrivetrainActionParams ¶ms) {
- return ::std::unique_ptr<DrivetrainAction>(
- new DrivetrainAction(&::y2016::actors::drivetrain_action, params));
-}
-
-} // namespace actors
-} // namespace y2016
diff --git a/y2016/actors/drivetrain_actor.h b/y2016/actors/drivetrain_actor.h
deleted file mode 100644
index 0ab3bf2..0000000
--- a/y2016/actors/drivetrain_actor.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef Y2016_ACTORS_DRIVETRAIN_ACTOR_H_
-#define Y2016_ACTORS_DRIVETRAIN_ACTOR_H_
-
-#include <memory>
-
-#include "aos/common/actions/actor.h"
-#include "aos/common/actions/actions.h"
-#include "frc971/control_loops/state_feedback_loop.h"
-
-#include "y2016/actors/drivetrain_action.q.h"
-
-namespace y2016 {
-namespace actors {
-
-class DrivetrainActor
- : public ::aos::common::actions::ActorBase<DrivetrainActionQueueGroup> {
- public:
- explicit DrivetrainActor(DrivetrainActionQueueGroup *s);
-
- bool RunAction(const actors::DrivetrainActionParams ¶ms) override;
-
- private:
- StateFeedbackLoop<4, 2, 2> loop_;
-};
-
-typedef ::aos::common::actions::TypedAction<DrivetrainActionQueueGroup>
- DrivetrainAction;
-
-// Makes a new DrivetrainActor action.
-::std::unique_ptr<DrivetrainAction> MakeDrivetrainAction(
- const ::y2016::actors::DrivetrainActionParams ¶ms);
-
-} // namespace actors
-} // namespace y2016
-
-#endif
diff --git a/y2016/actors/drivetrain_actor_main.cc b/y2016/actors/drivetrain_actor_main.cc
deleted file mode 100644
index 0fe9e71..0000000
--- a/y2016/actors/drivetrain_actor_main.cc
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <stdio.h>
-
-#include "aos/linux_code/init.h"
-#include "y2016/actors/drivetrain_action.q.h"
-#include "y2016/actors/drivetrain_actor.h"
-
-using ::aos::time::Time;
-
-int main(int /*argc*/, char* /*argv*/ []) {
- ::aos::Init(-1);
-
- ::y2016::actors::DrivetrainActor drivetrain(
- &::y2016::actors::drivetrain_action);
- drivetrain.Run();
-
- ::aos::Cleanup();
- return 0;
-}
diff --git a/y2016/dashboard/dashboard.cc b/y2016/dashboard/dashboard.cc
index 22a77fa..16ad077 100644
--- a/y2016/dashboard/dashboard.cc
+++ b/y2016/dashboard/dashboard.cc
@@ -124,7 +124,9 @@
AddPoint("big indicator", big_indicator);
AddPoint("superstructure state indicator", superstructure_state_indicator);
- AddPoint("auto mode indicator", auto_mode_indicator);
+ if(auto_mode_indicator != 15) {
+ AddPoint("auto mode indicator", auto_mode_indicator);
+ }
#endif
// Get ready for next iteration. /////
diff --git a/y2016/dashboard/www/index.html b/y2016/dashboard/www/index.html
index 3821b48..b7f943f 100644
--- a/y2016/dashboard/www/index.html
+++ b/y2016/dashboard/www/index.html
@@ -90,7 +90,7 @@
default:
$("#bigIndicator").css("background", "#000000");
$("#bigIndicator").css("color", "#444444");
- $("#bigIndicator").text("No ball, no target");
+ $("#bigIndicator").text("No ball");
break;
}
@@ -218,7 +218,8 @@
}
#autoModeIndicator {
- background: #FF0000;
+ background: #444444;
+ color: #AAAAAA;
}
</style>
</head>
diff --git a/y2016/joystick_reader.cc b/y2016/joystick_reader.cc
index 45733ff..6a0edf0 100644
--- a/y2016/joystick_reader.cc
+++ b/y2016/joystick_reader.cc
@@ -120,8 +120,6 @@
void HandleDrivetrain(const ::aos::input::driver_station::Data &data) {
bool is_control_loop_driving = false;
- static double left_goal = 0.0;
- static double right_goal = 0.0;
const double wheel = -data.GetAxis(kSteeringWheel);
const double throttle = -data.GetAxis(kDriveThrottle);
@@ -238,18 +236,15 @@
shooter_velocity_ = 640.0;
intake_goal_ = intake_when_shooting;
} else if (data.IsPressed(kBackFender)) {
- // Fender shot back
- shoulder_goal_ = M_PI / 2.0 - 0.2;
- wrist_goal_ = -0.55;
- shooter_velocity_ = 600.0;
+ // Backwards shot no IMU
+ shoulder_goal_ = M_PI / 2.0 - 0.4;
+ wrist_goal_ = -0.62 - 0.02;
+ shooter_velocity_ = 640.0;
intake_goal_ = intake_when_shooting;
} else if (data.IsPressed(kFrontFender)) {
- // Forwards shot, higher
+ // Forwards shot no IMU
shoulder_goal_ = M_PI / 2.0 + 0.1;
- wrist_goal_ = M_PI + 0.41 + 0.02 + 0.020;
- if (drivetrain_queue.status.get()) {
- wrist_goal_ += drivetrain_queue.status->ground_angle;
- }
+ wrist_goal_ = M_PI + 0.41 + 0.02 - 0.005;
shooter_velocity_ = 640.0;
intake_goal_ = intake_when_shooting;
} else if (data.IsPressed(kExpand) || data.IsPressed(kWinch)) {
@@ -458,6 +453,10 @@
double wrist_goal_;
double shooter_velocity_ = 0.0;
+ // Turning goals
+ double left_goal;
+ double right_goal;
+
bool was_running_ = false;
bool auto_running_ = false;
diff --git a/y2016_bot3/actors/BUILD b/y2016_bot3/actors/BUILD
index 6453f13..aa774a3 100644
--- a/y2016_bot3/actors/BUILD
+++ b/y2016_bot3/actors/BUILD
@@ -5,60 +5,11 @@
filegroup(
name = 'binaries',
srcs = [
- ':drivetrain_action',
':autonomous_action',
],
)
queue_library(
- name = 'drivetrain_action_queue',
- srcs = [
- 'drivetrain_action.q',
- ],
- deps = [
- '//aos/common/actions:action_queue',
- ],
-)
-
-cc_library(
- name = 'drivetrain_action_lib',
- srcs = [
- 'drivetrain_actor.cc',
- ],
- hdrs = [
- 'drivetrain_actor.h',
- ],
- deps = [
- ':drivetrain_action_queue',
- '//aos/common:time',
- '//aos/common:math',
- '//aos/common/util:phased_loop',
- '//aos/common/logging',
- '//aos/common/actions:action_lib',
- '//aos/common/logging:queue_logging',
- '//aos/common/util:trapezoid_profile',
- '//frc971/control_loops/drivetrain:drivetrain_queue',
- '//frc971/control_loops:state_feedback_loop',
- '//third_party/eigen',
- '//y2016_bot3/control_loops/intake:intake_lib',
- '//y2016_bot3/control_loops/drivetrain:drivetrain_base',
- '//y2016_bot3/control_loops/drivetrain:polydrivetrain_plants',
- ],
-)
-
-cc_binary(
- name = 'drivetrain_action',
- srcs = [
- 'drivetrain_actor_main.cc',
- ],
- deps = [
- ':drivetrain_action_lib',
- ':drivetrain_action_queue',
- '//aos/linux_code:init',
- ],
-)
-
-queue_library(
name = 'autonomous_action_queue',
srcs = [
'autonomous_action.q',
diff --git a/y2016_bot3/actors/autonomous_actor.cc b/y2016_bot3/actors/autonomous_actor.cc
index 4167f2e..27dae0e 100644
--- a/y2016_bot3/actors/autonomous_actor.cc
+++ b/y2016_bot3/actors/autonomous_actor.cc
@@ -204,14 +204,12 @@
void AutonomousActor::MoveIntake(double intake_goal,
const ProfileParameters intake_params,
bool traverse_up, double roller_power) {
-
auto new_intake_goal =
::y2016_bot3::control_loops::intake_queue.goal.MakeMessage();
new_intake_goal->angle_intake = intake_goal;
- new_intake_goal->max_angular_velocity_intake =
- intake_params.max_velocity;
+ new_intake_goal->max_angular_velocity_intake = intake_params.max_velocity;
new_intake_goal->max_angular_acceleration_intake =
intake_params.max_acceleration;
@@ -219,7 +217,6 @@
new_intake_goal->voltage_top_rollers = roller_power;
new_intake_goal->voltage_bottom_rollers = roller_power;
- new_intake_goal->traverse_unlatched = true;
new_intake_goal->traverse_down = !traverse_up;
if (!new_intake_goal.Send()) {
@@ -241,13 +238,15 @@
if (::std::abs(control_loops::intake_queue.status->intake.goal_angle -
intake_goal_.intake) < kProfileError &&
- ::std::abs(control_loops::intake_queue.status->intake
- .goal_angular_velocity) < kProfileError) {
+ ::std::abs(
+ control_loops::intake_queue.status->intake.goal_angular_velocity) <
+ kProfileError) {
LOG(DEBUG, "Profile done.\n");
if (::std::abs(control_loops::intake_queue.status->intake.angle -
intake_goal_.intake) < kEpsilon &&
- ::std::abs(control_loops::intake_queue.status->intake
- .angular_velocity) < kEpsilon) {
+ ::std::abs(
+ control_loops::intake_queue.status->intake.angular_velocity) <
+ kEpsilon) {
LOG(INFO, "Near goal, done.\n");
return true;
}
diff --git a/y2016_bot3/actors/drivetrain_action.q b/y2016_bot3/actors/drivetrain_action.q
deleted file mode 100644
index 7775cad..0000000
--- a/y2016_bot3/actors/drivetrain_action.q
+++ /dev/null
@@ -1,29 +0,0 @@
-package y2016_bot3.actors;
-
-import "aos/common/actions/actions.q";
-
-// Parameters to send with start.
-struct DrivetrainActionParams {
- double left_initial_position;
- double right_initial_position;
- double y_offset;
- double theta_offset;
- double maximum_velocity;
- double maximum_acceleration;
- double maximum_turn_velocity;
- double maximum_turn_acceleration;
-};
-
-queue_group DrivetrainActionQueueGroup {
- implements aos.common.actions.ActionQueueGroup;
-
- message Goal {
- uint32_t run;
- DrivetrainActionParams params;
- };
-
- queue Goal goal;
- queue aos.common.actions.Status status;
-};
-
-queue_group DrivetrainActionQueueGroup drivetrain_action;
diff --git a/y2016_bot3/actors/drivetrain_actor.cc b/y2016_bot3/actors/drivetrain_actor.cc
deleted file mode 100644
index 686c50f..0000000
--- a/y2016_bot3/actors/drivetrain_actor.cc
+++ /dev/null
@@ -1,181 +0,0 @@
-#include "y2016_bot3/actors/drivetrain_actor.h"
-
-#include <functional>
-#include <numeric>
-
-#include <Eigen/Dense>
-
-#include "aos/common/util/phased_loop.h"
-#include "aos/common/logging/logging.h"
-#include "aos/common/util/trapezoid_profile.h"
-#include "aos/common/commonmath.h"
-#include "aos/common/time.h"
-
-#include "y2016_bot3/actors/drivetrain_actor.h"
-#include "y2016_bot3/control_loops/drivetrain/drivetrain_dog_motor_plant.h"
-#include "frc971/control_loops/drivetrain/drivetrain.q.h"
-
-namespace y2016_bot3 {
-namespace actors {
-
-DrivetrainActor::DrivetrainActor(actors::DrivetrainActionQueueGroup *s)
- : aos::common::actions::ActorBase<actors::DrivetrainActionQueueGroup>(s),
- loop_(::y2016_bot3::control_loops::drivetrain::MakeDrivetrainLoop()) {
- loop_.set_controller_index(3);
-}
-
-bool DrivetrainActor::RunAction(const actors::DrivetrainActionParams ¶ms) {
- static const auto K = loop_.K();
-
- const double yoffset = params.y_offset;
- const double turn_offset =
- params.theta_offset * control_loops::drivetrain::kRobotRadius;
- LOG(INFO, "Going to move %f and turn %f\n", yoffset, turn_offset);
-
- // Measured conversion to get the distance right.
- ::aos::util::TrapezoidProfile profile(::aos::time::Time::InMS(5));
- ::aos::util::TrapezoidProfile turn_profile(::aos::time::Time::InMS(5));
- const double goal_velocity = 0.0;
- const double epsilon = 0.01;
- ::Eigen::Matrix<double, 2, 1> left_goal_state, right_goal_state;
-
- profile.set_maximum_acceleration(params.maximum_acceleration);
- profile.set_maximum_velocity(params.maximum_velocity);
- turn_profile.set_maximum_acceleration(
- params.maximum_turn_acceleration *
- control_loops::drivetrain::kRobotRadius);
- turn_profile.set_maximum_velocity(params.maximum_turn_velocity *
- control_loops::drivetrain::kRobotRadius);
-
- while (true) {
- ::aos::time::PhasedLoopXMS(5, 2500);
-
- ::frc971::control_loops::drivetrain_queue.status.FetchLatest();
- if (::frc971::control_loops::drivetrain_queue.status.get()) {
- const auto &status = *::frc971::control_loops::drivetrain_queue.status;
- if (::std::abs(status.uncapped_left_voltage -
- status.uncapped_right_voltage) > 24) {
- LOG(DEBUG, "spinning in place\n");
- // They're more than 24V apart, so stop moving forwards and let it deal
- // with spinning first.
- profile.SetGoal(
- (status.estimated_left_position + status.estimated_right_position -
- params.left_initial_position - params.right_initial_position) /
- 2.0);
- } else {
- static const double divisor = K(0, 0) + K(0, 2);
- double dx_left, dx_right;
-
- if (status.uncapped_left_voltage > 12.0) {
- dx_left = (status.uncapped_left_voltage - 12.0) / divisor;
- } else if (status.uncapped_left_voltage < -12.0) {
- dx_left = (status.uncapped_left_voltage + 12.0) / divisor;
- } else {
- dx_left = 0;
- }
-
- if (status.uncapped_right_voltage > 12.0) {
- dx_right = (status.uncapped_right_voltage - 12.0) / divisor;
- } else if (status.uncapped_right_voltage < -12.0) {
- dx_right = (status.uncapped_right_voltage + 12.0) / divisor;
- } else {
- dx_right = 0;
- }
-
- double dx;
-
- if (dx_left == 0 && dx_right == 0) {
- dx = 0;
- } else if (dx_left != 0 && dx_right != 0 &&
- ::aos::sign(dx_left) != ::aos::sign(dx_right)) {
- // Both saturating in opposite directions. Don't do anything.
- LOG(DEBUG, "Saturating opposite ways, not adjusting\n");
- dx = 0;
- } else if (::std::abs(dx_left) > ::std::abs(dx_right)) {
- dx = dx_left;
- } else {
- dx = dx_right;
- }
-
- if (dx != 0) {
- LOG(DEBUG, "adjusting goal by %f\n", dx);
- profile.MoveGoal(-dx);
- }
- }
- } else {
- // If we ever get here, that's bad and we should just give up
- LOG(ERROR, "no drivetrain status!\n");
- return false;
- }
-
- const auto drive_profile_goal_state =
- profile.Update(yoffset, goal_velocity);
- const auto turn_profile_goal_state = turn_profile.Update(turn_offset, 0.0);
- left_goal_state = drive_profile_goal_state - turn_profile_goal_state;
- right_goal_state = drive_profile_goal_state + turn_profile_goal_state;
-
- if (::std::abs(drive_profile_goal_state(0, 0) - yoffset) < epsilon &&
- ::std::abs(turn_profile_goal_state(0, 0) - turn_offset) < epsilon) {
- break;
- }
-
- if (ShouldCancel()) return true;
-
- LOG(DEBUG, "Driving left to %f, right to %f\n",
- left_goal_state(0, 0) + params.left_initial_position,
- right_goal_state(0, 0) + params.right_initial_position);
- ::frc971::control_loops::drivetrain_queue.goal.MakeWithBuilder()
- .control_loop_driving(true)
- .highgear(true)
- .left_goal(left_goal_state(0, 0) + params.left_initial_position)
- .right_goal(right_goal_state(0, 0) + params.right_initial_position)
- .left_velocity_goal(left_goal_state(1, 0))
- .right_velocity_goal(right_goal_state(1, 0))
- .Send();
- }
- if (ShouldCancel()) return true;
- ::frc971::control_loops::drivetrain_queue.status.FetchLatest();
-
- while (!::frc971::control_loops::drivetrain_queue.status.get()) {
- LOG(WARNING,
- "No previous drivetrain status packet, trying to fetch again\n");
- ::frc971::control_loops::drivetrain_queue.status.FetchNextBlocking();
- if (ShouldCancel()) return true;
- }
-
- while (true) {
- if (ShouldCancel()) return true;
- const double kPositionThreshold = 0.05;
-
- const double left_error =
- ::std::abs(::frc971::control_loops::drivetrain_queue.status
- ->estimated_left_position -
- (left_goal_state(0, 0) + params.left_initial_position));
- const double right_error =
- ::std::abs(::frc971::control_loops::drivetrain_queue.status
- ->estimated_right_position -
- (right_goal_state(0, 0) + params.right_initial_position));
- const double velocity_error = ::std::abs(
- ::frc971::control_loops::drivetrain_queue.status->robot_speed);
- if (left_error < kPositionThreshold && right_error < kPositionThreshold &&
- velocity_error < 0.2) {
- break;
- } else {
- LOG(DEBUG, "Drivetrain error is %f, %f, %f\n", left_error, right_error,
- velocity_error);
- }
- ::frc971::control_loops::drivetrain_queue.status.FetchNextBlocking();
- }
-
- LOG(INFO, "Done moving\n");
- return true;
-}
-
-::std::unique_ptr<DrivetrainAction> MakeDrivetrainAction(
- const ::y2016_bot3::actors::DrivetrainActionParams ¶ms) {
- return ::std::unique_ptr<DrivetrainAction>(
- new DrivetrainAction(&::y2016_bot3::actors::drivetrain_action, params));
-}
-
-} // namespace actors
-} // namespace y2016_bot3
diff --git a/y2016_bot3/actors/drivetrain_actor.h b/y2016_bot3/actors/drivetrain_actor.h
deleted file mode 100644
index ebf3ed5..0000000
--- a/y2016_bot3/actors/drivetrain_actor.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef Y2016_BOT3_ACTORS_DRIVETRAIN_ACTOR_H_
-#define Y2016_BOT3_ACTORS_DRIVETRAIN_ACTOR_H_
-
-#include <memory>
-
-#include "aos/common/actions/actor.h"
-#include "aos/common/actions/actions.h"
-#include "frc971/control_loops/state_feedback_loop.h"
-
-#include "y2016_bot3/actors/drivetrain_action.q.h"
-
-namespace y2016_bot3 {
-namespace actors {
-
-class DrivetrainActor
- : public ::aos::common::actions::ActorBase<DrivetrainActionQueueGroup> {
- public:
- explicit DrivetrainActor(DrivetrainActionQueueGroup *s);
-
- bool RunAction(const actors::DrivetrainActionParams ¶ms) override;
-
- private:
- StateFeedbackLoop<4, 2, 2> loop_;
-};
-
-typedef ::aos::common::actions::TypedAction<DrivetrainActionQueueGroup>
- DrivetrainAction;
-
-// Makes a new DrivetrainActor action.
-::std::unique_ptr<DrivetrainAction> MakeDrivetrainAction(
- const ::y2016_bot3::actors::DrivetrainActionParams ¶ms);
-
-} // namespace actors
-} // namespace y2016_bot3
-
-#endif
diff --git a/y2016_bot3/actors/drivetrain_actor_main.cc b/y2016_bot3/actors/drivetrain_actor_main.cc
deleted file mode 100644
index 41a4d28..0000000
--- a/y2016_bot3/actors/drivetrain_actor_main.cc
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <stdio.h>
-
-#include "aos/linux_code/init.h"
-#include "y2016_bot3/actors/drivetrain_action.q.h"
-#include "y2016_bot3/actors/drivetrain_actor.h"
-
-using ::aos::time::Time;
-
-int main(int /*argc*/, char* /*argv*/ []) {
- ::aos::Init(-1);
-
- ::y2016_bot3::actors::DrivetrainActor drivetrain(
- &::y2016_bot3::actors::drivetrain_action);
- drivetrain.Run();
-
- ::aos::Cleanup();
- return 0;
-}
diff --git a/y2016_bot3/control_loops/drivetrain/drivetrain_base.cc b/y2016_bot3/control_loops/drivetrain/drivetrain_base.cc
index cefb1cf..5997342 100644
--- a/y2016_bot3/control_loops/drivetrain/drivetrain_base.cc
+++ b/y2016_bot3/control_loops/drivetrain/drivetrain_base.cc
@@ -36,7 +36,9 @@
kThreeStateDriveShifter,
kThreeStateDriveShifter,
true,
- 0.0};
+ 0.0,
+ 0.4,
+ 1.0};
return kDrivetrainConfig;
};
diff --git a/y2016_bot3/control_loops/drivetrain/drivetrain_base.h b/y2016_bot3/control_loops/drivetrain/drivetrain_base.h
index d6a041e..280d1c5 100644
--- a/y2016_bot3/control_loops/drivetrain/drivetrain_base.h
+++ b/y2016_bot3/control_loops/drivetrain/drivetrain_base.h
@@ -8,7 +8,6 @@
static constexpr double drivetrain_max_speed = 5.0;
// The ratio from the encoder shaft to the drivetrain wheels.
-// TODO(constants): Update these.
static constexpr double kDrivetrainEncoderRatio = 1.0;
} // namespace constants
diff --git a/y2016_bot3/control_loops/intake/intake.cc b/y2016_bot3/control_loops/intake/intake.cc
index 5320cd5..b3d86af 100644
--- a/y2016_bot3/control_loops/intake/intake.cc
+++ b/y2016_bot3/control_loops/intake/intake.cc
@@ -16,7 +16,7 @@
// The maximum voltage the intake roller will be allowed to use.
constexpr float kMaxIntakeTopVoltage = 12.0;
constexpr float kMaxIntakeBottomVoltage = 12.0;
-
+constexpr float kMaxIntakeRollersVoltage = 12.0;
}
// namespace
@@ -33,28 +33,6 @@
.lpNorm<Eigen::Infinity>() < tolerance);
}
-double Intake::MoveButKeepAbove(double reference_angle, double current_angle,
- double move_distance) {
- return -MoveButKeepBelow(-reference_angle, -current_angle, -move_distance);
-}
-
-double Intake::MoveButKeepBelow(double reference_angle, double current_angle,
- double move_distance) {
- // There are 3 interesting places to move to.
- const double small_negative_move = current_angle - move_distance;
- const double small_positive_move = current_angle + move_distance;
- // And the reference angle.
-
- // Move the the highest one that is below reference_angle.
- if (small_negative_move > reference_angle) {
- return reference_angle;
- } else if (small_positive_move > reference_angle) {
- return small_negative_move;
- } else {
- return small_positive_move;
- }
-}
-
void Intake::RunIteration(const control_loops::IntakeQueue::Goal *unsafe_goal,
const control_loops::IntakeQueue::Position *position,
control_loops::IntakeQueue::Output *output,
@@ -162,10 +140,10 @@
requested_intake = unsafe_goal->angle_intake;
}
- //Push the request out to the hardware.
+ // Push the request out to the hardware.
limit_checker_.UpdateGoal(requested_intake);
- // ESTOP if we hit the hard limits.
+ // ESTOP if we hit the hard limits.
if (intake_.CheckHardLimits() && output) {
state_ = ESTOP;
}
@@ -198,6 +176,7 @@
output->voltage_top_rollers = 0.0;
output->voltage_bottom_rollers = 0.0;
+ output->voltage_intake_rollers = 0.0;
if (unsafe_goal) {
// Ball detector lights.
@@ -212,6 +191,10 @@
output->voltage_top_rollers = ::std::max(
-kMaxIntakeTopVoltage,
::std::min(unsafe_goal->voltage_top_rollers, kMaxIntakeTopVoltage));
+ output->voltage_intake_rollers =
+ ::std::max(-kMaxIntakeRollersVoltage,
+ ::std::min(unsafe_goal->voltage_intake_rollers,
+ kMaxIntakeRollersVoltage));
output->voltage_bottom_rollers =
::std::max(-kMaxIntakeBottomVoltage,
::std::min(unsafe_goal->voltage_bottom_rollers,
@@ -222,7 +205,6 @@
}
// Traverse.
- output->traverse_unlatched = unsafe_goal->traverse_unlatched;
output->traverse_down = unsafe_goal->traverse_down;
}
}
diff --git a/y2016_bot3/control_loops/intake/intake.h b/y2016_bot3/control_loops/intake/intake.h
index fed17ab..cfc204f 100644
--- a/y2016_bot3/control_loops/intake/intake.h
+++ b/y2016_bot3/control_loops/intake/intake.h
@@ -29,18 +29,19 @@
// the use.
// TODO(constants): Update these.
static constexpr ::frc971::constants::Range kIntakeRange{// Lower hard stop
- -0.5,
+ -0.4,
// Upper hard stop
2.90,
// Lower soft stop
- -0.300,
+ -0.28,
// Uppper soft stop
- 2.725};
+ 2.77};
struct IntakeZero {
- double pot_offset = 0.0;
- ::frc971::constants::ZeroingConstants zeroing{
- kZeroingSampleSize, kIntakeEncoderIndexDifference, 0.0, 0.3};
+ double pot_offset = 5.462409 + 0.333162;
+ ::frc971::constants::ZeroingConstants zeroing{kZeroingSampleSize,
+ kIntakeEncoderIndexDifference,
+ +(-0.291240 + 0.148604), 0.3};
};
} // namespace constants
namespace control_loops {
@@ -54,12 +55,14 @@
class IntakeTest_DisabledWhileZeroingLow_Test;
}
+// TODO(Adam): Implement this class and delete it from here.
class LimitChecker {
- public:
- LimitChecker(IntakeArm *intake) : intake_(intake) {}
- void UpdateGoal(double intake_angle_goal);
- private:
- IntakeArm *intake_;
+ public:
+ LimitChecker(IntakeArm *intake) : intake_(intake) {}
+ void UpdateGoal(double intake_angle_goal);
+
+ private:
+ IntakeArm *intake_;
};
class Intake : public ::aos::controls::ControlLoop<control_loops::IntakeQueue> {
@@ -109,15 +112,6 @@
State state() const { return state_; }
- // Returns the value to move the joint to such that it will stay below
- // reference_angle starting at current_angle, but move at least move_distance
- static double MoveButKeepBelow(double reference_angle, double current_angle,
- double move_distance);
- // Returns the value to move the joint to such that it will stay above
- // reference_angle starting at current_angle, but move at least move_distance
- static double MoveButKeepAbove(double reference_angle, double current_angle,
- double move_distance);
-
protected:
void RunIteration(const control_loops::IntakeQueue::Goal *unsafe_goal,
const control_loops::IntakeQueue::Position *position,
@@ -145,7 +139,6 @@
DISALLOW_COPY_AND_ASSIGN(Intake);
};
-
} // namespace intake
} // namespace control_loops
} // namespace y2016_bot3
diff --git a/y2016_bot3/control_loops/intake/intake.q b/y2016_bot3/control_loops/intake/intake.q
index da3edbb..55d102d 100644
--- a/y2016_bot3/control_loops/intake/intake.q
+++ b/y2016_bot3/control_loops/intake/intake.q
@@ -57,12 +57,10 @@
// Voltage to send to the rollers. Positive is sucking in.
float voltage_top_rollers;
float voltage_bottom_rollers;
+ float voltage_intake_rollers;
bool force_intake;
- // If true, release the latch which holds the traverse mechanism in the
- // middle.
- bool traverse_unlatched;
// If true, fire the traverse mechanism down.
bool traverse_down;
};
@@ -77,12 +75,8 @@
// The internal state of the state machine.
int32_t state;
-
// Estimated angle and angular velocitie of the intake.
JointState intake;
-
- // Is the intake collided?
- bool is_collided;
};
message Position {
@@ -96,9 +90,8 @@
float voltage_top_rollers;
float voltage_bottom_rollers;
+ float voltage_intake_rollers;
- // If true, release the latch to hold the traverse mechanism in the middle.
- bool traverse_unlatched;
// If true, fire the traverse mechanism down.
bool traverse_down;
};
diff --git a/y2016_bot3/control_loops/intake/intake_lib_test.cc b/y2016_bot3/control_loops/intake/intake_lib_test.cc
index 43232aa..4048a19 100644
--- a/y2016_bot3/control_loops/intake/intake_lib_test.cc
+++ b/y2016_bot3/control_loops/intake/intake_lib_test.cc
@@ -443,14 +443,6 @@
EXPECT_EQ(Intake::RUNNING, intake_.state());
}
-// Tests that MoveButKeepBelow returns sane values.
-TEST_F(IntakeTest, MoveButKeepBelowTest) {
- EXPECT_EQ(1.0, Intake::MoveButKeepBelow(1.0, 10.0, 1.0));
- EXPECT_EQ(1.0, Intake::MoveButKeepBelow(1.0, 2.0, 1.0));
- EXPECT_EQ(0.0, Intake::MoveButKeepBelow(1.0, 1.0, 1.0));
- EXPECT_EQ(1.0, Intake::MoveButKeepBelow(1.0, 0.0, 1.0));
-}
-
// Tests that the integrators works.
TEST_F(IntakeTest, IntegratorTest) {
intake_plant_.InitializeIntakePosition(
diff --git a/y2016_bot3/control_loops/python/drivetrain.py b/y2016_bot3/control_loops/python/drivetrain.py
index 5a67416..5de7dbc 100755
--- a/y2016_bot3/control_loops/python/drivetrain.py
+++ b/y2016_bot3/control_loops/python/drivetrain.py
@@ -71,9 +71,9 @@
# Free Current in Amps
self.free_current = 4.7 * self.num_motors
# Moment of inertia of the drivetrain in kg m^2
- self.J = 2.0
+ self.J = 8.0
# Mass of the robot, in kg.
- self.m = 68
+ self.m = 45
# Radius of the robot, in meters (requires tuning by hand)
self.rb = 0.601 / 2.0
# Radius of the wheels, in meters.
diff --git a/y2016_bot3/control_loops/python/polydrivetrain.py b/y2016_bot3/control_loops/python/polydrivetrain.py
index ac85bb6..07f9ff9 100755
--- a/y2016_bot3/control_loops/python/polydrivetrain.py
+++ b/y2016_bot3/control_loops/python/polydrivetrain.py
@@ -128,7 +128,7 @@
# FF * X = U (steady state)
self.FF = self.B.I * (numpy.eye(2) - self.A)
- self.PlaceControllerPoles([0.67, 0.67])
+ self.PlaceControllerPoles([0.85, 0.85])
self.PlaceObserverPoles([0.02, 0.02])
self.G_high = self._drivetrain.G_high
diff --git a/y2016_bot3/joystick_reader.cc b/y2016_bot3/joystick_reader.cc
index a02142d..02e6817 100644
--- a/y2016_bot3/joystick_reader.cc
+++ b/y2016_bot3/joystick_reader.cc
@@ -40,11 +40,11 @@
const ButtonLocation kTurn2(1, 11);
// Buttons on the lexan driver station to get things running on bring-up day.
-const ButtonLocation kIntakeDown(3, 11);
-const ButtonLocation kIntakeIn(3, 12);
+const ButtonLocation kIntakeDown(3, 5);
+const ButtonLocation kIntakeIn(3, 4);
const ButtonLocation kFire(3, 3);
-const ButtonLocation kIntakeOut(3, 9);
-const ButtonLocation kChevalDeFrise(3, 8);
+const ButtonLocation kIntakeOut(3, 3);
+const ButtonLocation kChevalDeFrise(3, 11);
class Reader : public ::aos::input::JoystickInput {
public:
@@ -143,11 +143,8 @@
saw_ball_when_started_intaking_ = ball_detected;
}
- if (data.IsPressed(kIntakeIn)) {
- is_intaking_ = (!ball_detected || saw_ball_when_started_intaking_);
- } else {
- is_intaking_ = false;
- }
+ is_intaking_ = data.IsPressed(kIntakeIn) &&
+ (!ball_detected || saw_ball_when_started_intaking_);
is_outtaking_ = data.IsPressed(kIntakeOut);
@@ -168,10 +165,8 @@
}
if (data.IsPressed(kChevalDeFrise)) {
- traverse_unlatched_ = false;
traverse_down_ = true;
} else {
- traverse_unlatched_ = true;
traverse_down_ = false;
}
@@ -182,23 +177,26 @@
new_intake_goal->max_angular_velocity_intake = 7.0;
new_intake_goal->max_angular_acceleration_intake = 40.0;
- // Granny mode
- /*
+#define GrannyMode false
+#if GrannyMode
new_intake_goal->max_angular_velocity_intake = 0.2;
new_intake_goal->max_angular_acceleration_intake = 1.0;
- */
+#endif
+
if (is_intaking_) {
- new_intake_goal->voltage_top_rollers = 12.0;
+ new_intake_goal->voltage_intake_rollers = -12.0;
+ new_intake_goal->voltage_top_rollers = -12.0;
new_intake_goal->voltage_bottom_rollers = 12.0;
} else if (is_outtaking_) {
- new_intake_goal->voltage_top_rollers = -12.0;
+ new_intake_goal->voltage_intake_rollers = 12.0;
+ new_intake_goal->voltage_top_rollers = 12.0;
new_intake_goal->voltage_bottom_rollers = -7.0;
} else {
+ new_intake_goal->voltage_intake_rollers = 0.0;
new_intake_goal->voltage_top_rollers = 0.0;
new_intake_goal->voltage_bottom_rollers = 0.0;
}
- new_intake_goal->traverse_unlatched = traverse_unlatched_;
new_intake_goal->traverse_down = traverse_down_;
new_intake_goal->force_intake = true;
@@ -236,7 +234,6 @@
bool was_running_ = false;
bool auto_running_ = false;
- bool traverse_unlatched_ = false;
bool traverse_down_ = false;
// If we're waiting for the subsystems to zero.
diff --git a/y2016_bot3/wpilib/wpilib_interface.cc b/y2016_bot3/wpilib/wpilib_interface.cc
index ad75401..3d7d8ce 100644
--- a/y2016_bot3/wpilib/wpilib_interface.cc
+++ b/y2016_bot3/wpilib/wpilib_interface.cc
@@ -84,13 +84,13 @@
// with proper units.
double drivetrain_translate(int32_t in) {
- return -static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*4x*/) *
+ return -static_cast<double>(in) / (512.0 /*cpr*/ * 4.0 /*4x*/) *
::y2016_bot3::constants::kDrivetrainEncoderRatio *
control_loops::drivetrain::kWheelRadius * 2.0 * M_PI;
}
double drivetrain_velocity_translate(double in) {
- return (1.0 / in) / 256.0 /*cpr*/ *
+ return (1.0 / in) / 512.0 /*cpr*/ *
::y2016_bot3::constants::kDrivetrainEncoderRatio *
control_loops::drivetrain::kWheelRadius * 2.0 * M_PI;
}
@@ -102,7 +102,7 @@
double intake_pot_translate(double voltage) {
return voltage * ::y2016_bot3::constants::kIntakePotRatio *
- (10.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
+ (5.0 /*turns*/ / 5.0 /*volts*/) * (2 * M_PI /*radians*/);
}
constexpr double kMaxDrivetrainEncoderPulsesPerSecond =
@@ -194,7 +194,7 @@
{
auto drivetrain_message = drivetrain_queue.position.MakeMessage();
drivetrain_message->right_encoder =
- drivetrain_translate(-drivetrain_right_encoder_->GetRaw());
+ drivetrain_translate(drivetrain_right_encoder_->GetRaw());
drivetrain_message->left_encoder =
-drivetrain_translate(drivetrain_left_encoder_->GetRaw());
drivetrain_message->left_speed =
@@ -210,7 +210,7 @@
{
auto intake_message = intake_queue.position.MakeMessage();
CopyPotAndIndexPosition(intake_encoder_, &intake_message->intake,
- intake_translate, intake_pot_translate, false,
+ intake_translate, intake_pot_translate, true,
intake_pot_offset);
intake_message.Send();
@@ -286,11 +286,6 @@
traverse_ = ::std::move(s);
}
- void set_traverse_latch(
- ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> s) {
- traverse_latch_ = ::std::move(s);
- }
-
void operator()() {
compressor_->Start();
::aos::SetCurrentThreadName("Solenoids");
@@ -311,9 +306,7 @@
intake_.FetchLatest();
if (intake_.get()) {
LOG_STRUCT(DEBUG, "solenoids", *intake_);
-
traverse_->Set(intake_->traverse_down);
- traverse_latch_->Set(intake_->traverse_unlatched);
}
}
@@ -333,8 +326,7 @@
private:
const ::std::unique_ptr<::frc971::wpilib::BufferedPcm> &pcm_;
- ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> traverse_,
- traverse_latch_;
+ ::std::unique_ptr<::frc971::wpilib::BufferedSolenoid> traverse_;
::std::unique_ptr<Compressor> compressor_;
::aos::Queue<::frc971::control_loops::DrivetrainQueue::Output> drivetrain_;
@@ -345,12 +337,16 @@
class DrivetrainWriter : public ::frc971::wpilib::LoopOutputHandler {
public:
- void set_drivetrain_left_talon(::std::unique_ptr<Talon> t) {
- drivetrain_left_talon_ = ::std::move(t);
+ void set_drivetrain_left_talon(::std::unique_ptr<Talon> t0,
+ ::std::unique_ptr<Talon> t1) {
+ drivetrain_left_talon_0_ = ::std::move(t0);
+ drivetrain_left_talon_1_ = ::std::move(t1);
}
- void set_drivetrain_right_talon(::std::unique_ptr<Talon> t) {
- drivetrain_right_talon_ = ::std::move(t);
+ void set_drivetrain_right_talon(::std::unique_ptr<Talon> t0,
+ ::std::unique_ptr<Talon> t1) {
+ drivetrain_right_talon_0_ = ::std::move(t0);
+ drivetrain_right_talon_1_ = ::std::move(t1);
}
private:
@@ -361,17 +357,22 @@
virtual void Write() override {
auto &queue = ::frc971::control_loops::drivetrain_queue.output;
LOG_STRUCT(DEBUG, "will output", *queue);
- drivetrain_left_talon_->Set(queue->left_voltage / 12.0);
- drivetrain_right_talon_->Set(-queue->right_voltage / 12.0);
+ drivetrain_left_talon_0_->Set(queue->left_voltage / 12.0);
+ drivetrain_left_talon_1_->Set(queue->left_voltage / 12.0);
+ drivetrain_right_talon_0_->Set(-queue->right_voltage / 12.0);
+ drivetrain_right_talon_1_->Set(-queue->right_voltage / 12.0);
}
virtual void Stop() override {
LOG(WARNING, "drivetrain output too old\n");
- drivetrain_left_talon_->Disable();
- drivetrain_right_talon_->Disable();
+ drivetrain_left_talon_0_->Disable();
+ drivetrain_right_talon_0_->Disable();
+ drivetrain_left_talon_1_->Disable();
+ drivetrain_right_talon_1_->Disable();
}
- ::std::unique_ptr<Talon> drivetrain_left_talon_, drivetrain_right_talon_;
+ ::std::unique_ptr<Talon> drivetrain_left_talon_0_, drivetrain_right_talon_0_,
+ drivetrain_right_talon_1_, drivetrain_left_talon_1_;
};
class IntakeWriter : public ::frc971::wpilib::LoopOutputHandler {
@@ -380,6 +381,10 @@
intake_talon_ = ::std::move(t);
}
+ void set_intake_rollers_talon(::std::unique_ptr<Talon> t) {
+ intake_rollers_talon_ = ::std::move(t);
+ }
+
void set_top_rollers_talon(::std::unique_ptr<Talon> t) {
top_rollers_talon_ = ::std::move(t);
}
@@ -400,6 +405,7 @@
kMaxBringupPower) /
12.0);
top_rollers_talon_->Set(-queue->voltage_top_rollers / 12.0);
+ intake_rollers_talon_->Set(-queue->voltage_intake_rollers / 12.0);
bottom_rollers_talon_->Set(-queue->voltage_bottom_rollers / 12.0);
}
@@ -409,7 +415,7 @@
}
::std::unique_ptr<Talon> intake_talon_, top_rollers_talon_,
- bottom_rollers_talon_;
+ bottom_rollers_talon_, intake_rollers_talon_;
};
class WPILibRobot : public ::frc971::wpilib::WPILibRobotBase {
@@ -430,14 +436,14 @@
::std::thread pdp_fetcher_thread(::std::ref(pdp_fetcher));
SensorReader reader;
- reader.set_drivetrain_left_encoder(make_encoder(5));
- reader.set_drivetrain_right_encoder(make_encoder(6));
+ reader.set_drivetrain_left_encoder(make_encoder(0));
+ reader.set_drivetrain_right_encoder(make_encoder(1));
- reader.set_intake_encoder(make_encoder(0));
+ reader.set_intake_encoder(make_encoder(2));
reader.set_intake_index(make_unique<DigitalInput>(0));
- reader.set_intake_potentiometer(make_unique<AnalogInput>(0));
+ reader.set_intake_potentiometer(make_unique<AnalogInput>(4));
- reader.set_ball_detector(make_unique<AnalogInput>(7));
+ reader.set_ball_detector(make_unique<AnalogInput>(5));
reader.set_dma(make_unique<DMA>());
::std::thread reader_thread(::std::ref(reader));
@@ -446,23 +452,27 @@
::std::thread gyro_thread(::std::ref(gyro_sender));
DrivetrainWriter drivetrain_writer;
+ // 2 and 3 are right. 0 and 1 are left
drivetrain_writer.set_drivetrain_left_talon(
- ::std::unique_ptr<Talon>(new Talon(5)));
+ ::std::unique_ptr<Talon>(new Talon(0)),
+ ::std::unique_ptr<Talon>(new Talon(1)));
drivetrain_writer.set_drivetrain_right_talon(
- ::std::unique_ptr<Talon>(new Talon(4)));
+ ::std::unique_ptr<Talon>(new Talon(2)),
+ ::std::unique_ptr<Talon>(new Talon(3)));
::std::thread drivetrain_writer_thread(::std::ref(drivetrain_writer));
IntakeWriter intake_writer;
- intake_writer.set_intake_talon(::std::unique_ptr<Talon>(new Talon(3)));
- intake_writer.set_top_rollers_talon(::std::unique_ptr<Talon>(new Talon(1)));
+ intake_writer.set_intake_talon(::std::unique_ptr<Talon>(new Talon(7)));
+ intake_writer.set_top_rollers_talon(::std::unique_ptr<Talon>(new Talon(6)));
+ intake_writer.set_intake_rollers_talon(
+ ::std::unique_ptr<Talon>(new Talon(5)));
intake_writer.set_bottom_rollers_talon(
- ::std::unique_ptr<Talon>(new Talon(0)));
+ ::std::unique_ptr<Talon>(new Talon(4)));
::std::thread intake_writer_thread(::std::ref(intake_writer));
::std::unique_ptr<::frc971::wpilib::BufferedPcm> pcm(
new ::frc971::wpilib::BufferedPcm());
SolenoidWriter solenoid_writer(pcm);
- solenoid_writer.set_traverse_latch(pcm->MakeSolenoid(2));
solenoid_writer.set_traverse(pcm->MakeSolenoid(3));
solenoid_writer.set_compressor(make_unique<Compressor>());