Advanced EasyC Jim Cline July 20-21, 2017
Advanced EasyC Variables Custom Functions Defines
Advanced EasyC Variables Variables can be used for many different purposes. Controlling the master loop Analog and digital inputs Speed controls Custom functions
Emergency Shutdown When first setting up a robot there can many times in which the robot can end up in state that needs to be shut down to prevent damage to the robot or other things. Motor and servo stalls, unresponsive controller. To do this we create a function that will shutdown all functions and create a variable that will drop out of the main loop and enter the shutdown function. Note: Robot will not function again until robot is restarted.
Emergency Shutdown Before doing anything make sure the Controller Configuration is set up with motors and servos in the correct spots.
Emergency Shutdown Add a variable that will hold the main loop control. Also add a Shutdown button pushed variable.
Emergency Shutdown Add a while loop and set the loop to run as long as the trigger is true
Emergency Shutdown Add a new custom function to shut down the motors and move servos to safe locations
Emergency Shutdown Set the motors to zero and move the servos to a safe location (0 may not be safe)
Emergency Shutdown Add the Robot_Shutdown function after the loop.
Emergency Shutdown Add a Get Joystick Digital function that gets the status of the button that will be used for shutdown
Emergency Shutdown Add an if statement that detects when the shutdown button is pushed.
Emergency Shutdown Add an assignment function inside the if statement that will set the trigger to false
Emergency Shutdown
Advanced EasyC So now we have a button that will shut the robot down if a button is pushed. What happens if they accidently press that button during the competition? The robot stops functioning and will not work until restarted. NOT GOOD So how do we fix that?
Defines Defines are in the same dialog as variables Set a define called TESTING Defines are typically all upper case to identify they are defines Set the define to 1 (true) to say that we are testing
Defines
Emergency Shutdown Add an if statement with the define TESTIN as the test. Put the shutdown code into the new if.
Defines Doesn’t a variable do the same thing? Sort-of. A variable can be changed, a define can’t. A variable is set at run-time the define at compile time.
Q and A Questions?