A man has admitted trying to kill a police officer in an attack motivated by anti-government ideology, a court has heard.