The controller will be mounted above the motor and is wired between the battery pack and the motor.
The controller’s job is to regulate how much of the battery pack voltage and current is sent to the motor, and to do so as efficiently as possible. Modern transistors are very efficient when they are fully on or fully off, but they tend to generate a lot of heat when they are partially on. The controller continuously connects and disconnects the motor to the battery pack. The switching speed is fast enough (8,000 cycles per second) that the motor does not react with a noticeable pulse each time the battery is connected and disconnected. The motor only “sees” an average voltage that depends on the how long the battery stays connected and how long the battery is disconnected within each switch cycle. For example, if the controller is on half the time, and off half the time, then the motor “sees” 50% of the battery voltage. If the controller stays on for 10% and off for 90% of each switch cycle, the motor will operate the same as if 10% of the full battery voltage were applied. The duty cycle is set by the position of the accelerator pedal.