Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adcs controllers and main pointing strategy #92

Merged
merged 13 commits into from
Jan 19, 2020
Merged

Adcs controllers and main pointing strategy #92

merged 13 commits into from
Jan 19, 2020

Conversation

nhz2
Copy link
Member

@nhz2 nhz2 commented Nov 27, 2019

No description provided.

Copy link
Member

@kylekrol kylekrol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the most part looks really good. I left a couple miscellaneous questions. I think my largest concern is some slight divergence from where I think the flight computer implementations of the controllers may have been going (particularly the pointer state's PD buffer).

I just want to make sure we're one the same page about the internals of the MATLAB controllers and CXX controllers so we don't have any issues integrating the CXX functions into MATLAB (which I plan on doing once the full suite of attitude controllers is complete).

Let me know what you think!

@stewartaslan for awareness.

MATLAB/config.m Outdated
@@ -70,6 +70,7 @@
% Torque on fuel/difference in angular rates in eci Nm/(rad/s).
const.ATTITUDE_PD_KP = 75e-4; % imported from simulink
const.ATTITUDE_PD_KD = 32.5e-4; % imported from simulink
const.ATTITUDE_PD_derivative_buffer_size=1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we need this for the flight algorithm you think? We're already buffering w_body in the estimation step.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I wanted to have way to point even if quat_body_eci was NaN. Before, the derivative term was just the gyro, but I wanted to see what would happen if I just did finite differences.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I guess this basically doing the same thing as estimating w_body

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. But in terms of the sorta version 1.0 of the GNC algorithms we're good keeping the finite difference estimation in the estimator and no buffer in the controller?

MATLAB/detumbler.m Outdated Show resolved Hide resolved
MATLAB/recursive_least_squares.m Outdated Show resolved Hide resolved
target_position_eci= other_satellite_state.dynamics.position_eci;
sensor_readings.target_position_ecef= utl_rotateframe(quat_ecef_eci,target_position_eci);
target_velocity_eci= other_satellite_state.dynamics.velocity_eci;
sensor_readings.target_velocity_ecef= utl_rotateframe(quat_ecef_eci, target_velocity_eci)-cross(rate_ecef,sensor_readings.target_position_ecef);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does CD GPS actually give us a velocity reading or were we going to calculate that ourselves?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we have to calculate that ourselves.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sensor_readings.target_velocity_ecef will only live in MATLAB?

MATLAB/sensor_reading.m Show resolved Hide resolved
Comment on lines 18 to 43
estimator.sat2sun_eci= env_sun_vector(sensor_readings.time);
estimator.mag_ecef= env_magnetic_field(sensor_readings.time,sensor_readings.position_ecef);
[estimator.quat_ecef_eci,~]=env_earth_attitude(sensor_readings.time);
estimator.quat_eci_ecef= utl_quat_conj(estimator.quat_ecef_eci);
estimator.mag_eci =utl_rotateframe(estimator.quat_eci_ecef,estimator.mag_ecef);
estimator.sat2sun_body= sensor_readings.sat2sun_body;
estimator.quat_body_eci=utl_triad(estimator.sat2sun_eci,estimator.mag_eci,sensor_readings.sat2sun_body,sensor_readings.magnetometer_body);
estimator.angular_rate_body= sensor_readings.gyro_body;
estimator.angular_momentum_body= const.JB*estimator.angular_rate_body+sensor_readings.wheel_momentum_body;
estimator.magnetometer_body= sensor_readings.magnetometer_body;
estimator.magnetic_field_body=estimator.magnetometer_body;
estimator.time= sensor_readings.time;
estimator.position_eci= utl_rotateframe(estimator.quat_eci_ecef,sensor_readings.position_ecef);
estimator.velocity_eci= utl_rotateframe(estimator.quat_eci_ecef,sensor_readings.velocity_ecef+cross(const.earth_rate_ecef,sensor_readings.position_ecef));
estimator.target_position_eci=utl_rotateframe(estimator.quat_eci_ecef,sensor_readings.target_position_ecef);
estimator.target_velocity_eci=utl_rotateframe(estimator.quat_eci_ecef,sensor_readings.target_velocity_ecef+cross(const.earth_rate_ecef,sensor_readings.target_position_ecef));
estimator.tumbling= ~(norm(estimator.angular_momentum_body)<const.MAXWHEELRATE*const.JWHEEL*0.7);
estimator.low_power= false;
estimator.eclipse= env_eclipse(estimator.position_eci,estimator.sat2sun_eci);
estimator.valid_gps=all(isfinite([estimator.position_eci; estimator.velocity_eci; estimator.time]));
estimator.valid_target_gps=estimator.valid_gps && all(isfinite([estimator.target_position_eci; estimator.target_velocity_eci; estimator.time]));

if estimator.valid_gps && ~estimator.eclipse && ~all(isfinite(estimator.sat2sun_body))
estimator.sat2sun_body= [0;0;-1]; % assume the sun is coming from the docking face
estimator.quat_body_eci=utl_triad(estimator.sat2sun_eci,estimator.mag_eci,estimator.sat2sun_body,estimator.magnetic_field_body);
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing this in an attitude estimator function and gps estimation function may be a good idea?

MATLAB/update_FC_state.m Outdated Show resolved Hide resolved
state.secondary_desired_direction_body= [0;0;1];
end
if strcmp(state.main_state,'rendezvous')
if estimator.tumbling || estimator.low_power || estimator.eclipse || ~estimator.valid_gps || ~estimator.valid_target_gps
Copy link
Member

@kylekrol kylekrol Nov 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be temporary, but if everything is behaving nominally except for having target position, velocity would we want to go back to detumble or hold attitude with the full ADCS system? The latter would probably give us a better shot at getting comms, gps, etc

EDIT: Actually setting it to 'detumble' will let it propagate through to 'get gps', 'get target orbit', etc on the next FC pass correct? If so, I think this is still good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully if cd gps lock is lost, the orbit estimator can just propagate the target orbit, that way it won't have to go into detumble.

@nhz2 nhz2 marked this pull request as ready for review January 6, 2020 15:55
@nhz2
Copy link
Member Author

nhz2 commented Jan 6, 2020

To run the simulation in MATLAB, go to the MATLAB directory in psim, then run:

run_tests and make sure there are no failed tests.

main will generate the trajectories

plot_pointing_errors(main_state_trajectory) will show the pointing errors

plot_state_transitions(computer_state_follower_trajectory) will show the state of the follower flight computer.

there are other plotting functions in the plot folder

Copy link
Member

@tanishqaggarwal tanishqaggarwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, I just have a few questions (mostly due to my ignorance of sim)

Comment on lines 25 to 31
case 5
%save magnetic field reading
state.old_magnetic_field= magnetometer_body;
case 9
%calculate finite difference and bang bang controller
deltaB= magnetometer_body-state.old_magnetic_field;
state.magrod_moment_cmd= -sign(deltaB)*const.MAXMOMENT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of 5 and 9?

MATLAB/adcs/adcs_pointer.m Show resolved Hide resolved
MATLAB/adcs/adcs_pointer.m Show resolved Hide resolved
MATLAB/initialize_main_state.m Show resolved Hide resolved
MATLAB/sensor_reading.m Show resolved Hide resolved
%move to next state if initialization time has passed
if state.initialization_hold_done || state.on_time>(30*60*1E9)
state.initialization_hold_done=true;%save this in eprom
state.main_state='detumble';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI Flight Software stores on_time instead of hold_done. The rationale is that the satellite can have low battery charge and can die during the post-deployment phase. I don't think it's necessary to copy this into sim though.

MATLAB/update_FC_state.m Show resolved Hide resolved
MATLAB/update_FC_state.m Outdated Show resolved Hide resolved
MATLAB/update_FC_state.m Show resolved Hide resolved
r_hat_cross_sat2sun_body=cross(estimator.sat2sun_body,r_hat_eci);
state.primary_current_direction_body= r_hat_body;
state.primary_desired_direction_body= [1;0;0];
if( norm(r_hat_cross_sat2sun_body) > sin(10*pi/180))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change the alignment threshold in Flight Software to also be 10 degrees

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general is there some way we could standardize these thresholds across Flight Software and sim? It would be great to not have to manually ensure their similitude

Copy link
Member

@kylekrol kylekrol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the organizational improvements! If this is good to go, merging it sooner rather than later would be cool so I can get on the rendezvous changes as well.

Copy link
Member

@tanishqaggarwal tanishqaggarwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to approve bc my questions aren't that important and sounds like work is waiting on this PR

Copy link
Contributor

@stewartaslan stewartaslan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@stewartaslan stewartaslan self-requested a review January 18, 2020 20:04
@nhz2 nhz2 merged commit cc672c0 into master Jan 19, 2020
@nhz2 nhz2 deleted the adcs_update branch January 19, 2020 01:26
tanishqaggarwal pushed a commit that referenced this pull request Mar 11, 2020
* starting adcs_update state machine

* draft of adcs_update, main running

* Draft of pointing and detumbling controllers

* optional finite diff for pd controller

* moved adcs into folder

* removed config from unit tests

* Update initialize_computer_states.m

* better initial conditions

* Long edge pointing

* addressing comments

* Some basic unit tests


Former-commit-id: cc672c0
Former-commit-id: 695fc2fb42cf48094fdb355e53e9986d8f070488
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants