1+
2+ #include " io/ArmIO.h"
3+
4+ void ArmIO::Periodic () {
5+ // Process all the inputs and outputs to/from high level software.
6+ VOKC_CALL (ProcessIO ());
7+ }
8+
9+ void ArmIO::SimulationPeriodic () {
10+ // SimulationPeriodic
11+ }
12+
13+ bool ArmIO::ProcessIO () {
14+ OKC_CHECK (sw_interface_ != nullptr );
15+ OKC_CHECK (hw_interface_ != nullptr );
16+
17+ // Set the software outputs
18+ // If the intake configuration needs to be updated, update it.
19+ if (sw_interface_->update_config ) {
20+ OKC_CALL (UpdateArmConfig (sw_interface_->arm_config ));
21+
22+ // Lower the update flag
23+ sw_interface_->update_config = false ;
24+ }
25+
26+ // If the encoder should be reset, reset it
27+ if (sw_interface_->reset_encoders ) {
28+ OKC_CALL (ResetEncoders ());
29+
30+ // Lower the encoder reset flag
31+ sw_interface_->reset_encoders = false ;
32+ }
33+
34+ // if the encoder should be set to a specific value
35+ if (sw_interface_->set_encoder_to_val ) {
36+ OKC_CALL (SetEncoder (sw_interface_->encoder_val_to_set ));
37+
38+ sw_interface_->set_encoder_to_val = false ;
39+ }
40+
41+ // Get the hardware sensor values.
42+ // limit switches
43+ sw_interface_->deployed_limit_switch_val =
44+ hw_interface_->deploy_limit_switch ->Get (); // ???
45+ sw_interface_->retracted_limit_switch_val =
46+ hw_interface_->retracted_limit_switch ->Get (); // ???
47+
48+ // intake position encoder
49+ sw_interface_->arm_position_encoder_val =
50+ hw_interface_->arm_position_motor ->GetEncoder ().GetPosition ();
51+
52+ return true ;
53+ }
54+
55+ bool ArmIO::UpdateArmConfig (ArmConfig &config) {
56+ OKC_CHECK (hw_interface_ != nullptr );
57+
58+ // Get the configuration
59+ double open_loop_ramp = config.open_loop_ramp_rate ;
60+ // double max_output_deploy = config.max_output_deploy;
61+ // double max_output_retract = config.max_output_retract;
62+ double max_indexer_current = config.max_indexer_current ;
63+
64+ // Apply the configuration
65+ // Open Loop Ramp Rate
66+ hw_interface_->arm_lift_motor ->SetOpenLoopRampRate (open_loop_ramp);
67+ hw_interface_->indexer_motor ->SetOpenLoopRampRate (open_loop_ramp);
68+
69+ // Java code has this commented out as well, I'm assuming because it was
70+ // meesing something up. well, the intake works (probably, been a while
71+ // since it's been actually plugged in) without this, so leaving commented
72+ // out for now
73+ // hw_interface_->intake_position_motor->SetOpenLoopRampRate(open_loop_ramp);
74+
75+ // current limiting, so the neo 550 on the indexer doesn't stall and smoke
76+ hw_interface_->indexer_motor ->SetSmartCurrentLimit (max_indexer_current);
77+
78+ return true ;
79+ }
80+
81+ bool ArmIO::ResetEncoders () {
82+ OKC_CHECK (hw_interface_ != nullptr );
83+
84+ hw_interface_->arm_position_motor ->GetEncoder ().SetPosition (0.0 );
85+
86+ // we currently don't use the encoder for these other two motors, so we
87+ // don't need to reset them yet. yet.
88+ // hw_interface_->intake_motor->GetEncoder().SetPosition(0.0);
89+ // hw_interface_->indexer_motor->GetEncoder().SetPosition(0.0);
90+
91+ return true ;
92+ }
93+
94+ bool ArmIO::SetEncoder (double &val) {
95+ OKC_CHECK (hw_interface_ != nullptr );
96+
97+ hw_interface_->arm_position_motor ->GetEncoder ().SetPosition (val);
98+
99+ return true ;
100+ }
0 commit comments