Skip to content

framework complete ?? Remote_W -> Pilot_X-> Driver_Y -> BLDC_Z #129

@RoboDurden

Description

@RoboDurden

With my Hoverbike project, i have introduced the concept of a pilot, so user code running on the hoverboard firmware can be seperated from the main.c code, with the PilotDefault code not (yet?) moved to a pilotDefault.c file:

			#ifdef PILOT_XY
				Pilot(&pwmMaster,&pwmSlave);
			#else
				if (iDrivingMode == 0)
				{
					// Calculate expo rate for less steering with higher speeds
					expo = MAP((float)ABS(speed), 0, 1000, 1, 0.5);
					
					// Each speedvalue or steervalue between 50 and -50 (STAND_STILL_THRESHOLD) means absolutely no pwm
					// -> to get the device calm 'around zero speed'
					scaledSpeed = speed < STAND_STILL_THRESHOLD && speed > -STAND_STILL_THRESHOLD ? 0 : CLAMP(speed, -speedLimit, speedLimit) * SPEED_COEFFICIENT;
					scaledSteer = steer < STAND_STILL_THRESHOLD && steer > -STAND_STILL_THRESHOLD ? 0 : CLAMP(steer, -speedLimit, speedLimit) * STEER_COEFFICIENT * expo;
					
					// Map to an angle of 180 degress to 0 degrees for array access (means angle -90 to 90 degrees)
					steerAngle = MAP((float)scaledSteer, -1000, 1000, 180, 0);
					xScale = lookUpTableAngle[(uint16_t)steerAngle];

					// Mix steering and speed value for right and left speed
					if(steerAngle >= 90)
					{
						pwmSlave = CLAMP(scaledSpeed, -1000, 1000);
						pwmMaster = CLAMP(pwmSlave / xScale, -1000, 1000);
					}
					else
					{
						pwmMaster = CLAMP(scaledSpeed, -1000, 1000);
						pwmSlave = CLAMP(xScale * pwmMaster, -1000, 1000);
					}
				}
				else
				{
					// simply boost/drop speed left and right according to steer going from -1.0 to +1.0
					pwmMaster = speed * (1+steer/1000.0);		
					pwmSlave = speed * (1-steer/1000.0);
				}
			#endif

The idea is, that still different Remotes can be used to talk to the same Pilot.
For my Hoverbike, the speed coming from a Remote can be used by the Pilot as the max speed.
This max speed could come from RemoteUart, RemoteUartBus but also from a throttle being read by RemoteAdc.
My PilotHoverbike will have the final word on the speed sent to the Driver, based on brake and pedaling detection.

Currently, the new 15% speed boost is hard coded with

//#define BLDC_SINE_BOOSTER		// can boost speed by 15% starting from 87% throttle.

But when i have merged the two bldc_get_pwm functions, a Pilot can deactivate the booster when battery is low, for example.

@WestlingPi , you already wanted to discuss the code of PilotDefault. But it might cause confusion if your RemoteROS2 will also need a PilotROS2.
So we could add a PilotNull which does nothing at all. pwmMaster and pwmSlave are global variables anyway, so you could already compute these values in RemoteROS2.

I was tempted to copy RemoteUart into a new RemoteHoverbike and also put my pilot code there.
But i think it is a good idea to give every user a new playground for their onboard code: PilotXY.c

This time, i have not added a "virtual class" Pilot.h, should i ?
To add a new Pilot, add the include to defines.h

#ifdef PILOT_HOVERBIKE
	#include "PilotHoverbike.h"
#endif

and in your .h file put

#define PILOT_XY
void 	Pilot(int16_t* pPwmMaster, int16_t* pPwmSlave);

The PILOT_XY will tell main.c to call the Pilot function instead of the default old code.

Ideas welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions