Chapter 12: Digital Cam Switch
A digital cam switch uses an axis' position to control a digital output, which is controlled by a switch. When the axis reaches a certain position, the switch is turned on or off. The switch can be controlled by a forward and backward movement of an axis. In this chapter, you'll learn how to set digital cam switches and use them to control digital outputs.
- Each digital output can be controlled by a track that contains multiple switches.
- Each switch has a starting position and either distance or duration. It can be limited to a specific direction.
- Time compensation and hysteresis can be added to a track to avoid fast changes in the value and frequent switching.
Time compensation and hysteresis
Time compensation is a period of time for a switch to be turned on or off earlier or later than the switching point. There are two time compensation: OnCompensation and OffCompensation. Hysteresis is a range in which a switch won't be turned on or off.
- OnCompensation: the length of time with which a switch is turned on (rising edge) before or after a switching point per track. If the value is positive, the switch-on will be delayed; if the value is negative, the switch-on will be advanced.
- OffCompensation: the length of time with which a switch is turned off (falling edge) before or after a switching point per track. If the value is positive, the switch-off will be delayed; if the value is negative, the switch-off will be advanced.
- Hysteresis: distance from a switching point (in positive and negative direction) in which a switch is not turned on or off until the axis has left this area. This can avoid frequent switching around a switching point.
Add a header and .cpp file
You need to add a header and a .cpp file to learn the code of this chapter. The steps of adding them are written in Chapter 2 > Add a header and .cpp file.
- Add a header file:
- Add a .cpp file:
In Solution Explorer, in Header Files, add a header file and name it "DigitalCamSwitch.h
."
In Solution Explorer, in Source Files, add a C++ file and name it "DigitalCamSwitch.cpp
."
Tutorial
Take the following steps to complete the training: